markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationWCF.cs @ ab7fe8c0
이력 | 보기 | 이력해설 | 다운로드 (16.2 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 | 731c84b8 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString,DBMSType)) |
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 | 731c84b8 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString,DBMSType)) |
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 | 731c84b8 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString,DBMSType)) |
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 | 731c84b8 | taeseongkim | using(PROPERTIESRepository repository = new PROPERTIESRepository(MarkusDBConnectionString,DBMSType)) |
169 | a5e5fff6 | taeseongkim | { |
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 | 731c84b8 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString,DBMSType)) |
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 | c1597feb | taeseongkim | else |
241 | { |
||
242 | if(Environment.UserInteractive) |
||
243 | { |
||
244 | Console.WriteLine($"run Process {convertItem.ID}"); |
||
245 | } |
||
246 | } |
||
247 | 43e1d368 | taeseongkim | |
248 | cdfb57ff | taeseongkim | result = true.ToString(); |
249 | } |
||
250 | 949d5058 | taeseongkim | else |
251 | { |
||
252 | 1d79913e | taeseongkim | logger.Warn($"ConvertProcessAdd PassConvertItem ProcessCount ProjectNo:{ProjectNo} convertID:{convertID} "); |
253 | /// sub service (다른ip의 서비스로 보낸다) 이중화 |
||
254 | a5e5fff6 | taeseongkim | PassConvertItem(ProjectNo, convertID, true); |
255 | 1d79913e | taeseongkim | |
256 | |||
257 | 949d5058 | taeseongkim | result = true.ToString(); |
258 | } |
||
259 | cdfb57ff | taeseongkim | } |
260 | else |
||
261 | 53c9637d | taeseongkim | { |
262 | result = true.ToString(); |
||
263 | } |
||
264 | } |
||
265 | catch (Exception ex) |
||
266 | { |
||
267 | result = "Convert Process Start Error"; |
||
268 | 949d5058 | taeseongkim | logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} ", ex); |
269 | 53c9637d | taeseongkim | } |
270 | } |
||
271 | else |
||
272 | { |
||
273 | 949d5058 | taeseongkim | logger.Error($"ConvertAdd ConvertProcess call Error ProjectNo:{ProjectNo} convertID:{convertID} item Null "); |
274 | 53c9637d | taeseongkim | result = "Get ConvertItem Error"; |
275 | } |
||
276 | } |
||
277 | |||
278 | return result; |
||
279 | } |
||
280 | |||
281 | a53dfe45 | taeseongkim | /// <summary> |
282 | /// 각 ConvertProcess의 상태값을 저장 |
||
283 | /// </summary> |
||
284 | /// <param name="ConvertID"></param> |
||
285 | /// <param name="status"></param> |
||
286 | /// <param name="CurrentPage"></param> |
||
287 | /// <param name="TotalPage"></param> |
||
288 | /// <param name="Error"></param> |
||
289 | /// <returns></returns> |
||
290 | a5e5fff6 | taeseongkim | public bool ConvertProcessState(string ConvertDocID, int status, int CurrentPage, int TotalPage, string Error) |
291 | 53c9637d | taeseongkim | { |
292 | 0a64fa85 | taeseongkim | bool isStatusChange = false; |
293 | |||
294 | 1d79913e | taeseongkim | if (AliveConvertQueue.Count() > 0) |
295 | 53c9637d | taeseongkim | { |
296 | a5e5fff6 | taeseongkim | var items = AliveConvertQueue.Where(x => x.ID == ConvertDocID); |
297 | 53c9637d | taeseongkim | |
298 | 1d79913e | taeseongkim | if (items.Count() > 0) |
299 | { |
||
300 | var item = items.First(); |
||
301 | 53c9637d | taeseongkim | |
302 | a5e5fff6 | taeseongkim | item.TOTAL_PAGE = TotalPage; |
303 | item.CURRENT_PAGE = CurrentPage; |
||
304 | 0a64fa85 | taeseongkim | |
305 | if (item.STATUS != status) |
||
306 | { |
||
307 | item.STATUS = status; |
||
308 | isStatusChange = true; |
||
309 | } |
||
310 | 1d79913e | taeseongkim | } |
311 | } |
||
312 | |||
313 | 0a64fa85 | taeseongkim | if (isStatusChange || CurrentPage % SaveStatusInterval == 0 || !Error.IsNullOrEmpty()) |
314 | 53c9637d | taeseongkim | { |
315 | 731c84b8 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString,DBMSType)) |
316 | 53c9637d | taeseongkim | { |
317 | a5e5fff6 | taeseongkim | var result = database.UpdateStatusAsync(this.ServiceID, ConvertDocID, status, CurrentPage, TotalPage, Error).GetAwaiter().GetResult(); |
318 | |||
319 | if (result < 1) |
||
320 | 53c9637d | taeseongkim | { |
321 | a5e5fff6 | taeseongkim | logger.Error($"DataBase Error database.SetConvertState({ConvertDocID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
322 | 53c9637d | taeseongkim | } |
323 | } |
||
324 | } |
||
325 | |||
326 | return true; |
||
327 | } |
||
328 | |||
329 | a53dfe45 | taeseongkim | /// <summary> |
330 | /// Convert Process 완료시 호출 |
||
331 | /// </summary> |
||
332 | /// <param name="ConvertID"></param> |
||
333 | /// <param name="status"></param> |
||
334 | /// <param name="CurrentPage"></param> |
||
335 | /// <param name="TotalPage"></param> |
||
336 | /// <param name="Error"></param> |
||
337 | /// <returns></returns> |
||
338 | a5e5fff6 | taeseongkim | public bool ConvertFinish(string ConvertDocID, int status, int CurrentPage, int TotalPage, string Error) |
339 | 53c9637d | taeseongkim | { |
340 | 731c84b8 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString,DBMSType)) |
341 | 53c9637d | taeseongkim | { |
342 | a5e5fff6 | taeseongkim | var result = database.UpdateStatusAsync(this.ServiceID, ConvertDocID, status, CurrentPage, TotalPage, Error).GetAwaiter().GetResult(); |
343 | |||
344 | if (result < 1) |
||
345 | 53c9637d | taeseongkim | { |
346 | a5e5fff6 | taeseongkim | logger.Error($"DataBase Error database.SetConvertState({ConvertDocID}, {(int)status},{CurrentPage},{TotalPage}, {Error})"); |
347 | 53c9637d | taeseongkim | } |
348 | } |
||
349 | |||
350 | a5e5fff6 | taeseongkim | var _convertItem = AliveConvertQueue.Where(f => f.ID == ConvertDocID); |
351 | 53c9637d | taeseongkim | |
352 | if (_convertItem.Count() > 0) |
||
353 | 06f13e11 | taeseongkim | { |
354 | 53c9637d | taeseongkim | ConvertFinish(_convertItem.First()); |
355 | 06f13e11 | taeseongkim | } |
356 | 53c9637d | taeseongkim | |
357 | return true; |
||
358 | } |
||
359 | |||
360 | a53dfe45 | taeseongkim | /// <summary> |
361 | /// 대기중인 Convert Item을 가져옴 |
||
362 | /// </summary> |
||
363 | /// <returns></returns> |
||
364 | a5e5fff6 | taeseongkim | public List<ConvertDoc> WaitConvertList() |
365 | 53c9637d | taeseongkim | { |
366 | a5e5fff6 | taeseongkim | List<ConvertDoc> result = new List<ConvertDoc>(); |
367 | |||
368 | 731c84b8 | taeseongkim | using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString,DBMSType)) |
369 | 53c9637d | taeseongkim | { |
370 | a5e5fff6 | taeseongkim | result = database.GetConvertDocAsync((int)Message.StatusCodeType.Wait).GetAwaiter().GetResult().ToList(); |
371 | 53c9637d | taeseongkim | } |
372 | |||
373 | return result; |
||
374 | } |
||
375 | |||
376 | a53dfe45 | taeseongkim | /// <summary> |
377 | /// 현재 AliveConvertQueue에 있는 컨버터 리스트 |
||
378 | /// </summary> |
||
379 | /// <returns></returns> |
||
380 | a5e5fff6 | taeseongkim | public List<ConvertDoc> AliveConvertList() |
381 | 53c9637d | taeseongkim | { |
382 | 06f13e11 | taeseongkim | return ServiceStation.AliveConvertQueue; |
383 | 53c9637d | taeseongkim | } |
384 | |||
385 | a53dfe45 | taeseongkim | /// <summary> |
386 | /// WCF 시작 |
||
387 | /// </summary> |
||
388 | /// <returns></returns> |
||
389 | 53c9637d | taeseongkim | public CommunicationState StartWcfService() |
390 | { |
||
391 | CommunicationState result = CommunicationState.Faulted; |
||
392 | |||
393 | try |
||
394 | { |
||
395 | if (gServiceHostAddress != null) |
||
396 | { |
||
397 | gWcfServiceHost = gWcfServiceHost.WcfCreate(this, typeof(IWcfService.IStationService), gServiceHostAddress); |
||
398 | } |
||
399 | |||
400 | if (gWcfServiceHost?.State != CommunicationState.Faulted) |
||
401 | { |
||
402 | result = gWcfServiceHost.State; |
||
403 | } |
||
404 | } |
||
405 | catch (Exception ex) |
||
406 | { |
||
407 | logger.Error("Start WCF Service Error ", ex); |
||
408 | } |
||
409 | |||
410 | return result; |
||
411 | } |
||
412 | |||
413 | a53dfe45 | taeseongkim | /// <summary> |
414 | /// WCF 중단 |
||
415 | /// </summary> |
||
416 | /// <returns></returns> |
||
417 | 53c9637d | taeseongkim | private bool StopWcfService() |
418 | { |
||
419 | bool result = false; |
||
420 | try |
||
421 | { |
||
422 | 0a64fa85 | taeseongkim | if (gWcfServiceHost != null) |
423 | { |
||
424 | gWcfServiceHost.Abort(); |
||
425 | } |
||
426 | |||
427 | 53c9637d | taeseongkim | result = true; |
428 | } |
||
429 | catch (Exception ex) |
||
430 | { |
||
431 | logger.Error("Stop WCF Service Error ", ex); |
||
432 | } |
||
433 | |||
434 | return result; |
||
435 | } |
||
436 | |||
437 | 06f13e11 | taeseongkim | public bool ReleaseConvertItems() |
438 | { |
||
439 | System.Diagnostics.Debug.WriteLine("Call ReleaseConvertItems"); |
||
440 | 60723dc9 | taeseongkim | if (!IsReleaseItems) |
441 | { |
||
442 | ReleaseItems(); |
||
443 | } |
||
444 | |||
445 | 06f13e11 | taeseongkim | System.Diagnostics.Debug.WriteLine("end ReleaseConvertItems"); |
446 | return true; |
||
447 | } |
||
448 | 53c9637d | taeseongkim | } |
449 | } |