프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / ConvertService / ServiceBase / Markus.Service.Station / StationService / ServiceStationTask.cs @ c7555c83

이력 | 보기 | 이력해설 | 다운로드 (23.9 KB)

1 a5e5fff6 taeseongkim
using Markus.Message;
2 53c9637d taeseongkim
using System;
3
using System.Collections.Generic;
4
using System.Diagnostics;
5
using System.Linq;
6
using System.Text;
7
using System.Threading;
8
using System.Threading.Tasks;
9
using System.Management;
10
using static Markus.Service.Extensions.Encrypt;
11
using Markus.Service.Extensions;
12
using Markus.Service.Helper;
13 a5e5fff6 taeseongkim
using Markus.Service.DataBase.Entities;
14
using Markus.Service.DataBase.Repositories;
15 53c9637d taeseongkim
16
namespace Markus.Service
17
{
18
    /// <summary>
19
    /// 컨버터 큐 처리 
20
    /// </summary>
21
    public partial class ServiceStation
22
    {
23
        /// <summary>
24
        /// 컨버터 실행중인 item
25
        /// </summary>
26 a5e5fff6 taeseongkim
        private static List<ConvertDoc> AliveConvertQueue = new List<ConvertDoc>();
27 53c9637d taeseongkim
28
        /// <summary>
29
        /// 컨버터 프로세스 실행
30
        /// </summary>
31
        /// <param name="convertitem"></param>
32 a5e5fff6 taeseongkim
        public bool ConvertProcessStart(ConvertDoc convertitem)
33 53c9637d taeseongkim
        {
34
            bool result = false;
35
            try
36
            {
37
                Process ConvertProcess = new Process();
38
39
                ProcessContext processSendData = new ProcessContext
40
                {
41 a5e5fff6 taeseongkim
                    ConvertID = convertitem.ID,
42 53c9637d taeseongkim
                    ConnectionString = MarkusDBConnectionString,
43 731c84b8 taeseongkim
                    DbmsType = DBMSType.ToString(),
44 53c9637d taeseongkim
                    ServiceStationUri = gServiceHostAddress.ToString(),
45 a5e5fff6 taeseongkim
                    OriginFilePath = convertitem.DOCUMENT_URL,
46 53c9637d taeseongkim
                    SaveDirectory = convertitem.ConvertPath,
47
                    TempDirectory = DownloadTempFolder,
48 8feb21df taeseongkim
                    ReleaseWorkMemory = ReleaseWorkMemory,
49 53c9637d taeseongkim
                    MultiThreadMaxPages = MultiThreadMaxPages,
50
                    MinFontSize = MinFontSize,
51 2091a7e5 taeseongkim
                    SendStatusInterval = SaveStatusInterval,
52 950e6b84 taeseongkim
                    UseResolution = UseResolution,
53
                    FontsFolder = FontsFolder
54 53c9637d taeseongkim
                };
55
56
                var sendData = ObjectToBytesStringConvert.ObjectToBytesString(processSendData);
57 0a64fa85 taeseongkim
                var convertPath = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Convert");
58 1d79913e taeseongkim
59 53c9637d taeseongkim
                ProcessStartInfo startInfo = new ProcessStartInfo
60
                {
61
                    UseShellExecute = false,
62 0a64fa85 taeseongkim
                    FileName = System.IO.Path.Combine(convertPath, "Markus.Service.ConvertProcess.exe"),
63 53c9637d taeseongkim
                    WindowStyle = ProcessWindowStyle.Hidden,
64
                    CreateNoWindow = true,
65
                    ErrorDialog = false,
66
                    RedirectStandardError = false,
67 0a64fa85 taeseongkim
                    WorkingDirectory = convertPath,
68 a5e5fff6 taeseongkim
                    Arguments = $"{convertitem.ID.ToString()} {AESEncrypter.Encrypt(sendData)}"
69 53c9637d taeseongkim
                    //Arguments = $"{convertitem.ConvertID.ToString()} {convertitem.ProjectNumber} {AESEncrypter.Encrypt(MarkusDBConnectionString)} {gServiceHostAddress} {DownloadTempFolder} {MultiThreadMaxPages}"
70
                };
71
72
                ConvertProcess.StartInfo = startInfo;
73 1d79913e taeseongkim
                ConvertProcess.EnableRaisingEvents = true;
74
                
75 53c9637d taeseongkim
                System.Diagnostics.Debug.WriteLine("convert process run : " + startInfo.Arguments);
76
77 a5e5fff6 taeseongkim
                logger.Info($"convert process run : ConvertDoc ID:{convertitem.ID}" + startInfo.Arguments);
78 53c9637d taeseongkim
79
                if (ConvertProcess.Start())
80
                {
81
                    try
82
                    {
83
                        var processAffinity = ProcessorAffinityList.Except(AliveConvertQueue.Select(f => (long)f.ProcessorAffinity));
84
85 43e1d368 taeseongkim
                        long currentAffinity = 0;
86
87 53c9637d taeseongkim
                        if (processAffinity.Count() > 0)
88
                        {
89 43e1d368 taeseongkim
                            currentAffinity = processAffinity.First();
90 53c9637d taeseongkim
91
                            //int bitMask = 1 << (convertitem.ProcessorAffinity - 1);
92
                            //bitMask |= 1 << (anotherUserSelection - 1); / //  프로세스 두개 이상 선택
93
94 43e1d368 taeseongkim
                            ConvertProcess.ProcessorAffinity = new IntPtr(currentAffinity);
95 a5e5fff6 taeseongkim
                            logger.Info($"convert process currentAffinity set {currentAffinity} : ConvertDoc ID:{convertitem.ID}");
96 53c9637d taeseongkim
97
                        }
98
                        else
99
                        {
100 0a64fa85 taeseongkim
                            ConvertProcess.ProcessorAffinity = new IntPtr(DefaultAffinity);
101 53c9637d taeseongkim
102 a5e5fff6 taeseongkim
                            logger.Info($"convert process Affinity All use {currentAffinity} :  ConvertDoc ID:{convertitem.ID}");
103 43e1d368 taeseongkim
                        }
104
105
                        var item = AliveConvertQueue.Find(x => x.Equals(convertitem));
106
107
                        if (item != null)
108
                        {
109
                            item.ProcessorAffinity = currentAffinity;
110 53c9637d taeseongkim
                        }
111
                    }
112
                    catch (Exception ex)
113
                    {
114 43e1d368 taeseongkim
                        AliveConvertQueue.Remove(convertitem);
115 d91efe5c taeseongkim
                        logger.Error("ConvertProcessStart error", ex);
116 53c9637d taeseongkim
                    }
117
118 a5e5fff6 taeseongkim
                    logger.Info($"convert process run true ConvertDoc ID:{convertitem.ID}");
119 53c9637d taeseongkim
                    result = true;
120
                }
121
            }
122
            catch (Exception ex)
123
            {
124 43e1d368 taeseongkim
                AliveConvertQueue.Remove(convertitem);
125 a5e5fff6 taeseongkim
                throw new Exception("ConvertThread " + $" ConvertDoc ID:{convertitem.ID} {convertitem.PROJECT_NO} {AESEncrypter.Encrypt(MarkusDBConnectionString)} {gServiceHostAddress} {DownloadTempFolder} {MultiThreadMaxPages}", ex.InnerException);
126 53c9637d taeseongkim
            }
127
            finally
128
            {
129
                //GC.WaitForPendingFinalizers();
130
                //GC.Collect(2);
131
                //GC.Collect(2);
132
            }
133
134
            return result;
135
        }
136 0157b158 taeseongkim
    
137 53c9637d taeseongkim
        /// <summary>
138 4b33593a taeseongkim
        /// DB에 있는 대기중인 Item을 가져와서 프로세스 실행
139
        /// 
140 53c9637d taeseongkim
        /// </summary>
141
        public void setDataBaseWaitingList()
142
        {
143 731c84b8 taeseongkim
            using (ConvertDocRepository database = new ConvertDocRepository(MarkusDBConnectionString,DBMSType))
144 53c9637d taeseongkim
            {
145 a5e5fff6 taeseongkim
                int totalProcessCount = this.ServiceProperty.PROCESS_COUNT + StationServiceList.Where(x => x.IsOnline).Sum(f => f.Properties.PROCESS_COUNT);
146 0157b158 taeseongkim
147 a5e5fff6 taeseongkim
                var convertItems = database.GetWaitorErrorAsync(totalProcessCount).GetAwaiter().GetResult();
148 ff4b1e6e taeseongkim
149 a5e5fff6 taeseongkim
                foreach (var convert in convertItems)
150 1ae729e4 taeseongkim
                {
151 a5e5fff6 taeseongkim
                    //ReflashSubService();
152
153 4b33593a taeseongkim
                    if (AliveConvertQueue.Count(x => x.ID == convert.ID 
154
                                              || x.DOCUMENT_ID == convert.DOCUMENT_ID  // 같은 경로로 다운로드 및 작업되어 추가
155
                                              || (x.STATUS <= (int)StatusCodeType.Wait && x.DOCUMENT_URL == convert.DOCUMENT_URL)) == 0)
156
                                                 //  같은 url을 다운로드시 서버의 퍼포먼스가 좋지 않으면 다운로드 오류 발생하여 추가
157 0157b158 taeseongkim
                    {
158 a5e5fff6 taeseongkim
                        if (convert.STATUS > (int)StatusCodeType.None)
159 43e1d368 taeseongkim
                        {
160 a5e5fff6 taeseongkim
                            var result = database.SetCleanUpItemAsync(convert.ID, 1).GetAwaiter().GetResult();
161
162
                            if (result != 1)
163
                            {
164
                                throw new Exception($"SetCleanUpItem result :{result} {convert.ID}");
165
                            }
166 43e1d368 taeseongkim
                        }
167 a5e5fff6 taeseongkim
168
                        ConvertProcessAdd(convert.PROJECT_NO, convert.ID);
169
                        //PassConvertItem(convert.PROJECT_NO, convert.ID, convert.DOCUMENT_ID);
170
171
                        //System.Threading.Thread.Sleep(1000);
172 0157b158 taeseongkim
                    }
173 a5e5fff6 taeseongkim
#if DEBUG
174
                    else
175
                    {
176 4b33593a taeseongkim
                        if (AliveConvertQueue.Where(x => x.STATUS <= (int)StatusCodeType.Wait && x.DOCUMENT_URL == convert.DOCUMENT_URL) is var items)
177
                        {
178
                            if (System.Environment.UserInteractive)
179
                            {
180
                                if (items.Count() > 0)
181
                                {
182
                                    Console.WriteLine($"Same DOCUMENT_URL : {((StatusCodeType)items.First().STATUS).ToString()} - {items.First().DOCUMENT_URL}");
183
                                }
184
                            }
185
                        }
186
187 a5e5fff6 taeseongkim
                        if (AliveConvertQueue.Count(x => x.ID == convert.ID) > 0)
188
                        {
189
                            if (System.Environment.UserInteractive)
190
                            {
191 4b33593a taeseongkim
                                Console.WriteLine($"same convert.ID : {convert.ID}");
192 a5e5fff6 taeseongkim
                            }
193
                        }
194 1ae729e4 taeseongkim
195 a5e5fff6 taeseongkim
                        if (AliveConvertQueue.Count(x=> x.DOCUMENT_ID == convert.DOCUMENT_ID) > 0)
196
                        {
197
                            if (System.Environment.UserInteractive)
198
                            {
199 4b33593a taeseongkim
                                Console.WriteLine($"same convert.DOCUMENT_ID : {convert.DOCUMENT_ID}");
200 a5e5fff6 taeseongkim
                            }
201
                        }
202
                    }
203
#endif
204
                    /// 2022.11.28 수정
205
                    if (AliveConvertQueue.Count >= this.ServiceProperty.PROCESS_COUNT)
206
                    {
207
                        break;
208
                    }
209 43e1d368 taeseongkim
                }
210 53c9637d taeseongkim
            }
211 0157b158 taeseongkim
        }
212 53c9637d taeseongkim
213 a5e5fff6 taeseongkim
        /// <summary>
214
        /// DB에 있는 대기중인 Item을 가져온다.
215
        /// </summary>
216
        //public void setDataBaseWaitingLista()
217
        //{
218
219
        //    List<EntityModel.CONVERTER_DOC> convertItems = new List<EntityModel.CONVERTER_DOC>();
220
221 731c84b8 taeseongkim
        //    using (DataBase.ConvertDatabase database = new DataBase.ConvertDatabase(MarkusDBConnectionString,DBMSType))
222 a5e5fff6 taeseongkim
        //    {
223
        //        // 전체 서비스의 process count 만큼 waiting item을 가져온다.
224
        //        int totalProcessCount = this.ServiceProperty.PROCESS_COUNT + StationServiceList.Where(x => x.IsOnline).Sum(f => f.Properties.PROCESS_COUNT);
225
        //        convertItems = database.GetWaitConvertItems(this.RunProjectList, totalProcessCount).ToList();
226
        //    }
227
228
        //    foreach (var convert in convertItems)
229
        //    {
230
        //        //ReflashSubService();
231
232
        //        if (AliveConvertQueue.Count(x => x.ConvertID == convert.ID) == 0)
233
        //        {
234
        //            if (convert.STATUS > (int)StatusCodeType.None)
235
        //            {
236 731c84b8 taeseongkim
        //                using (DataBase.ConvertDatabase database = new DataBase.ConvertDatabase(MarkusDBConnectionString,DBMSType))
237 a5e5fff6 taeseongkim
        //                {
238
        //                    database.SetCleanUpItem(convert.ID, 1);
239
        //                }
240
        //            }
241
        //            ConvertProcessAdd(convert.PROJECT_NO, convert.ID);
242
        //            //PassConvertItem(convert.PROJECT_NO, convert.ID, convert.DOCUMENT_ID);
243
244
        //            //System.Threading.Thread.Sleep(1000);
245
        //        }
246
247
        //        /// 2022.11.28 수정
248
        //        if (AliveConvertQueue.Count >= this.ServiceProperty.PROCESS_COUNT)
249
        //        {
250
        //            break;
251
        //        }
252
        //    }
253
254
        //}
255
256 ff4b1e6e taeseongkim
        public bool IsDataBaseWaitingList(int overListCount)
257
        {
258
            bool result = false;
259
260
            try
261
            {
262 731c84b8 taeseongkim
                using (ConvertDocRepository convertDatabase = new ConvertDocRepository(MarkusDBConnectionString,DBMSType))
263 ff4b1e6e taeseongkim
                {
264 a5e5fff6 taeseongkim
                    var convertItems = convertDatabase.GetWaitorErrorAsync(overListCount).GetAwaiter().GetResult();
265 ff4b1e6e taeseongkim
266
                    if (convertItems.Count() > 0)
267
                    {
268
                        result = true;
269
                    }
270
                }
271
            }
272
            catch (Exception ex)
273
            {
274
                logger.Error($"IsDataBaseWaitingList Error",ex);
275
            }
276
277
            return result;
278
        }
279
280 43e1d368 taeseongkim
        private async Task<bool> ReflashSubServiceAsync()
281 0157b158 taeseongkim
        {
282 43e1d368 taeseongkim
            bool result = false;
283
284
            try
285 0157b158 taeseongkim
            {
286 43e1d368 taeseongkim
                foreach (var subservice in StationServiceList)
287 0157b158 taeseongkim
                {
288 43e1d368 taeseongkim
                    try
289 06f13e11 taeseongkim
                    {
290 0a64fa85 taeseongkim
                        if (subservice.Properties.ID == this.ServiceProperty.ID)
291 43e1d368 taeseongkim
                        {
292 0a64fa85 taeseongkim
                            subservice.ConvertItems = this.AliveConvertList();
293
                            subservice.AliveCount = this.AliveConvertList().Count();
294 43e1d368 taeseongkim
                        }
295
                        else
296
                        {
297 0a64fa85 taeseongkim
                            subservice.IsOnline = await SytemNet.PingAsync(subservice.Properties.SERVICE_ADDRESS);
298
299
                            if (subservice.IsOnline)
300
                            {
301
                                var alivelist = await subservice.Service.AliveConvertListAsync();
302
303
                                subservice.ConvertItems = alivelist.Select(x => 
304
                                                        new ConvertDoc(x.ID, x.PROJECT_NO, x.DOCUMENT_URL, x.DOCUMENT_ID, 
305
                                                        x.CREATE_DATETIME, x.STATUS, x.TOTAL_PAGE, x.CURRENT_PAGE,
306
                                                        x.RECONVERTER, x.EXCEPTION, x.END_DATETIME, x.START_DATETIME, x.SERVICE_ID)
307
                                                        ).ToList();
308
309
                                subservice.AliveCount = alivelist.Count();
310
                            }
311
                            else
312
                            {
313
                                logger.Error($"Connection Error {subservice.Properties.SERVICE_ADDRESS}");
314
                                subservice.ConvertItems = new List<ConvertDoc>();
315
                                subservice.AliveCount = subservice.Properties.PROCESS_COUNT;
316
                            }
317 43e1d368 taeseongkim
                        }
318
319
                        result = true;
320 06f13e11 taeseongkim
                    }
321 43e1d368 taeseongkim
                    catch (Exception ex)
322 06f13e11 taeseongkim
                    {
323 43e1d368 taeseongkim
                        logger.Error($"ReflashSubService error - Service ID : {subservice.Properties.ID} ", ex);
324 06f13e11 taeseongkim
                    }
325 0157b158 taeseongkim
                }
326 6f6e7dbf taeseongkim
            }
327 43e1d368 taeseongkim
            catch (Exception ex)
328
            {
329
                logger.Error($"ReflashSubService error", ex);
330
            }
331
332
            return result;
333 6f6e7dbf taeseongkim
        }
334
335 06f13e11 taeseongkim
336 0a89a17f taeseongkim
        /// <summary>
337
        /// 
338
        /// </summary>
339
        /// <param name="ProjectNo"></param>
340
        /// <param name="ConvertID"></param>
341
        /// <param name="UniqueKey">Document ID(문서의 유일키)</param>
342 a5e5fff6 taeseongkim
        private async void PassConvertItem(string ProjectNo,string ConvertDocID,bool isSubStation = false)
343 6f6e7dbf taeseongkim
        {
344
            try
345
            {
346 43e1d368 taeseongkim
                IEnumerable<SubStationServiceItem> stationList = null;
347
348
                //if (!isSubStation)
349
                //{
350
                    stationList = StationServiceList.Where(x => x.IsOnline);
351
                //}
352
                //else
353
                //{
354
                //    stationList = StationServiceList.Where(x => x.Properties.ID != this.ServiceID && x.IsOnline);
355
                //}
356 06f13e11 taeseongkim
357 a5e5fff6 taeseongkim
                if (stationList.SelectMany(x => x.ConvertItems).Count(c => c.PROJECT_NO == ProjectNo && c.ID == ConvertDocID) == 0)
358 6f6e7dbf taeseongkim
                {
359 06f13e11 taeseongkim
                    var station = stationList.OrderByDescending(x => x.Properties.PROCESS_COUNT - x.AliveCount).FirstOrDefault();
360 6f6e7dbf taeseongkim
361
                    if (station != null)
362
                    {
363 60723dc9 taeseongkim
                        if (station.Properties.PROCESS_COUNT - station.AliveCount > 0)
364 ff4b1e6e taeseongkim
                        {
365 60723dc9 taeseongkim
                            System.Diagnostics.Debug.WriteLine($"{station.Properties.SERVICE_ADDRESS}  {station.Properties.PROCESS_COUNT}/{station.AliveCount}");
366 a5e5fff6 taeseongkim
                            var result = await station.Service.PassConvertAsync(ProjectNo, ConvertDocID);
367 60723dc9 taeseongkim
368
                            if (!result.IsNullOrEmpty())
369
                            {
370
                                if (result.ToLower() == true.ToString().ToLower())
371
                                {
372 a5e5fff6 taeseongkim
                                    Console.WriteLine($"PassConvertItem - Service ID : {station.Properties.ID} ConvertDocID : {ConvertDocID}");
373
                                    logger.Info($"PassConvertItem - Service ID : {station.Properties.ID} ConvertDocID : {ConvertDocID}");
374 43e1d368 taeseongkim
375 60723dc9 taeseongkim
                                    station.AliveCount++;
376
                                }
377 43e1d368 taeseongkim
                                else
378
                                {
379 a5e5fff6 taeseongkim
                                        logger.Error($"PassConvertItem Error result : {result} - Service ID : {station.Properties.ID} ConvertDocID : {ConvertDocID}");
380 43e1d368 taeseongkim
                                }
381 60723dc9 taeseongkim
                            }
382
                            else
383
                            {
384 a5e5fff6 taeseongkim
                                logger.Error($"PassConvertItem result: Nulll; - Service ID : {station.Properties.ID} ConvertDocID : {ConvertDocID}");
385 60723dc9 taeseongkim
                                System.Diagnostics.Debug.WriteLine("result : Nulll;");
386
                            }
387 ff4b1e6e taeseongkim
                        }
388 6f6e7dbf taeseongkim
                    }
389 0157b158 taeseongkim
                }
390
            }
391 6f6e7dbf taeseongkim
            catch (Exception ex)
392
            {
393 0a64fa85 taeseongkim
                logger.Error($"PassConvertItem", ex);
394 6f6e7dbf taeseongkim
            }
395 0157b158 taeseongkim
        }
396
397 ff4b1e6e taeseongkim
        /// <summary>
398
        /// 컨버터 프로세스와 AiliveItems을 비교하여 AliveItems에 없는 경우 AliveItems을 제거
399
        /// </summary>
400 06f13e11 taeseongkim
        private void CleanUpAliveQueueItems()
401
        {
402 ff4b1e6e taeseongkim
            if (AliveConvertQueue.Count() > 0)
403 06f13e11 taeseongkim
            {
404 ff4b1e6e taeseongkim
                var processList = Process.GetProcessesByName("Markus.Service.ConvertProcess");
405 06f13e11 taeseongkim
406 ff4b1e6e taeseongkim
                if (processList.Length == 0)
407 06f13e11 taeseongkim
                {
408 ff4b1e6e taeseongkim
                    AliveConvertQueue.Clear();
409
                    System.Diagnostics.Debug.WriteLine("AliveConvertQueue.Clear()");
410
                }
411
                else
412
                {
413 a5e5fff6 taeseongkim
                    var argumentList = processList.Where(x=> !x.HasExited).Select(f => f.Arguments().CommandLine).SelectMany(f => f).ToList();
414 ff4b1e6e taeseongkim
415 a5e5fff6 taeseongkim
                    List<ConvertDoc> convertItems = AliveConvertQueue;
416 60723dc9 taeseongkim
417
                    try
418 06f13e11 taeseongkim
                    {
419 d91efe5c taeseongkim
                        if (convertItems.Count() > 0 && argumentList.Count() > 0)
420 ff4b1e6e taeseongkim
                        {
421 1ae729e4 taeseongkim
                            for (int i = convertItems.Count - 1; i >= 0; --i)
422 60723dc9 taeseongkim
                            {
423 a5e5fff6 taeseongkim
                                if (argumentList.Count(x => x == convertItems[i].ID) == 0)
424 1ae729e4 taeseongkim
                                {
425 a5e5fff6 taeseongkim
                                    System.Diagnostics.Debug.WriteLine($"AliveConvertQueue remove {convertItems[i].ID}");
426
                                    logger.Warn($"AliveConvertQueue remove {convertItems[i].ID}");
427 43e1d368 taeseongkim
                                    AliveConvertQueue.Remove(convertItems[i]);
428
429 1ae729e4 taeseongkim
                                }
430 60723dc9 taeseongkim
                            }
431 ff4b1e6e taeseongkim
                        }
432 06f13e11 taeseongkim
                    }
433 60723dc9 taeseongkim
                    catch (Exception ex)
434
                    {
435 d91efe5c taeseongkim
                        logger.Error("CleanUpAliveQueueItems error",ex);
436 60723dc9 taeseongkim
                    }
437 06f13e11 taeseongkim
                }
438
            }
439
        }
440
441 ff4b1e6e taeseongkim
        /// <summary>
442 60723dc9 taeseongkim
        /// AliveConvertQueue와 db를 비교하여 AliveConvertQueue에 없는 데이터를 초기화 하여 다시 컨버팅
443 ff4b1e6e taeseongkim
        /// </summary>
444
        private async void CleanUpDataBaseItems()
445 0157b158 taeseongkim
        {
446 150747cb taeseongkim
            try
447 53c9637d taeseongkim
            {
448 a5e5fff6 taeseongkim
                int totalProcessCount = this.ServiceProperty.PROCESS_COUNT + StationServiceList.Where(x => x.IsOnline).Sum(f => f.Properties.PROCESS_COUNT);
449
450 731c84b8 taeseongkim
                using (DataBase.Repositories.ConvertDocRepository repository = new DataBase.Repositories.ConvertDocRepository(MarkusDBConnectionString,DBMSType))
451 150747cb taeseongkim
                {
452 a5e5fff6 taeseongkim
                    var items = repository.GetConvertingItemAsync(totalProcessCount).GetAwaiter().GetResult();
453
454
                    List<ConvertDoc> aliveItems = new List<ConvertDoc>();
455 53c9637d taeseongkim
456 a5e5fff6 taeseongkim
                    aliveItems.AddRange(this.AliveConvertList());
457 0157b158 taeseongkim
458 60723dc9 taeseongkim
                    foreach (var item in StationServiceList.Where(x => x.IsOnline))
459 0157b158 taeseongkim
                    {
460 ff4b1e6e taeseongkim
                        var serviceItems = await item.Service.AliveConvertListAsync();
461 0a64fa85 taeseongkim
462
                        var convertDocItems = serviceItems.Select(x => new ConvertDoc(x.ID, x.PROJECT_NO, x.DOCUMENT_URL, x.DOCUMENT_ID,
463
                                                        x.CREATE_DATETIME, x.STATUS, x.TOTAL_PAGE, x.CURRENT_PAGE,
464
                                                        x.RECONVERTER, x.EXCEPTION, x.END_DATETIME, x.START_DATETIME, x.SERVICE_ID));
465
466
467
                        aliveItems.AddRange(convertDocItems);
468 0157b158 taeseongkim
                    }
469 60723dc9 taeseongkim
470 0a64fa85 taeseongkim
                    //if (aliveItems.Count() > 0)
471
                    //{
472
                    //logger.Warn($"aliveItems  : {string.Join(",",aliveItems.Select(x=>x.ID))}");
473 43e1d368 taeseongkim
474
                        foreach (var item in items)
475 60723dc9 taeseongkim
                        {
476 a5e5fff6 taeseongkim
                            if (aliveItems.Count(x => x.ID == item.ID) == 0)
477 43e1d368 taeseongkim
                            {
478
                                Console.WriteLine($"SetCleanUpItem  : {item.ID}");
479
                                logger.Warn($"SetCleanUpItem  : {item.ID}");
480 a5e5fff6 taeseongkim
                                repository.SetCleanUpItemAsync(item.ID, 0).GetAwaiter().GetResult();
481 43e1d368 taeseongkim
                            }
482 60723dc9 taeseongkim
                        }
483 0a64fa85 taeseongkim
                    //}
484 150747cb taeseongkim
             
485 53c9637d taeseongkim
                }
486 150747cb taeseongkim
            }
487
            catch (Exception ex)
488
            {
489
                throw new Exception("CleanUpDataBaseItems Error ", ex);
490 53c9637d taeseongkim
            }
491
        }
492
493
        public void Stopprocess()
494
        {
495
            var process = Process.GetProcessesByName("Markus.Service.ConvertProcess");
496
497
            for (int i = process.Count() - 1; i >= 0 ; i--)
498
            {
499
                try
500
                {
501
                    Console.WriteLine($"{i} Process Kill");
502
                    process[i].Kill();
503
                }
504
                catch (Exception ex)
505
                {
506
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
507
                }
508
            }
509
        }
510
511
        /// <summary>
512
        /// finish가 호출되고 살아있는 프로세스라고 추정됨
513
        /// </summary>
514
        public void DeadLockProcessKill()
515
        {
516
            var process = Process.GetProcessesByName("Markus.Service.ConvertProcess");
517
518
            for (int i = process.Count() - 1; i >= 0; i--)
519
            {
520
                try
521
                {
522
                    var commandLines = process[i].Arguments().CommandLine;
523
524
                    if (commandLines.Count() > 0)
525
                    {
526 a5e5fff6 taeseongkim
                        if (ServiceStation.AliveConvertQueue.Count(f => f.ID == commandLines[0]) == 0)
527 53c9637d taeseongkim
                        {
528
                            process[i].Kill();
529
                        }
530
                    }
531
                }
532
                catch (Exception ex)
533
                {
534
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
535
                }
536
            }
537
        }
538
539 a5e5fff6 taeseongkim
        private async void ConvertFinish(ConvertDoc convertitem)
540 53c9637d taeseongkim
        {
541
            try
542
            {
543 a5e5fff6 taeseongkim
                System.Diagnostics.Debug.WriteLine("Convert Finish : " + convertitem.ID);
544 53c9637d taeseongkim
545
                System.Diagnostics.Debug.WriteLine("ServiceStation.AliveConvertQueue.Count() : " + ServiceStation.AliveConvertQueue.Count());
546 1d79913e taeseongkim
547 a5e5fff6 taeseongkim
                List<string> deleteItems = new List<string> { convertitem.ID };
548 1d79913e taeseongkim
549
550 a5e5fff6 taeseongkim
                ServiceStation.AliveConvertQueue.RemoveAll(x=>deleteItems.Any(y=>y == x.ID));
551 53c9637d taeseongkim
552
                System.Diagnostics.Debug.WriteLine("ServiceStation.AliveConvertQueue.Count() : " + ServiceStation.AliveConvertQueue.Count());
553
554 06f13e11 taeseongkim
                if (IsStation)
555
                {
556 43e1d368 taeseongkim
                    if (!IsReleaseItems)
557
                    {
558
                        System.Diagnostics.Debug.WriteLine("ConvertFinish ReleaseItems call");
559
                        ReleaseItems();
560
                    }
561 06f13e11 taeseongkim
                }
562 0a64fa85 taeseongkim
                //else
563
                //{
564
                //    if (StationClient != null)
565
                //    {
566
                //       await  StationClient.ReleaseConvertItemsAsync();
567
                //    }
568
                //}
569 0157b158 taeseongkim
                //if (ServiceStation.AliveConvertQueue.Count() < MultiProcessCount)
570
                //{
571
                //    setDataBaseWaitingList();
572
                //}
573 53c9637d taeseongkim
            }
574
            catch (Exception ex)
575
            {
576
                logger.Error("ConvertFinish Error",ex);
577
            }
578
        }
579
    }
580
}
클립보드 이미지 추가 (최대 크기: 500 MB)