프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.Station / ServiceStation.cs @ ab7fe8c0

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

1 53c9637d taeseongkim
using log4net;
2 c1597feb taeseongkim
using Markus.Service.DataBase;
3 a5e5fff6 taeseongkim
using Markus.Service.DataBase.Entities;
4
using Markus.Service.DataBase.Repositories;
5 53c9637d taeseongkim
using Markus.Service.Extensions;
6
using Markus.Service.Helper;
7
using Markus.Service.IWcfService;
8
using Markus.Service.WcfService;
9
using Salaros.Configuration;
10
using System;
11 0a64fa85 taeseongkim
using System.Collections;
12 53c9637d taeseongkim
using System.Collections.Generic;
13
using System.ComponentModel;
14
using System.Data;
15
using System.Diagnostics;
16
using System.Globalization;
17
using System.IO;
18
using System.Linq;
19
using System.Runtime.InteropServices;
20
using System.ServiceModel;
21 1ae729e4 taeseongkim
using System.ServiceModel.Channels;
22
using System.ServiceModel.Dispatcher;
23 53c9637d taeseongkim
using System.ServiceProcess;
24
using System.Text;
25 d91efe5c taeseongkim
using System.Threading;
26 53c9637d taeseongkim
using System.Threading.Tasks;
27
using System.Timers;
28
using static Markus.Service.Extensions.Encrypt;
29
30
namespace Markus.Service
31
{
32
    public partial class ServiceStation : ServiceBase
33
    {
34
        protected ILog logger = LogManager.GetLogger(typeof(ServiceStation));
35
        protected ServiceHost gWcfServiceHost;
36 a5e5fff6 taeseongkim
        private SERVICEPROPERTIES ServiceProperty;
37 53c9637d taeseongkim
38 0157b158 taeseongkim
        private string ServiceID;
39
        private List<SubStationServiceItem> StationServiceList;
40 a5e5fff6 taeseongkim
        private List<string> StationServiceIDList = new List<string>();
41 60723dc9 taeseongkim
        private Service.WcfClient.StationServiceTask.StationServiceClient StationClient;
42 06f13e11 taeseongkim
        private bool IsStation;
43 53c9637d taeseongkim
44
        private Uri gServiceHostAddress;
45
46
        private string MarkusDBConnectionString;
47 c1597feb taeseongkim
        private DBMSType DBMSType;
48 53c9637d taeseongkim
        private string DownloadTempFolder;
49 950e6b84 taeseongkim
        private string FontsFolder;
50 53c9637d taeseongkim
        private int MultiThreadMaxPages;
51
        private int MinFontSize;
52 2091a7e5 taeseongkim
        private int UseResolution;
53 53c9637d taeseongkim
        private bool CreateProcessWindow;
54 8feb21df taeseongkim
        private long ReleaseWorkMemory;
55 53c9637d taeseongkim
56
        private int SaveStatusInterval;
57
58 43e1d368 taeseongkim
        private bool IsReleaseItems;
59
        private readonly System.Timers.Timer timer= null;
60
        
61
        private readonly object locker = new object();
62 06f13e11 taeseongkim
63 53c9637d taeseongkim
        private List<string> RunProjectList = new List<string>();
64
65
        /// <summary>
66
        /// 프로세스 카운터 자주 람다식을 사용해서 list<int>로 함.
67
        /// </summary>
68
        private List<Int64> ProcessorAffinityList;
69 0a64fa85 taeseongkim
        private Int64 DefaultAffinity;
70 53c9637d taeseongkim
71
        private string configFileName;
72
73
        public ServiceStation()
74
        {
75
            InitializeComponent();
76 43e1d368 taeseongkim
77 a5e5fff6 taeseongkim
            timer = new System.Timers.Timer(new TimeSpan(0, 0, 0,5).TotalMilliseconds);
78 43e1d368 taeseongkim
            timer.Elapsed += timerWorkMethod;
79 53c9637d taeseongkim
        }
80
81 a53dfe45 taeseongkim
        /// <summary>
82
        /// Config 파일 
83
        /// </summary>
84 53c9637d taeseongkim
        public void GetApplicationConfig()
85
        {
86
            try
87
            {
88
                ConfigParser config = null;
89
90
                try
91
                {
92
                    configFileName = $"{typeof(ServiceStation).Name}.ini";
93
                    config = ConfigHelper.AppConfig(this.configFileName);
94
                }
95 150747cb taeseongkim
                catch (Exception ex)
96 53c9637d taeseongkim
                {
97 150747cb taeseongkim
                    throw new Exception("Config Read Error.", ex);
98 53c9637d taeseongkim
                }
99
100
                if (config != null)
101
                {
102 0157b158 taeseongkim
                    // CONVERT DATABASE 연결 문자열
103
                    MarkusDBConnectionString = AESEncrypter.Decrypt(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.MARKUS_CONNECTION_STRING));
104
105 731c84b8 taeseongkim
                    var dbtype = config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.DBTYPE);
106 c1597feb taeseongkim
                    if (string.IsNullOrWhiteSpace(dbtype))
107 731c84b8 taeseongkim
                    {
108
                        throw new Exception("DBTYPE not defined in SERVICE section");
109
                    }
110
                    else
111
                    {
112 c1597feb taeseongkim
                        if (!Enum.TryParse<DBMSType>(dbtype, out DBMSType))
113 731c84b8 taeseongkim
                        {
114
                            throw new Exception("DBTYPE of SERVICE is MSSQL,POSTGRESQL.");
115
                        }
116
                    }
117
118 06f13e11 taeseongkim
                    IsStation = System.Convert.ToBoolean(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.IS_STATAION, "false"));
119 0157b158 taeseongkim
120 06f13e11 taeseongkim
                    ServiceID = config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.SERVICE_ID, Guid.Empty.ToString());
121 0157b158 taeseongkim
122 06f13e11 taeseongkim
                    if (IsStation)
123 0157b158 taeseongkim
                    {
124 06f13e11 taeseongkim
                        var servicetList = config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.SERVICE_LIST, "");
125 0157b158 taeseongkim
126 06f13e11 taeseongkim
                        if (!servicetList.IsNullOrEmpty())
127
                        {
128
                            StationServiceIDList = servicetList.Split(',').ToList();
129
                        }
130
                    }
