markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationWCF.cs @ 1c7f408a
이력 | 보기 | 이력해설 | 다운로드 (11.7 KB)
1 | 53c9637d | taeseongkim | using Markus.Message; |
---|---|---|---|
2 | using Markus.Service.Extensions; |
||
3 | using Markus.Service.Interface; |
||
4 | using Markus.Service.IWcfService; |
||
5 | using System; |
||
6 | using System.Collections.Generic; |
||
7 | using System.Diagnostics; |
||
8 | using System.Linq; |
||
9 | using System.ServiceModel; |
||
10 | using System.ServiceModel.Activation; |
||
11 | using System.ServiceModel.Web; |
||
12 | using System.Text; |
||
13 | using System.Threading.Tasks; |
||
14 | |||
15 | namespace Markus.Service |
||
16 | { |
||
17 | a53dfe45 | taeseongkim | /// <summary> |
18 | /// web service 목록 |
||
19 | /// </summary> |
||
20 | 53c9637d | taeseongkim | [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] |
21 | 1ae729e4 | taeseongkim | //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true)] |
22 | 53c9637d | taeseongkim | public partial class ServiceStation : IStationService |
23 | { |
||
24 | a53dfe45 | taeseongkim | /// <summary> |
25 | /// DB에 Convrert Item을 추가 하고 호출 |
||
26 | /// CovnertWebService에서 호출시 사용 |
||
27 | /// </summary> |
||
28 | /// <param name="ProjectNo"></param> |
||
29 | /// <param name="ConvertID"></param> |
||
30 | /// <returns></returns> |
||
31 | 53c9637d | taeseongkim | public string ConvertAdd(string ProjectNo, string ConvertID) |
32 | { |
||
33 | string result = false.ToString(); |
||
34 | |||
35 | try |
||
36 | { |
||
37 | 06f13e11 | taeseongkim | result = ConvertProcessAdd(ProjectNo, ConvertID); |
38 | 949d5058 | taeseongkim | |
39 | logger.Info($"ConvertAdd Call Item ProjectNo : {ProjectNo} ConvertID : {ConvertID} result : {result}"); |
||
40 | 53c9637d | taeseongkim | } |
41 | catch (Exception ex) |
||
42 | { |
||
43 | result = $"ConvertAdd Error {ConvertID}"; |
||
44 | logger.Error($"ConvertAdd Error- {ConvertID}", ex); |
||
45 | } |
||
46 | |||
47 | return result; |
||
48 | } |
||
49 | |||
50 | a53dfe45 | taeseongkim | /// <summary> |
51 | /// 별도의 호출 사용 |
||
52 | /// </summary> |
||
53 | /// <param name="ProjectNo"></param> |
||
54 | /// <param name="originfilePath"></param> |
||
55 | /// <param name="DocumentID"></param> |
||
56 | /// <returns></returns> |
||
57 | 53c9637d | taeseongkim | public string ConvertMenualAdd(string ProjectNo, string originfilePath, string DocumentID) |
58 | { |
||
59 | string result = false.ToString(); |
||
60 | 06f13e11 | taeseongkim | string convertID = new Guid().CreateUniqueGuid().ToString().Replace("-", ""); |
61 | 53c9637d | taeseongkim | |
62 | try |
||
63 | { |
||
64 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
65 | { |
||
66 | if (!database.SetConvertDoc(ProjectNo, convertID, originfilePath, DocumentID)) |
||
67 | { |
||
68 | logger.Error($"Set Convert Document Error - ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}"); |
||
69 | } |
||
70 | else |
||
71 | { |
||
72 | 06f13e11 | taeseongkim | result = ConvertProcessAdd(ProjectNo, convertID); |
73 | 53c9637d | taeseongkim | } |
74 | } |
||
75 | } |
||
76 | catch (Exception ex) |
||
77 | { |
||
78 | result = "DataBase SetConvert Error"; |
||
79 | logger.Error($"ConvertMenualAdd Error- database.SetConvertDoc ProjectNo:{ProjectNo} UniqueID:{convertID} originfilePath:{originfilePath} DocumentID:{DocumentID}", ex); |
||
80 | } |
||
81 | 06f13e11 | taeseongkim | |
82 | 53c9637d | taeseongkim | return result; |
83 | } |
||
84 | |||
85 | a53dfe45 | taeseongkim | /// <summary> |
86 | /// ConvertItem의 상태 |
||
87 | /// </summary> |
||
88 | /// <param name="ProjectNo"></param> |
||
89 | /// <param name="DocumentID"></param> |
||
90 | /// <returns></returns> |
||
91 | public Item GetConvertItem(string ProjectNo, string DocumentID) |
||
92 | { |
||
93 | Item result = null; |
||
94 | |||
95 | try |
||
96 | { |
||
97 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
98 | { |
||
99 | var item = database.GetConvertItembyDocumentID(ProjectNo, DocumentID); |
||
100 | |||
101 | if (item != null) |
||
102 | { |
||
103 | result = |
||
104 | new Item |
||
105 | { |
||
106 | DocumentID = item.UniqueKey, |
||
107 | Status = item.ConvertState, |
||
108 | ProjectNo = item.ProjectNumber, |
||
109 | TotalPage = item.TotalPage, |
||
110 | CurrentPageNo = item.CurrentPageNo, |
||
111 | PdfPath = item.OriginfilePath, |
||
112 | ConvertPath = item.ConvertPath |
||
113 | }; |
||
114 | 53c9637d | taeseongkim | |
115 | a53dfe45 | taeseongkim | } |
116 | } |
||
117 | } |
||
118 | catch (Exception ex) |
||
119 | { |
||
120 | throw new FaultException("Get ConvertItem Error"); |
||
121 | } |
||
122 | 53c9637d | taeseongkim | |
123 | a53dfe45 | taeseongkim | return result; |
124 | } |
||
125 | |||
126 | /// <summary> |
||
127 | /// Convert Item을 DB에 추가 하고 프로세스 실행시 호출 |
||
128 | /// </summary> |
||
129 | /// <param name="ProjectNo"></param> |
||
130 | /// <param name="convertID"></param> |
||
131 | /// <returns></returns> |
||
132 | 53c9637d | taeseongkim | private string ConvertProcessAdd(string ProjectNo, string convertID) |
133 | { |
||
134 | string result = false.ToString(); |
||
135 | |||
136 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
137 | { |
||
138 | 06f13e11 | taeseongkim | var convertItem = database.GetConvertItem(ProjectNo, convertID); |
139 | 53c9637d | taeseongkim | |
140 | /// 순서별 Convert Item 처리 |
||
141 | if (convertItem != null) |
||
142 | { |
||
143 | try |
||
144 | { |
||
145 | cdfb57ff | taeseongkim | if (AliveConvertQueue.Count(c => c.UniqueKey == convertItem.UniqueKey) == 0) |
146 | { |
||
147 | 60723dc9 | taeseongkim | if (ServiceStation.AliveConvertQueue.Count() < ServiceProperty.PROCESS_COUNT) |
148 | cdfb57ff | taeseongkim | { |
149 | 0a89a17f | taeseongkim | convertItem.ServiceID = this.ServiceID; |
150 | cdfb57ff | taeseongkim | ConvertProcessStart(convertItem); |
151 | result = true.ToString(); |
||
152 | } |
||
153 | 949d5058 | taeseongkim | else |
154 | { |
||
155 | logger.Info($"ConvertAdd ConvertProcess Wait ProcessCount ProjectNo:{ProjectNo} convertID:{convertID} "); |
||
156 | result = true.ToString(); |
||
157 | } |
||
158 | cdfb57ff | taeseongkim | } |
159 | else |
||
160 | 53c9637d | taeseongkim | { |
161 | 0a89a17f | taeseongkim | PassConvertItem(ProjectNo, convertID, convertItem.UniqueKey); |
162 | 53c9637d | taeseongkim | result = true.ToString(); |
163 | } |
||
164 | } |
||
165 | catch (Exception ex) |
||
166 | { |
||
167 | result = "Convert Process Start Error"; |
||
168 | 949d5058 | taeseongkim | logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} ", ex); |
169 | 53c9637d | taeseongkim | } |
170 | } |
||
171 | else |
||
172 | { |
||
173 | 949d5058 | taeseongkim | logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} item Null "); |
174 | 53c9637d | taeseongkim | result = "Get ConvertItem Error"; |
175 | } |
||
176 | } |
||
177 | |||
178 | return result; |
||
179 | } |
||
180 | |||
181 | a53dfe45 | taeseongkim | /// <summary> |
182 | /// 각 ConvertProcess의 상태값을 저장 |
||
183 | /// </summary> |
||
184 | /// <param name="ConvertID"></param> |
||
185 | /// <param name="status"></param> |
||
186 | /// <param name="CurrentPage"></param> |
||
187 | /// <param name="TotalPage"></param> |
||
188 | /// <param name="Error"></param> |
||
189 | /// <returns></returns> |
||
190 | 06f13e11 | taeseongkim | public bool ConvertProcessState(string ConvertID, int status, int CurrentPage, int TotalPage, string Error) |
191 | 53c9637d | taeseongkim | { |
192 | 06f13e11 | taeseongkim | var items = AliveConvertQueue.Where(x => x.ConvertID == ConvertID); |
193 | |||
194 | if (items.Count() > 0) |
||
195 | 53c9637d | taeseongkim | { |
196 | var item = items.First(); |
||
197 | |||
198 | item.TotalPage = TotalPage; |
||
199 | item.CurrentPageNo = CurrentPage; |
||
200 | item.ConvertState = ((StatusCodeType)status).ToString(); |
||
201 | } |
||
202 | |||
203 | if (CurrentPage % SaveStatusInterval == 0 || !Error.IsNullOrEmpty()) |
||
204 | { |
||
205 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
206 | { |
||
207 | 0157b158 | taeseongkim | if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error)) |
208 | 53c9637d | taeseongkim | { |
209 | logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
||
210 | } |
||
211 | } |
||
212 | } |
||
213 | |||
214 | return true; |
||
215 | } |
||
216 | |||
217 | a53dfe45 | taeseongkim | /// <summary> |
218 | /// Convert Process 완료시 호출 |
||
219 | /// </summary> |
||
220 | /// <param name="ConvertID"></param> |
||
221 | /// <param name="status"></param> |
||
222 | /// <param name="CurrentPage"></param> |
||
223 | /// <param name="TotalPage"></param> |
||
224 | /// <param name="Error"></param> |
||
225 | /// <returns></returns> |
||
226 | 06f13e11 | taeseongkim | public bool ConvertFinish(string ConvertID, int status, int CurrentPage, int TotalPage, string Error) |
227 | 53c9637d | taeseongkim | { |
228 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
229 | { |
||
230 | 0157b158 | taeseongkim | if (!database.SetConvertState(this.ServiceID, ConvertID, status, CurrentPage, TotalPage, Error)) |
231 | 53c9637d | taeseongkim | { |
232 | logger.Error($"DataBase Error database.SetConvertState({ConvertID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
||
233 | } |
||
234 | } |
||
235 | |||
236 | var _convertItem = ServiceStation.AliveConvertQueue.Where(f => f.ConvertID == ConvertID); |
||
237 | |||
238 | if (_convertItem.Count() > 0) |
||
239 | 06f13e11 | taeseongkim | { |
240 | 53c9637d | taeseongkim | ConvertFinish(_convertItem.First()); |
241 | 06f13e11 | taeseongkim | } |
242 | 53c9637d | taeseongkim | |
243 | return true; |
||
244 | } |
||
245 | |||
246 | a53dfe45 | taeseongkim | /// <summary> |
247 | /// 대기중인 Convert Item을 가져옴 |
||
248 | /// </summary> |
||
249 | /// <returns></returns> |
||
250 | 53c9637d | taeseongkim | public List<ConvertItem> WaitConvertList() |
251 | { |
||
252 | List<ConvertItem> result = new List<ConvertItem>(); |
||
253 | |||
254 | using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(MarkusDBConnectionString)) |
||
255 | { |
||
256 | result = database.GetConvertItems(Message.StatusCodeType.Wait).ToList(); |
||
257 | } |
||
258 | |||
259 | return result; |
||
260 | } |
||
261 | |||
262 | a53dfe45 | taeseongkim | /// <summary> |
263 | /// 현재 AliveConvertQueue에 있는 컨버터 리스트 |
||
264 | /// </summary> |
||
265 | /// <returns></returns> |
||
266 | 53c9637d | taeseongkim | public List<ConvertItem> AliveConvertList() |
267 | { |
||
268 | 06f13e11 | taeseongkim | return ServiceStation.AliveConvertQueue; |
269 | 53c9637d | taeseongkim | } |
270 | |||
271 | a53dfe45 | taeseongkim | /// <summary> |
272 | /// WCF 시작 |
||
273 | /// </summary> |
||
274 | /// <returns></returns> |
||
275 | 53c9637d | taeseongkim | public CommunicationState StartWcfService() |
276 | { |
||
277 | CommunicationState result = CommunicationState.Faulted; |
||
278 | |||
279 | try |
||
280 | { |
||
281 | if (gServiceHostAddress != null) |
||
282 | { |
||
283 | gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress); |
||
284 | } |
||
285 | |||
286 | if (gWcfServiceHost?.State != CommunicationState.Faulted) |
||
287 | { |
||
288 | result = gWcfServiceHost.State; |
||
289 | } |
||
290 | } |
||
291 | catch (Exception ex) |
||
292 | { |
||
293 | logger.Error("Start WCF Service Error ", ex); |
||
294 | } |
||
295 | |||
296 | return result; |
||
297 | } |
||
298 | |||
299 | a53dfe45 | taeseongkim | /// <summary> |
300 | /// WCF 중단 |
||
301 | /// </summary> |
||
302 | /// <returns></returns> |
||
303 | 53c9637d | taeseongkim | private bool StopWcfService() |
304 | { |
||
305 | bool result = false; |
||
306 | try |
||
307 | { |
||
308 | gWcfServiceHost.Abort(); |
||
309 | result = true; |
||
310 | } |
||
311 | catch (Exception ex) |
||
312 | { |
||
313 | logger.Error("Stop WCF Service Error ", ex); |
||
314 | } |
||
315 | |||
316 | return result; |
||
317 | } |
||
318 | |||
319 | 06f13e11 | taeseongkim | public bool ReleaseConvertItems() |
320 | { |
||
321 | System.Diagnostics.Debug.WriteLine("Call ReleaseConvertItems"); |
||
322 | 60723dc9 | taeseongkim | if (!IsReleaseItems) |
323 | { |
||
324 | ReleaseItems(); |
||
325 | } |
||
326 | |||
327 | 06f13e11 | taeseongkim | System.Diagnostics.Debug.WriteLine("end ReleaseConvertItems"); |
328 | return true; |
||
329 | } |
||
330 | 53c9637d | taeseongkim | } |
331 | } |