프로젝트

일반

사용자정보

개정판 43e1d368

ID43e1d3684849725d38b5c74b43d4bb593f546d7a
상위 d91efe5c
하위 42d49521

김태성이(가) 약 2년 전에 추가함

issue #0000 코드 정리

Change-Id: I7c8ba4ef6d78a7e4f51b72f226507cddac722939

차이점 보기:

ConvertService/ServiceBase/Markus.Service.Station/StationService/ServiceStationTask.cs
53 53
                };
54 54

  
55 55
                var sendData = ObjectToBytesStringConvert.ObjectToBytesString(processSendData);
56
                
56

  
57
#if DEBUG
58
                var convertPath = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Markus.Service.ConvertProcess.exe");
59
#else
60
                var convertPath = System.IO.Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Convert\\Markus.Service.ConvertProcess.exe");
61
#endif
57 62
                ProcessStartInfo startInfo = new ProcessStartInfo
58 63
                {
59 64
                    UseShellExecute = false,
60
                    FileName = "Markus.Service.ConvertProcess.exe",
65
                    FileName = convertPath,
61 66
                    WindowStyle = ProcessWindowStyle.Hidden,
62 67
                    CreateNoWindow = true,
63 68
                    ErrorDialog = false,
......
71 76

  
72 77
                System.Diagnostics.Debug.WriteLine("convert process run : " + startInfo.Arguments);
73 78

  
79
                logger.Info($"convert process run : UniqueKey:{convertitem.UniqueKey}   ConvertID:{convertitem.ConvertID}" + startInfo.Arguments);
74 80

  
75 81
                if (ConvertProcess.Start())
76 82
                {
......
78 84
                    {
79 85
                        var processAffinity = ProcessorAffinityList.Except(AliveConvertQueue.Select(f => (long)f.ProcessorAffinity));
80 86

  
87
                        long currentAffinity = 0;
88

  
81 89
                        if (processAffinity.Count() > 0)
82 90
                        {
83
                            convertitem.ProcessorAffinity = processAffinity.First();
91
                            currentAffinity = processAffinity.First();
84 92

  
85 93
                            //int bitMask = 1 << (convertitem.ProcessorAffinity - 1);
86 94
                            //bitMask |= 1 << (anotherUserSelection - 1); / //  프로세스 두개 이상 선택
87 95

  
88
                            ConvertProcess.ProcessorAffinity = new IntPtr(convertitem.ProcessorAffinity);
96
                            ConvertProcess.ProcessorAffinity = new IntPtr(currentAffinity);
97
                            logger.Info($"convert process currentAffinity set {currentAffinity} : UniqueKey:{convertitem.UniqueKey}   ConvertID:{convertitem.ConvertID}");
89 98

  
90 99
                        }
91 100
                        else
92 101
                        {
93 102
                            // 모두 사용중일때 점유율이 작은 걸로 사용
94
                            var CurrentProcessAffinity = AliveConvertQueue.Select(f =>f.ProcessorAffinity).Distinct();
103
                            var CurrentProcessAffinity = AliveConvertQueue.Select(f => f.ProcessorAffinity).Distinct();
104

  
105
                            currentAffinity = CurrentProcessAffinity.Min();
106
                            ConvertProcess.ProcessorAffinity = new IntPtr(currentAffinity);
95 107

  
96
                            var affinity = CurrentProcessAffinity.Min();
108
                            logger.Info($"convert process Affinity All use {currentAffinity} : UniqueKey:{convertitem.UniqueKey}   ConvertID:{convertitem.ConvertID}");
97 109

  
98
                            convertitem.ProcessorAffinity = affinity;
99
                            ConvertProcess.ProcessorAffinity = new IntPtr(affinity);
110
                        }
111

  
112
                        var item = AliveConvertQueue.Find(x => x.Equals(convertitem));
113

  
114
                        if (item != null)
115
                        {
116
                            item.ProcessorAffinity = currentAffinity;
100 117
                        }
101 118
                    }
102 119
                    catch (Exception ex)
103 120
                    {
121
                        AliveConvertQueue.Remove(convertitem);
104 122
                        logger.Error("ConvertProcessStart error", ex);
105 123
                    }
106
        
107 124

  
108
                    ServiceStation.AliveConvertQueue.Add(convertitem);
125
                    logger.Info($"convert process run true UniqueKey:{convertitem.UniqueKey}   ConvertID:{convertitem.ConvertID}");
109 126
                    result = true;
110 127
                }
111 128
            }