131
                    else
132
                    {
133
                        var address = config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.STATAION_ADDRESS,"");
134 0157b158 taeseongkim
135 06f13e11 taeseongkim
                        if (!address.IsNullOrEmpty())
136
                        {
137
                            BasicHttpBinding myBinding = new BasicHttpBinding();
138
                            EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate(address));
139 60723dc9 taeseongkim
                            StationClient = new WcfClient.StationServiceTask.StationServiceClient(myBinding, myEndpoint);
140 06f13e11 taeseongkim
                        }
141
                    }
142 53c9637d taeseongkim
143
                    CreateProcessWindow = System.Convert.ToBoolean(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.CREATE_WINDOW, "false"));
144
145
                    // PDF 임시 다운로드 폴더
146 2091a7e5 taeseongkim
                    DownloadTempFolder = config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.DOWNLOAD_TEMP_FOLDER,"C:\\temp");
147 950e6b84 taeseongkim
                    FontsFolder = config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.FONTS_FOLDER, "C:\\MarkusFonts"); 
148 2bbea412 taeseongkim
                    // pThraed를 이용한 컨버팅 설정.
149
                    //최대 페이지가 MultiThreadMaxPages설정까지 pThread를 적용하여 컨버팅함.
150 53c9637d taeseongkim
                    MultiThreadMaxPages = System.Convert.ToInt16(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.MULTI_TRHEAD_MAX_PAGE, "500"));
151
152 2bbea412 taeseongkim
                    // 서비스 상태 Log 저장간격
