markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationWCF.cs @ 0a64fa85
이력 | 보기 | 이력해설 | 다운로드 (15.8 KB)
1 | 53c9637d | taeseongkim | using Markus.Message; |
---|---|---|---|
2 | a5e5fff6 | taeseongkim | using Markus; |
3 | using Markus.Service.DataBase; |
||
4 | using Markus.Service.DataBase.Repositories; |
||
5 | 53c9637d | taeseongkim | using Markus.Service.Extensions; |
6 | using Markus.Service.IWcfService; |
||
7 | using System; |
||
8 | using System.Collections.Generic; |
||
9 | using System.Diagnostics; |
||
10 | using System.Linq; |
||
11 | using System.ServiceModel; |
||
12 | using System.ServiceModel.Activation; |
||
13 | using System.ServiceModel.Web; |
||
14 | using System.Text; |
||
15 | using System.Threading.Tasks; |
||
16 | a5e5fff6 | taeseongkim | using Markus.Service.DataBase.Entities; |
17 | 53c9637d | taeseongkim | |
18 | namespace Markus.Service |
||
19 | { |
||
20 | a53dfe45 | taeseongkim | /// <summary> |
21 | /// web service 목록 |
||
22 | /// </summary> |
||
23 | 53c9637d | taeseongkim | [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] |
24 | 1ae729e4 | taeseongkim | //[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true)] |
25 | 53c9637d | taeseongkim | public partial class ServiceStation : IStationService |
26 | { |
||
27 | a53dfe45 | taeseongkim | /// <summary> |
28 | /// DB에 Convrert Item을 추가 하고 호출 |
||
29 | /// CovnertWebService에서 호출시 사용 |
||
30 | /// </summary> |
||
31 | /// <param name="ProjectNo"></param> |
||
32 | /// <param name="ConvertID"></param> |
||
33 | /// <returns></returns> |
||
34 | 53c9637d | taeseongkim | public string ConvertAdd(string ProjectNo, string ConvertID) |
35 | { |
||
36 | string result = false.ToString(); |
||
37 | |||
38 | try |
||
39 | { |
||
40 | 06f13e11 | taeseongkim | result = ConvertProcessAdd(ProjectNo, ConvertID); |
41 | 949d5058 | taeseongkim | |
42 | logger.Info($"ConvertAdd Call Item ProjectNo : {ProjectNo} ConvertID : {ConvertID} result : {result}"); |
||
43 | 53c9637d | taeseongkim | } |
44 | catch (Exception ex) |
||
45 | { |
||
46 | result = $"ConvertAdd Error {ConvertID}"; |
||
47 | logger.Error($"ConvertAdd Error- {ConvertID}", ex); |
||
48 | } |
||
49 | |||
50 | return result; |
||
51 | } |
||
52 | |||
53 | 1d79913e | taeseongkim | |
54 | /// <summary> |
||
55 | /// Main Station에서 전달받은 convert item |
||
56 | /// </summary> |
||
57 | /// <param name="ProjectNo"></param> |
||
58 | a5e5fff6 | taeseongkim | /// <param name="ConvertDocID"></param> |
59 | 1d79913e | taeseongkim | /// <returns></returns> |
60 | a5e5fff6 | taeseongkim | public string PassConvert(string ProjectNo, string ConvertDocID) |
61 | 1d79913e | taeseongkim | { |
62 | string result = false.ToString(); |
||
63 | |||
64 | try |
||
65 | { |
||
66 | a5e5fff6 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString)) |
67 | 1d79913e | taeseongkim | { |
68 | a5e5fff6 | taeseongkim | var convertItem = database.GetConvertDocSingleAsync(ProjectNo:ProjectNo,ConvertID:ConvertDocID).GetAwaiter().GetResult(); |
69 | 1d79913e | taeseongkim | |
70 | /// 순서별 Convert Item 처리 |
||
71 | if (convertItem != null) |
||
72 | { |
||
73 | a5e5fff6 | taeseongkim | if (AliveConvertQueue.Count(c => c.ID == convertItem.ID) == 0) |
74 | 1d79913e | taeseongkim | { |
75 | a5e5fff6 | taeseongkim | result = ConvertProcessAdd(ProjectNo, ConvertDocID); |
76 | logger.Info($"PassConvert Item ProjectNo : {ProjectNo} ConvertDocID : {ConvertDocID} result : {result}"); |
||
77 | 1d79913e | taeseongkim | } |
78 | else |
||
79 | { |
||
80 | |||
81 | } |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | catch (Exception ex) |
||
86 | { |
||
87 | a5e5fff6 | taeseongkim | result = $"PassConvert Error {ConvertDocID}"; |
88 | logger.Error($"PassConvert Error- {ConvertDocID}", ex); |
||
89 | 1d79913e | taeseongkim | } |
90 | |||
91 | return result; |
||
92 | } |
||
93 | |||
94 | |||
95 | a53dfe45 | taeseongkim | /// <summary> |
96 | /// 별도의 호출 사용 |
||
97 | /// </summary> |
||
98 | /// <param name="ProjectNo"></param> |
||
99 | /// <param name="originfilePath"></param> |
||
100 | /// <param name="DocumentID"></param> |
||
101 | /// <returns></returns> |
||
102 | 53c9637d | taeseongkim | public string ConvertMenualAdd(string ProjectNo, string originfilePath, string DocumentID) |
103 | { |
||
104 | string result = false.ToString(); |
||
105 | |||
106 | try |
||
107 | { |
||
108 | a5e5fff6 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString)) |
109 | 53c9637d | taeseongkim | { |
110 | 0a64fa85 | taeseongkim | //var convertItem = database.GetConvertDocSingleAsync(ProjectNo: ProjectNo, DocumentID: DocumentID).GetAwaiter().GetResult(); |
111 | 5d863c06 | taeseongkim | |
112 | 0a64fa85 | taeseongkim | //if (convertItem != null) |
113 | //{ |
||
114 | var newConvertDocId = database.CreateAsync(ProjectNo, originfilePath, DocumentID).GetAwaiter().GetResult(); |
||
115 | |||
116 | if (newConvertDocId == null) |
||
117 | 5d863c06 | taeseongkim | { |
118 | 0a64fa85 | taeseongkim | logger.Error($"Set Convert document Insert Error - createId is Null. ProjectNo:{ProjectNo} originfilePath:{originfilePath} DocumentID:{DocumentID}"); |
119 | } |
||
120 | else |
||
121 | { |
||
122 | var aliveItems = AliveConvertQueue.Where(x => x.DOCUMENT_ID == DocumentID); |
||
123 | 5d863c06 | taeseongkim | |
124 | 0a64fa85 | taeseongkim | if (aliveItems.Count() == 0) |
125 | a5e5fff6 | taeseongkim | { |
126 | 0a64fa85 | taeseongkim | result = ConvertProcessAdd(ProjectNo, newConvertDocId); |
127 | a5e5fff6 | taeseongkim | } |
128 | else |
||
129 | { |
||
130 | 0a64fa85 | taeseongkim | logger.Info("ConvertMenualAdd Wait ProjectNo:{ ProjectNo} originfilePath: { originfilePath} DocumentID: { DocumentID}"); |
131 | a5e5fff6 | taeseongkim | } |
132 | 0a64fa85 | taeseongkim | |
133 | result = true.ToString(); |
||
134 | 53c9637d | taeseongkim | } |
135 | 0a64fa85 | taeseongkim | //} |
136 | 53c9637d | taeseongkim | } |
137 | } |
||
138 | catch (Exception ex) |
||
139 | { |
||
140 | a5e5fff6 | taeseongkim | result = "ConvertMenualAdd Error"; |
141 | logger.Error($"ConvertMenualAdd Error- database.SetConvertDoc ProjectNo:{ProjectNo} originfilePath:{originfilePath} DocumentID:{DocumentID}", ex); |
||
142 | 53c9637d | taeseongkim | } |
143 | 06f13e11 | taeseongkim | |
144 | 53c9637d | taeseongkim | return result; |
145 | } |
||
146 | |||
147 | a53dfe45 | taeseongkim | /// <summary> |
148 | /// ConvertItem의 상태 |
||
149 | /// </summary> |
||
150 | /// <param name="ProjectNo"></param> |
||
151 | /// <param name="DocumentID"></param> |
||
152 | /// <returns></returns> |
||
153 | public Item GetConvertItem(string ProjectNo, string DocumentID) |
||
154 | { |
||
155 | Item result = null; |
||
156 | |||
157 | try |
||
158 | { |
||
159 | a5e5fff6 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString)) |
160 | a53dfe45 | taeseongkim | { |
161 | |||
162 | a5e5fff6 | taeseongkim | var convertItem = database.GetConvertDocSingleAsync(ProjectNo: ProjectNo, DocumentID: DocumentID).GetAwaiter().GetResult(); |
163 | |||
164 | if (convertItem != null) |
||
165 | a53dfe45 | taeseongkim | { |
166 | a5e5fff6 | taeseongkim | string baseStoragePath = null; |
167 | |||
168 | using(PROPERTIESRepository repository = new PROPERTIESRepository(MarkusDBConnectionString)) |
||
169 | { |
||
170 | var propeties = repository.GetFirstAsync(ProjectNo, PropertiesTypeDefine.TILE_SOURCE_STORAGE).GetAwaiter().GetResult(); |
||
171 | |||
172 | if(propeties != null) |
||
173 | { |
||
174 | baseStoragePath = propeties.VALUE; |
||
175 | } |
||
176 | else |
||
177 | { |
||
178 | throw new FaultException($"Get {ProjectNo} is {PropertiesTypeDefine.TILE_SOURCE_STORAGE} null Error"); |
||
179 | } |
||
180 | } |
||
181 | |||
182 | var convertPath = CreateConvertPath.Get(baseStoragePath, ProjectNo, DocumentID); |
||
183 | |||
184 | a53dfe45 | taeseongkim | result = |
185 | new Item |
||
186 | { |
||
187 | a5e5fff6 | taeseongkim | DocumentID = convertItem.ID, |
188 | Status = convertItem.STATUS.ToString(), |
||
189 | ProjectNo = convertItem.PROJECT_NO, |
||
190 | TotalPage = convertItem.TOTAL_PAGE, |
||
191 | CurrentPageNo = convertItem.CURRENT_PAGE, |
||
192 | PdfPath = convertItem.DOCUMENT_URL, |
||
193 | ConvertPath = convertPath |
||
194 | a53dfe45 | taeseongkim | }; |
195 | 53c9637d | taeseongkim | |
196 | a53dfe45 | taeseongkim | } |
197 | } |
||
198 | } |
||
199 | catch (Exception ex) |
||
200 | { |
||
201 | throw new FaultException("Get ConvertItem Error"); |
||
202 | } |
||
203 | 53c9637d | taeseongkim | |
204 | a53dfe45 | taeseongkim | return result; |
205 | } |
||
206 | |||
207 | /// <summary> |
||
208 | /// Convert Item을 DB에 추가 하고 프로세스 실행시 호출 |
||
209 | /// </summary> |
||
210 | /// <param name="ProjectNo"></param> |
||
211 | /// <param name="convertID"></param> |
||
212 | /// <returns></returns> |
||
213 | 53c9637d | taeseongkim | private string ConvertProcessAdd(string ProjectNo, string convertID) |
214 | { |
||
215 | string result = false.ToString(); |
||
216 | 43e1d368 | taeseongkim | logger.Warn($"WCF ConvertProcessAdd Call ProjectNo:{ProjectNo} convertID:{convertID} "); |
217 | 53c9637d | taeseongkim | |
218 | a5e5fff6 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString)) |
219 | 53c9637d | taeseongkim | { |
220 | a5e5fff6 | taeseongkim | var convertItem = database.GetConvertDocSingleAsync(ProjectNo:ProjectNo,ConvertID:convertID).GetAwaiter().GetResult(); |
221 | 53c9637d | taeseongkim | |
222 | /// 순서별 Convert Item 처리 |
||
223 | if (convertItem != null) |
||
224 | { |
||
225 | try |
||
226 | { |
||
227 | a5e5fff6 | taeseongkim | if (AliveConvertQueue.Find(c => c.ID == convertItem.ID) == null) |
228 | cdfb57ff | taeseongkim | { |
229 | 43e1d368 | taeseongkim | if (AliveConvertQueue.Count() < ServiceProperty.PROCESS_COUNT) |
230 | cdfb57ff | taeseongkim | { |
231 | a5e5fff6 | taeseongkim | convertItem.SERVICE_ID = this.ServiceID; |
232 | 43e1d368 | taeseongkim | AliveConvertQueue.Add(convertItem); |
233 | 1d79913e | taeseongkim | |
234 | 43e1d368 | taeseongkim | var startResult = ConvertProcessStart(convertItem); |
235 | |||
236 | if(!startResult) |
||
237 | { |
||
238 | AliveConvertQueue.Remove(convertItem); |
||
239 | } |
||
240 | |||
241 | cdfb57ff | taeseongkim | result = true.ToString(); |
242 | } |
||
243 | 949d5058 | taeseongkim | else |
244 | { |
||
245 | 1d79913e | taeseongkim | logger.Warn($"ConvertProcessAdd PassConvertItem ProcessCount ProjectNo:{ProjectNo} convertID:{convertID} "); |
246 | /// sub service (다른ip의 서비스로 보낸다) 이중화 |
||
247 | a5e5fff6 | taeseongkim | PassConvertItem(ProjectNo, convertID, true); |
248 | 1d79913e | taeseongkim | |
249 | |||
250 | 949d5058 | taeseongkim | result = true.ToString(); |
251 | } |
||
252 | cdfb57ff | taeseongkim | } |
253 | else |
||
254 | 53c9637d | taeseongkim | { |
255 | result = true.ToString(); |
||
256 | } |
||
257 | } |
||
258 | catch (Exception ex) |
||
259 | { |
||
260 | result = "Convert Process Start Error"; |
||
261 | 949d5058 | taeseongkim | logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} ", ex); |
262 | 53c9637d | taeseongkim | } |
263 | } |
||
264 | else |
||
265 | { |
||
266 | 949d5058 | taeseongkim | logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} item Null "); |
267 | 53c9637d | taeseongkim | result = "Get ConvertItem Error"; |
268 | } |
||
269 | } |
||
270 | |||
271 | return result; |
||
272 | } |
||
273 | |||
274 | a53dfe45 | taeseongkim | /// <summary> |
275 | /// 각 ConvertProcess의 상태값을 저장 |
||
276 | /// </summary> |
||
277 | /// <param name="ConvertID"></param> |
||
278 | /// <param name="status"></param> |
||
279 | /// <param name="CurrentPage"></param> |
||
280 | /// <param name="TotalPage"></param> |
||
281 | /// <param name="Error"></param> |
||
282 | /// <returns></returns> |
||
283 | a5e5fff6 | taeseongkim | public bool ConvertProcessState(string ConvertDocID, int status, int CurrentPage, int TotalPage, string Error) |
284 | 53c9637d | taeseongkim | { |
285 | 0a64fa85 | taeseongkim | bool isStatusChange = false; |
286 | |||
287 | 1d79913e | taeseongkim | if (AliveConvertQueue.Count() > 0) |
288 | 53c9637d | taeseongkim | { |
289 | a5e5fff6 | taeseongkim | var items = AliveConvertQueue.Where(x => x.ID == ConvertDocID); |
290 | 53c9637d | taeseongkim | |
291 | 1d79913e | taeseongkim | if (items.Count() > 0) |
292 | { |
||
293 | var item = items.First(); |
||
294 | 53c9637d | taeseongkim | |
295 | a5e5fff6 | taeseongkim | item.TOTAL_PAGE = TotalPage; |
296 | item.CURRENT_PAGE = CurrentPage; |
||
297 | 0a64fa85 | taeseongkim | |
298 | if (item.STATUS != status) |
||
299 | { |
||
300 | item.STATUS = status; |
||
301 | isStatusChange = true; |
||
302 | } |
||
303 | 1d79913e | taeseongkim | } |
304 | } |
||
305 | |||
306 | 0a64fa85 | taeseongkim | if (isStatusChange || CurrentPage % SaveStatusInterval == 0 || !Error.IsNullOrEmpty()) |
307 | 53c9637d | taeseongkim | { |
308 | a5e5fff6 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString)) |
309 | 53c9637d | taeseongkim | { |
310 | a5e5fff6 | taeseongkim | var result = database.UpdateStatusAsync(this.ServiceID, ConvertDocID, status, CurrentPage, TotalPage, Error).GetAwaiter().GetResult(); |
311 | |||
312 | if (result < 1) |
||
313 | 53c9637d | taeseongkim | { |
314 | a5e5fff6 | taeseongkim | logger.Error($"DataBase Error database.SetConvertState({ConvertDocID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
315 | 53c9637d | taeseongkim | } |
316 | } |
||
317 | } |
||
318 | |||
319 | return true; |
||
320 | } |
||
321 | |||
322 | a53dfe45 | taeseongkim | /// <summary> |
323 | /// Convert Process 완료시 호출 |
||
324 | /// </summary> |
||
325 | /// <param name="ConvertID"></param> |
||
326 | /// <param name="status"></param> |
||
327 | /// <param name="CurrentPage"></param> |
||
328 | /// <param name="TotalPage"></param> |
||
329 | /// <param name="Error"></param> |
||
330 | /// <returns></returns> |
||
331 | a5e5fff6 | taeseongkim | public bool ConvertFinish(string ConvertDocID, int status, int CurrentPage, int TotalPage, string Error) |
332 | 53c9637d | taeseongkim | { |
333 | a5e5fff6 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString)) |
334 | 53c9637d | taeseongkim | { |
335 | a5e5fff6 | taeseongkim | var result = database.UpdateStatusAsync(this.ServiceID, ConvertDocID, status, CurrentPage, TotalPage, Error).GetAwaiter().GetResult(); |
336 | |||
337 | if (result < 1) |
||
338 | 53c9637d | taeseongkim | { |
339 | a5e5fff6 | taeseongkim | logger.Error($"DataBase Error database.SetConvertState({ConvertDocID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
340 | 53c9637d | taeseongkim | } |
341 | } |
||
342 | |||
343 | a5e5fff6 | taeseongkim | var _convertItem = AliveConvertQueue.Where(f => f.ID == ConvertDocID); |
344 | 53c9637d | taeseongkim | |
345 | if (_convertItem.Count() > 0) |
||
346 | 06f13e11 | taeseongkim | { |
347 | 53c9637d | taeseongkim | ConvertFinish(_convertItem.First()); |
348 | 06f13e11 | taeseongkim | } |
349 | 53c9637d | taeseongkim | |
350 | return true; |
||
351 | } |
||
352 | |||
353 | a53dfe45 | taeseongkim | /// <summary> |
354 | /// 대기중인 Convert Item을 가져옴 |
||
355 | /// </summary> |
||
356 | /// <returns></returns> |
||
357 | a5e5fff6 | taeseongkim | public List<ConvertDoc> WaitConvertList() |
358 | 53c9637d | taeseongkim | { |
359 | a5e5fff6 | taeseongkim | List<ConvertDoc> result = new List<ConvertDoc>(); |
360 | |||
361 | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString)) |
||
362 | 53c9637d | taeseongkim | { |
363 | a5e5fff6 | taeseongkim | result = database.GetConvertDocAsync((int)Message.StatusCodeType.Wait).GetAwaiter().GetResult().ToList(); |
364 | 53c9637d | taeseongkim | } |
365 | |||
366 | return result; |
||
367 | } |
||
368 | |||
369 | a53dfe45 | taeseongkim | /// <summary> |
370 | /// 현재 AliveConvertQueue에 있는 컨버터 리스트 |
||
371 | /// </summary> |
||
372 | /// <returns></returns> |
||
373 | a5e5fff6 | taeseongkim | public List<ConvertDoc> AliveConvertList() |
374 | 53c9637d | taeseongkim | { |
375 | 06f13e11 | taeseongkim | return ServiceStation.AliveConvertQueue; |
376 | 53c9637d | taeseongkim | } |
377 | |||
378 | a53dfe45 | taeseongkim | /// <summary> |
379 | /// WCF 시작 |
||
380 | /// </summary> |
||
381 | /// <returns></returns> |
||
382 | 53c9637d | taeseongkim | public CommunicationState StartWcfService() |
383 | { |
||
384 | CommunicationState result = CommunicationState.Faulted; |
||
385 | |||
386 | try |
||
387 | { |
||
388 | if (gServiceHostAddress != null) |
||
389 | { |
||
390 | gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress); |
||
391 | } |
||
392 | |||
393 | if (gWcfServiceHost?.State != CommunicationState.Faulted) |
||
394 | { |
||
395 | result = gWcfServiceHost.State; |
||
396 | } |
||
397 | } |
||
398 | catch (Exception ex) |
||
399 | { |
||
400 | logger.Error("Start WCF Service Error ", ex); |
||
401 | } |
||
402 | |||
403 | return result; |
||
404 | } |
||
405 | |||
406 | a53dfe45 | taeseongkim | /// <summary> |
407 | /// WCF 중단 |
||
408 | /// </summary> |
||
409 | /// <returns></returns> |
||
410 | 53c9637d | taeseongkim | private bool StopWcfService() |
411 | { |
||
412 | bool result = false; |
||
413 | try |
||
414 | { |
||
415 | 0a64fa85 | taeseongkim | if (gWcfServiceHost != null) |
416 | { |
||
417 | gWcfServiceHost.Abort(); |
||
418 | } |
||
419 | |||
420 | 53c9637d | taeseongkim | result = true; |
421 | } |
||
422 | catch (Exception ex) |
||
423 | { |
||
424 | logger.Error("Stop WCF Service Error ", ex); |
||
425 | } |
||
426 | |||
427 | return result; |
||
428 | } |
||
429 | |||
430 | 06f13e11 | taeseongkim | public bool ReleaseConvertItems() |
431 | { |
||
432 | System.Diagnostics.Debug.WriteLine("Call ReleaseConvertItems"); |
||
433 | 60723dc9 | taeseongkim | if (!IsReleaseItems) |
434 | { |
||
435 | ReleaseItems(); |
||
436 | } |
||
437 | |||
438 | 06f13e11 | taeseongkim | System.Diagnostics.Debug.WriteLine("end ReleaseConvertItems"); |
439 | return true; |
||
440 | } |
||
441 | 53c9637d | taeseongkim | } |
442 | } |