112 129
            catch (Exception ex)
113 130
            {
131
                AliveConvertQueue.Remove(convertitem);
114 132
                throw new Exception("ConvertThread " + $"{convertitem.ConvertID.ToString()} {convertitem.ProjectNumber} {AESEncrypter.Encrypt(MarkusDBConnectionString)} {gServiceHostAddress} {DownloadTempFolder} {MultiThreadMaxPages}", ex.InnerException);
115 133
            }
116 134
            finally
......
139 157
            {
140 158
                //ReflashSubService();
141 159

  
142
                if (convert.STATUS > (int)StatusCodeType.None)
160
                if (AliveConvertQueue.Count(x => x.ConvertID == convert.ID) == 0)
143 161
                {
144
                    using (DataBase.ConvertDatabase database = new DataBase.ConvertDatabase(MarkusDBConnectionString))
162
                    if (convert.STATUS > (int)StatusCodeType.None)
145 163
                    {
146
                        database.SetCleanUpItem(convert.ID,1);
164
                        using (DataBase.ConvertDatabase database = new DataBase.ConvertDatabase(MarkusDBConnectionString))
165
                        {
166
                            database.SetCleanUpItem(convert.ID, 1);
167
                        }
147 168
                    }
148
                }
149 169

  
150
                PassConvertItem(convert.PROJECT_NO, convert.ID,convert.DOCUMENT_ID);
170
                    PassConvertItem(convert.PROJECT_NO, convert.ID, convert.DOCUMENT_ID);
171
                    
172
                    //System.Threading.Thread.Sleep(1000);
173
                }
151 174
            }
152 175
          
153 176
        }
......
176 199
            return result;
177 200
        }
178 201

  
179
        private async void ReflashSubServiceAsync()
202
        private async Task<bool> ReflashSubServiceAsync()
180 203
        {
181
            foreach (var subservice in StationServiceList)
204
            bool result = false;
205

  
206
            try
182 207
            {
183
                try
208
                foreach (var subservice in StationServiceList)
184 209
                {
185
                    subservice.IsOnline = await SytemNet.PingAsync(subservice.Properties.SERVICE_ADDRESS);
186

  
187
                    if (subservice.IsOnline)
210
                    try
188 211
                    {
189
                        var result = await subservice.Service.AliveConvertListAsync();
212
                        subservice.IsOnline = await SytemNet.PingAsync(subservice.Properties.SERVICE_ADDRESS);
213

  
214
                        if (subservice.IsOnline)
215
                        {
216
                            var alivelist = await subservice.Service.AliveConvertListAsync();
190 217

  
191
                        subservice.ConvertItems = result.ToList();
192
                        subservice.AliveCount = result.Count();
218
                            subservice.ConvertItems = alivelist.ToList();
219
                            subservice.AliveCount = alivelist.Count();
220
                        }
221
                        else
222
                        {
223
                            logger.Error($"Connection Error {subservice.Properties.SERVICE_ADDRESS}");
224
                            subservice.ConvertItems = new List<WcfClient.StationServiceTask.ConvertItem>();
225
                            subservice.AliveCount = subservice.Properties.PROCESS_COUNT;
226
                        }
227

  
228
                        result = true;
193 229
                    }
194
                    else
230
                    catch (Exception ex)
195 231
                    {
196
                        logger.Error($"Connection Error {subservice.Properties.SERVICE_ADDRESS}");
197
                        subservice.ConvertItems = new List<WcfClient.StationServiceTask.ConvertItem>();
198
                        subservice.AliveCount = subservice.Properties.PROCESS_COUNT;
232
                        logger.Error($"ReflashSubService error - Service ID : {subservice.Properties.ID} ", ex);
199 233
                    }
200 234
                }
201
                catch (Exception ex)
202
                {
203
                    logger.Error($"ReflashSubService error - Service ID : {subservice.Properties.ID} ", ex);
204
                }
205 235
            }
236
            catch (Exception ex)
237
            {
238
                logger.Error($"ReflashSubService error", ex);
239
            }
240

  
241
            return result;
206 242
        }
207 243

  
208 244

  
......
212 248
        /// <param name="ProjectNo"></param>
213 249
        /// <param name="ConvertID"></param>
214 250
        /// <param name="UniqueKey">Document ID(문서의 유일키)</param>
215
        private async void PassConvertItem(string ProjectNo,string ConvertID,string UniqueKey)
251
        private async void PassConvertItem(string ProjectNo,string ConvertID,string UniqueKey,bool isSubStation = false)