153 53c9637d taeseongkim
                    SaveStatusInterval = System.Convert.ToInt16(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.SAVE_STATUS_INTERVAL, "5"));
154
155 2bbea412 taeseongkim
                    //PDF에 폰트가 최소 폰트 사이즈보다 작은 사이증의 폰트가 있으면 해상도를 높여서 컨버팅함.
156 53c9637d taeseongkim
                    MinFontSize = System.Convert.ToInt16(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.MIN_FONT_SIZE, "10"));
157
158 2bbea412 taeseongkim
                    // 사용자 설정의 해상도
159
                    // MinFontSize를 -1로 하고 UseResolution를 설정하면 해당 해상도로 컨버팅됨
160 2091a7e5 taeseongkim
                    UseResolution = System.Convert.ToInt16(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.USE_RESOLUTION, "0"));
161
162 2bbea412 taeseongkim
                    // 각 프로세스의 최대 메모리 사용량
163 0157b158 taeseongkim
                    var workingMemory = System.Convert.ToDouble(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.RELEASE_WORK_MEMORY, "1.5"));
164 8feb21df taeseongkim
165
                    ReleaseWorkMemory = MathBytes.Bytes(workingMemory, DataSizeType.GB);
166
167 2bbea412 taeseongkim
                    // 서비스 사용 프로젝트
168 2091a7e5 taeseongkim
                    var projectList = config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.FITER_PROCECT,"");
169 53c9637d taeseongkim
170
                    if(!projectList.IsNullOrEmpty())
171
                    {
172
                        RunProjectList = projectList.Split(',').ToList();
173
                    }
174
175
                    // 서비스 ENDPOINT
176
                    // http://localhost/
177
                    var endpointName = config.GetValue(CONFIG_DEFINE.WCF_ENDPOINT, CONFIG_DEFINE.STATION_SERVICE_NAME);
178
                    var port = config.GetValue(CONFIG_DEFINE.WCF_ENDPOINT, CONFIG_DEFINE.STATION_PORT);
179
180
                    if (!string.IsNullOrWhiteSpace(endpointName) && port.IsNumber())
181
                    {
182
                        gServiceHostAddress = UriHelper.UriCreate($"http://localhost:{port}/{endpointName}");
183
                    }
184 60723dc9 taeseongkim
185 2bbea412 taeseongkim
                    // 각  ConvertService의 원격 관리를 위한 서비스 설정 로드
186 731c84b8 taeseongkim
                    using (Markus.Service.DataBase.Repositories.SERVICEPROPERTIESRepository db = new DataBase.Repositories.SERVICEPROPERTIESRepository(MarkusDBConnectionString,DBMSType))
187 60723dc9 taeseongkim
                    {
188 a5e5fff6 taeseongkim
                        ServiceProperty = db.GetSingleAsync(ServiceID).GetAwaiter().GetResult();
189 60723dc9 taeseongkim
                    }
190 53c9637d taeseongkim
                }
191
            }
192
            catch (Exception ex)
193
            {
194
                throw new Exception("ApplicationConfig ", ex);
195
            }
196
        }
197
198
        protected override void OnStart(string[] args)
199
        {
200
            try
201
            {
202 43e1d368 taeseongkim
                StartService();
203 53c9637d taeseongkim
            }
204
            catch (Exception ex)
205
            {
206
                logger.Error("ServiceStation Start Error - ", ex);
207
            }
208
        }
209 d91efe5c taeseongkim
210 06f13e11 taeseongkim
        /// <summary>
211
        /// alivequeue와 process를 비교하여 정리하고
212
        /// 대기중인 아이템을 분배한다.
213
        /// </summary>
214
        private void ReleaseItems()
215
        {
216 0157b158 taeseongkim
            try
217 53c9637d taeseongkim
            {
218 06f13e11 taeseongkim
                IsReleaseItems = true;
219
220 d91efe5c taeseongkim
                System.Diagnostics.Debug.WriteLine("CleanUpAliveQueueItems start");
221 06f13e11 taeseongkim
                CleanUpAliveQueueItems();
222 d91efe5c taeseongkim
                System.Diagnostics.Debug.WriteLine("CleanUpAliveQueueItems end");
223 06f13e11 taeseongkim
224
                if (IsStation)
225
                {
226 60723dc9 taeseongkim
                    //if (IsDataBaseWaitingList(1))
227
                    //{
228 1ae729e4 taeseongkim
                    System.Diagnostics.Debug.WriteLine("ReleaseItems start");
229 43e1d368 taeseongkim
230 a5e5fff6 taeseongkim
                    bool reflashResult = false;
231
232
                    if (this.StationServiceList.Count() > 0)
233
                    {
234
                        reflashResult = ReflashSubServiceAsync().GetAwaiter().GetResult();
235
                    }
236
                    else
237
                    {
238
                        reflashResult = true;
239
                    }
240
            
241
                    if (reflashResult)
242
                    {
243
                        //if (StationServiceList.All(x => x.IsOnline))
244
                        //{
245
                            CleanUpDataBaseItems();
246
                            setDataBaseWaitingList();
247
                        //}
248
                        //else
249
                        //{
250
                        //    logger.Error("Service Any Offline");
251
                        //}
252
                    }
253
                    else
254
                    {
255
                        logger.Error("ReleaseItems - ReflashSubServiceAsync result false");
256 1ae729e4 taeseongkim
                    }
257
258 43e1d368 taeseongkim
259 1ae729e4 taeseongkim
                    System.Diagnostics.Debug.WriteLine("ReleaseItems end");
260 60723dc9 taeseongkim
                    //}
261 06f13e11 taeseongkim
                }
262 53c9637d taeseongkim
            }
263 0157b158 taeseongkim
            catch (Exception ex)
264 53c9637d taeseongkim
            {
265 0157b158 taeseongkim
                logger.Error("get Wating Item error", ex);
266 53c9637d taeseongkim
            }
267
268 06f13e11 taeseongkim
            IsReleaseItems = false;
269 53c9637d taeseongkim
        }
270
271 a53dfe45 taeseongkim
        /// <summary>
272
        /// System.Diagnostics.Process의 ProcessorAffinity Core 선호도를 위한 초기화
273
        /// 설정된 MultiProcessCount에 대해서 프로세스의 코어의 선호도를 지정 한다.
274
        /// 코어의 선택은 비트로 이루어 진다.
275
        /// 8코어에서 1번 코어 00000001
276
        /// 8코어에서 1번 3번 코어 00000101
277
        /// 8코어에서 1번 3번 코어 00000101
278
        /// 8코어에서 1,2,3 선택   00000111
279
        /// https://dotnetgalactics.wordpress.com/2009/10/20/how-to-set-the-processor-affinity-programatically/
280
        /// </summary>
281 53c9637d taeseongkim
        private void ProcessorAffinityInit()
282
        {
283
            ProcessorAffinityList = new List<long>();
284
285
            int processCount = Environment.ProcessorCount;
286 1d79913e taeseongkim
            int AffinityScope = processCount;
287 53c9637d taeseongkim
288 0a64fa85 taeseongkim
            //Process 자동 배분 
289
            DefaultAffinity = GetAffinityMask(processCount, processCount);
290 53c9637d taeseongkim
291 1d79913e taeseongkim
            long affinityMask = 0;
292 53c9637d taeseongkim
293 1d79913e taeseongkim
            while (ProcessorAffinityList.Count() < ServiceProperty.PROCESS_COUNT)
294 0a64fa85 taeseongkim
295
            for (int i = ServiceProperty.PROCESS_COUNT; i > 0; i--)
296 1d79913e taeseongkim
            {
297 0a64fa85 taeseongkim
                affinityMask = GetAffinityMask(processCount, i);
298
299
                if (Environment.UserInteractive)
300 1d79913e taeseongkim
                {
301 0a64fa85 taeseongkim
                    Console.WriteLine($"index{string.Format("{0:D2}", ProcessorAffinityList.Count())} - {longToBinaryString(affinityMask)}");
302 53c9637d taeseongkim
                }
303
304 1d79913e taeseongkim
                ProcessorAffinityList.Add(affinityMask);
305 53c9637d taeseongkim
            }
306 0a64fa85 taeseongkim
        }