216 252
        {
217

  
218 253
            try
219 254
            {
220
                var stationList = StationServiceList.Where(x => x.IsOnline);
255
                IEnumerable<SubStationServiceItem> stationList = null;
256

  
257
                //if (!isSubStation)
258
                //{
259
                    stationList = StationServiceList.Where(x => x.IsOnline);
260
                //}
261
                //else
262
                //{
263
                //    stationList = StationServiceList.Where(x => x.Properties.ID != this.ServiceID && x.IsOnline);
264
                //}
221 265

  
222 266
                if (stationList.SelectMany(x => x.ConvertItems).Count(c => c.ProjectNumber == ProjectNo && c.UniqueKey == UniqueKey) == 0)
223 267
                {
......
234 278
                            {
235 279
                                if (result.ToLower() == true.ToString().ToLower())
236 280
                                {
281
                                    Console.WriteLine($"PassConvertItem - Service ID : {station.Properties.ID} ConvertID : {ConvertID}");
282
                                    logger.Info($"PassConvertItem - Service ID : {station.Properties.ID} ConvertID : {ConvertID}");
283

  
237 284
                                    station.AliveCount++;
238 285
                                }
286
                                else
287
                                {
288
                                    logger.Error($"PassConvertItem Error result : {result} - Service ID : {station.Properties.ID} ConvertID : {ConvertID}");
289
                                }
239 290
                            }
240 291
                            else
241 292
                            {
293
                                logger.Error($"PassConvertItem result: Nulll; - Service ID : {station.Properties.ID} ConvertID : {ConvertID}");
242 294
                                System.Diagnostics.Debug.WriteLine("result : Nulll;");
243 295
                            }
244
                            Console.WriteLine($"PassConvertItem - Service ID : {station.Properties.ID} ConvertID : {ConvertID}");
245
                            logger.Info($"PassConvertItem - Service ID : {station.Properties.ID} ConvertID : {ConvertID}");
246 296
                        }
247 297
                    }
248 298
                }
......
281 331
                            {
282 332
                                if (argumentList.Count(x => x == convertItems[i].ConvertID) == 0)
283 333
                                {
284
                                    AliveConvertQueue.RemoveAll(x => x.ConvertID == convertItems[i].ConvertID);
285 334
                                    System.Diagnostics.Debug.WriteLine($"AliveConvertQueue remove {convertItems[i].ConvertID}");
335
                                    logger.Warn($"AliveConvertQueue remove {convertItems[i].ConvertID}");
336
                                    AliveConvertQueue.Remove(convertItems[i]);
337

  
286 338
                                }
287 339
                            }
288 340
                        }
......
314 366
                        aliveItems.AddRange(serviceItems);
315 367
                    }
316 368

  
317
                    foreach (var item in items)
369
                    if (aliveItems.Count() > 0)
318 370
                    {
319
                        if (aliveItems.Count(x => x.ConvertID == item.ID) == 0)
371
                        logger.Warn($"aliveItems  : {string.Join(",",aliveItems.Select(x=>x.ConvertID))}");
372

  
373
                        foreach (var item in items)
320 374
                        {
321
                            Console.WriteLine($"SetCleanUpItem  : {item.ID}");
322
                            database.SetCleanUpItem(item.ID,0);
375
                            if (aliveItems.Count(x => x.ConvertID == item.ID) == 0)
376
                            {
377
                                Console.WriteLine($"SetCleanUpItem  : {item.ID}");
378
                                logger.Warn($"SetCleanUpItem  : {item.ID}");
379
                                database.SetCleanUpItem(item.ID, 0);
380
                            }
323 381
                        }
324 382
                    }
325 383
             
......
331 389
            }
332 390
        }
333 391

  
334

  
335 392
        public void Stopprocess()
336 393
        {
337 394
            var process = Process.GetProcessesByName("Markus.Service.ConvertProcess");
......
392 449

  
393 450
                if (IsStation)
394 451
                {
395
                    //if (!IsReleaseItems)
396
                    //{
397
                    //    System.Diagnostics.Debug.WriteLine("ConvertFinish ReleaseItems call");
398
                    //    ReleaseItems();
399
                    //}
452
                    if (!IsReleaseItems)
453
                    {
454
                        System.Diagnostics.Debug.WriteLine("ConvertFinish ReleaseItems call");
455
                        ReleaseItems();
456
                    }
400 457
                }
401 458
                else
402 459
                {

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)