307 1d79913e taeseongkim
308 0a64fa85 taeseongkim
        private static long GetAffinityMask(int processCount, int index)
309
        {
310
            BitArray bitArray = new BitArray(processCount);
311 1d79913e taeseongkim
312 0a64fa85 taeseongkim
            if (processCount - 1 < index)
313
            {
314
                bitArray = new BitArray(processCount, true);
315
            }
316
            else
317
            {
318
                bitArray.Set(index, true);
319
            }
320 1d79913e taeseongkim
321 0a64fa85 taeseongkim
            var bits = bitArray.Cast<bool>().Select(bit => bit ? 1 : 0);
322 1d79913e taeseongkim
323 0a64fa85 taeseongkim
            return System.Convert.ToInt64(string.Join("", bits), 2);
324
        }
325
        private static string longToBinaryString(long value)
326
        {
327
            string binary = Convert.ToString(value, 2);
328
            return binary.PadLeft(64, '0');
329 53c9637d taeseongkim
        }
330
331 43e1d368 taeseongkim
        public void StartService()
332 53c9637d taeseongkim
        {
333 2bbea412 taeseongkim
            /// 서비스 설정 로드
334 53c9637d taeseongkim
            try
335
            {
336
                this.GetApplicationConfig();
337
                logger.Info("Read Config");
338
339 60723dc9 taeseongkim
                if (ServiceProperty != null)
340
                {
341
                    ProcessorAffinityInit();
342
                }
343
                else
344
                {
345
                    throw new Exception("StartService Error. ServiceProperty is Null");
346
                }
347 53c9637d taeseongkim
348
            }
349
            catch (Exception e)
350
            {
351 60723dc9 taeseongkim
                throw new Exception("StartService Error. ", e);
352 53c9637d taeseongkim
            }
353 60723dc9 taeseongkim
354 2bbea412 taeseongkim
            /// pThread.dll을 리소스에서 Service 실행 디렉토리로 복사.
355 43e1d368 taeseongkim
            //try
356
            //{
357
            //    // MarkusPDF.dll에서 pThread lib 사용을 위해 Insatll
358
            //    var libPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "\\convert\\libpthread.dll");
359
            //    if (!File.Exists(libPath))
360
            //    {
361
            //        Markus.Library.Installer.Install();
362
            //        logger.Info("Markus.Library.Installer Install");
363
            //    }
364
            //    else
365
            //    {
366
            //        logger.Info("Markus.Library.Installer Exists.");
367
            //    }
368
369
            //}
370
            //catch (Exception e)
371
            //{
372
            //    throw new Exception("Stop Installer Error. ", e);
373
            //}
374 53c9637d taeseongkim
375 2bbea412 taeseongkim
            /// 컨버터 프로세스가 실행중인 경우 모두 중지 시킨다.
376 53c9637d taeseongkim
            try
377
            {
378 a53dfe45 taeseongkim
                // 기존에 실행 중이던 프로세스 종료
379 53c9637d taeseongkim
                Stopprocess();
380
                logger.Info("Stopprocess");
381
            }
382
            catch (Exception e)
383
            {
384
                throw new Exception("Stop Process Error. ", e);
385
            }
386
387 2bbea412 taeseongkim
            /// wcf 서비스 실행
388 53c9637d taeseongkim
            try
389
            {
390 a53dfe45 taeseongkim
                // WCF 실행
391 53c9637d taeseongkim
                StartWcfService();
392
393
                if (gWcfServiceHost.BaseAddresses?.Count() > 0)
394
                {
395
                    gServiceHostAddress = gWcfServiceHost.BaseAddresses.First();
396
                }
397
398 43e1d368 taeseongkim
                //  각 sub서비스에 컨버터 아이템을 보내기 위한 서비스 초기화
399 06f13e11 taeseongkim
                if (IsStation)
400 0157b158 taeseongkim
                {
401
                    SetServiceList(this.StationServiceIDList);
402
                }
403
404 53c9637d taeseongkim
                logger.Info($"StartWcfService {gServiceHostAddress}");
405
            }
406
            catch (Exception e)
407
            {
408
                throw new Exception("start Wcf Service Error. ", e);
409
            }
410
411 0157b158 taeseongkim
            //try
412
            //{
413
            //    // Status가 4이하인 Convert Item을 다시 Convert 함. 
414
            //    setDataBaseWaitingList();
415
            //    logger.Info("setDataBaseWaitingList");
416
            //}
417
            //catch (Exception e)
418
            //{
419
            //    throw new Exception("Database Waiting List Error . ", e);
420
            //}
421 53c9637d taeseongkim
422
            logger.Info("Start ServiceStation");
423 43e1d368 taeseongkim
            timer.Start();
424
        }
425 d91efe5c taeseongkim
426 43e1d368 taeseongkim
        private void timerWorkMethod(object sender, ElapsedEventArgs e)
427
        {
428
            if (timer.Enabled)
429
            {
430
                var _timer = (System.Timers.Timer)sender;
431
                _timer.Stop();
432 d91efe5c taeseongkim
433 43e1d368 taeseongkim
                if (!IsStop)
434
                {
435
                    StartConvert();
436
                    
437
                    _timer.Start();
438
                }
439
                else
440
                {
441
                    StopService();
442
                }
443
            }
444
            else
445
            {
446
                logger.Error("timer disable");
447
            }
448 53c9637d taeseongkim
        }
449
450 d91efe5c taeseongkim
        private bool IsStop = false;
451 43e1d368 taeseongkim
    
452 60723dc9 taeseongkim
        DateTime logTime;
453 1ae729e4 taeseongkim
        DateTime ReleaseTime;
454 60723dc9 taeseongkim
455 43e1d368 taeseongkim
456
        private bool StartConvert()
457 60723dc9 taeseongkim
        {
458 d91efe5c taeseongkim
            //stateTimer.Change(new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 0, 0, -1));
459 60723dc9 taeseongkim
            try
460
            {
461 1ae729e4 taeseongkim
               
462 d91efe5c taeseongkim
                if ((DateTime.Now - ReleaseTime) >= new TimeSpan(0, 0,1))
463 60723dc9 taeseongkim
                {
464 1ae729e4 taeseongkim
                    if (!IsReleaseItems)
465
                    {
466 43e1d368 taeseongkim
                        if (System.Environment.UserInteractive)
467
                        {
468
                            Console.WriteLine("Release Items");
469
                        }
470 a5e5fff6 taeseongkim
471 1ae729e4 taeseongkim
                        ReleaseItems();
472
                    }
473 d91efe5c taeseongkim
                    else
474
                    {
475 43e1d368 taeseongkim
                        if (System.Environment.UserInteractive)
476
                        {
477
                            Console.WriteLine("pass Release Items");
478
                        }
479 d91efe5c taeseongkim
                    }
480
481 1ae729e4 taeseongkim
                    ReleaseTime = DateTime.Now;
482 60723dc9 taeseongkim
                }
483 1ae729e4 taeseongkim
              
484 150747cb taeseongkim
                if ((DateTime.Now - logTime) >= new TimeSpan(0, 5,0))
485 60723dc9 taeseongkim
                {
486
                    logTime = DateTime.Now;
487
                    logger.Info("StationService Alive Check");
488
                }
489
            }
490
            catch (Exception ex)
491
            {
492
                logger.Error("Timer Error ", ex);
493
            }
494 43e1d368 taeseongkim
495
            return true;
496 60723dc9 taeseongkim
        }
497
498 0157b158 taeseongkim
        public void SetServiceList(List<string> serviceList)
499
        {
500
            StationServiceList = new List<SubStationServiceItem>();
501
502 731c84b8 taeseongkim
            using (SERVICEPROPERTIESRepository database = new SERVICEPROPERTIESRepository(MarkusDBConnectionString,DBMSType))
503 0157b158 taeseongkim
            {
504
                foreach (var item in serviceList)
505
                {
506
                    try
507
                    {
508 a5e5fff6 taeseongkim
                        var prop = database.GetSingleAsync(item).GetAwaiter().GetResult();
509 0157b158 taeseongkim
510
                        if (prop != null)
511
                        {
512 1ae729e4 taeseongkim
                            BasicHttpBinding httpbinding = new BasicHttpBinding();
513
                            httpbinding.CloseTimeout = new TimeSpan(0, 10, 0);
514
                            httpbinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
515
                            httpbinding.SendTimeout = new TimeSpan(0, 10, 0);
516
                            httpbinding.OpenTimeout = new TimeSpan(0, 10, 0);
517
518 0157b158 taeseongkim
                            EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate(prop.SERVICE_ADDRESS));
519 1ae729e4 taeseongkim
                            var StationServiceClient = new WcfClient.StationServiceTask.StationServiceClient(httpbinding, myEndpoint);
520 0157b158 taeseongkim
                        
521
                       
522
                                //var items = StationServiceClient.AliveConvertList();
523
                            
524
                                StationServiceList.Add(new SubStationServiceItem
525
                                {
526
                                    Properties = prop,
527
                                    Service = StationServiceClient
528
                                });
529
                        }
530
531
                    }
532
                    catch (Exception ex)
533
                    {
534 06f13e11 taeseongkim
                        logger.Error($"Service Properties Error  ID : { item }",ex);
535 0157b158 taeseongkim
                    }
536
                }
537
            }
538
        }
539 53c9637d taeseongkim
540
        protected override void OnStop()
541
        {
542
            try
543
            {
544 43e1d368 taeseongkim
                IsStop = true;
545 53c9637d taeseongkim
            }
546
            catch (Exception e)
547
            {
548
                logger.Error("OnStop Error . ", e);
549
            }
550
        }
551
552 d91efe5c taeseongkim
        public void StopService()
553
        {
554
            StopWcfService();
555 a5e5fff6 taeseongkim
            try
556
            {
557
                Stopprocess();
558
            }
559
            catch (Exception ex)
560
            {
561
                System.Diagnostics.Debug.WriteLine(ex);
562
            }
563 d91efe5c taeseongkim
564
            logger.Info("ServiceStation Stop");
565
        }
566
567 53c9637d taeseongkim
        #region Sleep 방지
568
        //[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
569
        //static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
570
        //[FlagsAttribute]
571
        //public enum EXECUTION_STATE : uint
572
        //{
573
        //    ES_AWAYMODE_REQUIRED = 0x00000040,
574
        //    ES_CONTINUOUS = 0x80000000,
575
        //    ES_DISPLAY_REQUIRED = 0x00000002,
576
        //    ES_SYSTEM_REQUIRED = 0x00000001
577
        //    // Legacy flag, should not be used.
578
        //    // ES_USER_PRESENT = 0x00000004
579
        //}
580
        //public static void PreventScreenAndSleep()
581
        //{
582
        //    SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS |
583
        //                            EXECUTION_STATE.ES_SYSTEM_REQUIRED |
584
        //                            EXECUTION_STATE.ES_AWAYMODE_REQUIRED |
585
        //                            EXECUTION_STATE.ES_DISPLAY_REQUIRED);
586
        //} 
587
        #endregion
588
    }
589
}
클립보드 이미지 추가 (최대 크기: 500 MB)