개정판 43e1d368
issue #0000 코드 정리
Change-Id: I7c8ba4ef6d78a7e4f51b72f226507cddac722939
ConvertService/ServiceBase/Markus.Service.Station/ServiceStation.cs | ||
---|---|---|
51 | 51 |
|
52 | 52 |
private int SaveStatusInterval; |
53 | 53 |
|
54 |
private static bool IsReleaseItems; |
|
54 |
private bool IsReleaseItems; |
|
55 |
private readonly System.Timers.Timer timer= null; |
|
56 |
|
|
57 |
private readonly object locker = new object(); |
|
55 | 58 |
|
56 | 59 |
private List<string> RunProjectList = new List<string>(); |
57 | 60 |
|
... | ... | |
65 | 68 |
public ServiceStation() |
66 | 69 |
{ |
67 | 70 |
InitializeComponent(); |
71 |
|
|
72 |
timer = new System.Timers.Timer(new TimeSpan(0, 0, 0,1).TotalMilliseconds); |
|
73 |
timer.Elapsed += timerWorkMethod; |
|
68 | 74 |
} |
69 | 75 |
|
70 | 76 |
/// <summary> |
... | ... | |
175 | 181 |
{ |
176 | 182 |
try |
177 | 183 |
{ |
178 |
if (StartService()) |
|
179 |
{ |
|
180 |
while (stateTimer != null) |
|
181 |
{ |
|
182 |
//Wait until the job is done |
|
183 |
AutoEventInstance.WaitOne(); |
|
184 |
//Wait for 5 minutes before starting the job again. |
|
185 |
stateTimer.Change(1000, Timeout.Infinite); |
|
186 |
} |
|
187 |
} |
|
188 |
else |
|
189 |
{ |
|
190 |
logger.Error("not working StartService"); |
|
191 |
} |
|
184 |
StartService(); |
|
192 | 185 |
} |
193 | 186 |
catch (Exception ex) |
194 | 187 |
{ |
... | ... | |
215 | 208 |
//if (IsDataBaseWaitingList(1)) |
216 | 209 |
//{ |
217 | 210 |
System.Diagnostics.Debug.WriteLine("ReleaseItems start"); |
218 |
ReflashSubServiceAsync(); |
|
219 |
|
|
220 |
if (StationServiceList.All(x => x.IsOnline))
|
|
211 |
var task = ReflashSubServiceAsync();
|
|
212 |
|
|
213 |
if(task.Wait(40000))
|
|
221 | 214 |
{ |
222 |
CleanUpDataBaseItems(); |
|
223 |
setDataBaseWaitingList(); |
|
224 |
} |
|
225 |
else |
|
226 |
{ |
|
227 |
System.Diagnostics.Debug.WriteLine("Service Any Offline"); |
|
215 |
if (task.Result) |
|
216 |
{ |
|
217 |
if (StationServiceList.All(x => x.IsOnline)) |
|
218 |
{ |
|
219 |
CleanUpDataBaseItems(); |
|
220 |
setDataBaseWaitingList(); |
|
221 |
} |
|
222 |
else |
|
223 |
{ |
|
224 |
logger.Error("Service Any Offline"); |
|
225 |
} |
|
226 |
} |
|
227 |
else |
|
228 |
{ |
|
229 |
logger.Error("ReleaseItems - ReflashSubServiceAsync result false"); |
|
230 |
} |
|
231 |
|
|
228 | 232 |
} |
229 | 233 |
|
234 |
|
|
230 | 235 |
System.Diagnostics.Debug.WriteLine("ReleaseItems end"); |
231 | 236 |
//} |
232 | 237 |
} |
... | ... | |
276 | 281 |
} |
277 | 282 |
} |
278 | 283 |
|
279 |
public bool StartService()
|
|
284 |
public void StartService()
|
|
280 | 285 |
{ |
281 |
|
|
282 | 286 |
/// 서비스 설정 로드 |
283 | 287 |
try |
284 | 288 |
{ |
... | ... | |
301 | 305 |
} |
302 | 306 |
|
303 | 307 |
/// pThread.dll을 리소스에서 Service 실행 디렉토리로 복사. |
304 |
try |
|
305 |
{ |
|
306 |
// MarkusPDF.dll에서 pThread lib 사용을 위해 Insatll |
|
307 |
if (!File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "libpthread.dll"))) |
|
308 |
{ |
|
309 |
Markus.Library.Installer.Install(); |
|
310 |
logger.Info("Markus.Library.Installer Install"); |
|
311 |
} |
|
312 |
else |
|
313 |
{ |
|
314 |
logger.Info("Markus.Library.Installer Exists."); |
|
315 |
} |
|
316 |
|
|
317 |
} |
|
318 |
catch (Exception e) |
|
319 |
{ |
|
320 |
throw new Exception("Stop Installer Error. ", e); |
|
321 |
} |
|
308 |
//try |
|
309 |
//{ |
|
310 |
// // MarkusPDF.dll에서 pThread lib 사용을 위해 Insatll |
|
311 |
// var libPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "\\convert\\libpthread.dll"); |
|
312 |
// if (!File.Exists(libPath)) |
|
313 |
// { |
|
314 |
// Markus.Library.Installer.Install(); |
|
315 |
// logger.Info("Markus.Library.Installer Install"); |
|
316 |
// } |
|
317 |
// else |
|
318 |
// { |
|
319 |
// logger.Info("Markus.Library.Installer Exists."); |
|
320 |
// } |
|
321 |
|
|
322 |
//} |
|
323 |
//catch (Exception e) |
|
324 |
//{ |
|
325 |
// throw new Exception("Stop Installer Error. ", e); |
|
326 |
//} |
|
322 | 327 |
|
323 | 328 |
/// 컨버터 프로세스가 실행중인 경우 모두 중지 시킨다. |
324 | 329 |
try |
... | ... | |
343 | 348 |
gServiceHostAddress = gWcfServiceHost.BaseAddresses.First(); |
344 | 349 |
} |
345 | 350 |
|
346 |
// 각 서비스에 컨버터 아이템을 보내기 위한 서비스 초기화 |
|
351 |
// 각 sub서비스에 컨버터 아이템을 보내기 위한 서비스 초기화
|
|
347 | 352 |
if (IsStation) |
348 | 353 |
{ |
349 | 354 |
SetServiceList(this.StationServiceIDList); |
... | ... | |
367 | 372 |
// throw new Exception("Database Waiting List Error . ", e); |
368 | 373 |
//} |
369 | 374 |
|
370 |
|
|
371 | 375 |
logger.Info("Start ServiceStation"); |
372 |
AutoEventInstance = new System.Threading.AutoResetEvent(false);
|
|
373 |
StatusCheckerInstance = new StatusChecker();
|
|
376 |
timer.Start();
|
|
377 |
}
|
|
374 | 378 |
|
375 |
TimerCallback timerDelegate = new TimerCallback(StatusCheckerInstance.CheckStatus); |
|
379 |
private void timerWorkMethod(object sender, ElapsedEventArgs e) |
|
380 |
{ |
|
381 |
if (timer.Enabled) |
|
382 |
{ |
|
383 |
var _timer = (System.Timers.Timer)sender; |
|
384 |
_timer.Stop(); |
|
376 | 385 |
|
377 |
stateTimer = new System.Threading.Timer(new System.Threading.TimerCallback(TimerCallBack), AutoEventInstance,new TimeSpan(0,0,0,0,10),new TimeSpan(0,0,0,0,10)); |
|
378 |
|
|
379 |
return true; |
|
386 |
if (!IsStop) |
|
387 |
{ |
|
388 |
StartConvert(); |
|
389 |
|
|
390 |
_timer.Start(); |
|
391 |
} |
|
392 |
else |
|
393 |
{ |
|
394 |
StopService(); |
|
395 |
} |
|
396 |
} |
|
397 |
else |
|
398 |
{ |
|
399 |
logger.Error("timer disable"); |
|
400 |
} |
|
380 | 401 |
} |
381 | 402 |
|
382 | 403 |
private bool IsStop = false; |
383 |
private AutoResetEvent AutoEventInstance { get; set; } |
|
384 |
private StatusChecker StatusCheckerInstance { get; set; } |
|
385 |
System.Threading.Timer stateTimer; |
|
404 |
|
|
386 | 405 |
DateTime logTime; |
387 | 406 |
DateTime ReleaseTime; |
388 | 407 |
|
389 |
private void TimerCallBack(object state) |
|
408 |
|
|
409 |
private bool StartConvert() |
|
390 | 410 |
{ |
391 |
System.Threading.AutoResetEvent autoEvent = (System.Threading.AutoResetEvent)state; |
|
392 | 411 |
//stateTimer.Change(new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 0, 0, -1)); |
393 | 412 |
try |
394 | 413 |
{ |
... | ... | |
397 | 416 |
{ |
398 | 417 |
if (!IsReleaseItems) |
399 | 418 |
{ |
400 |
Console.WriteLine("Release Items"); |
|
419 |
if (System.Environment.UserInteractive) |
|
420 |
{ |
|
421 |
Console.WriteLine("Release Items"); |
|
422 |
} |
|
423 |
logger.Info("Release Items"); |
|
401 | 424 |
ReleaseItems(); |
402 | 425 |
} |
403 | 426 |
else |
404 | 427 |
{ |
405 |
Console.WriteLine("pass Release Items"); |
|
428 |
if (System.Environment.UserInteractive) |
|
429 |
{ |
|
430 |
Console.WriteLine("pass Release Items"); |
|
431 |
} |
|
406 | 432 |
} |
407 | 433 |
|
408 | 434 |
ReleaseTime = DateTime.Now; |
... | ... | |
418 | 444 |
{ |
419 | 445 |
logger.Error("Timer Error ", ex); |
420 | 446 |
} |
421 |
//Console.WriteLine($"time : {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.FFF")}"); |
|
422 |
autoEvent.Set(); |
|
423 |
//stateTimer.Change(new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 0, 0, 1)); |
|
447 |
|
|
448 |
return true; |
|
424 | 449 |
} |
425 | 450 |
|
426 | 451 |
public void SetServiceList(List<string> serviceList) |
... | ... | |
469 | 494 |
{ |
470 | 495 |
try |
471 | 496 |
{ |
472 |
StopService();
|
|
497 |
IsStop = true;
|
|
473 | 498 |
} |
474 | 499 |
catch (Exception e) |
475 | 500 |
{ |
... | ... | |
479 | 504 |
|
480 | 505 |
public void StopService() |
481 | 506 |
{ |
482 |
stateTimer.Dispose(); |
|
483 |
|
|
484 | 507 |
StopWcfService(); |
485 | 508 |
Stopprocess(); |
486 | 509 |
|
487 | 510 |
logger.Info("ServiceStation Stop"); |
488 | 511 |
} |
489 | 512 |
|
490 |
class StatusChecker |
|
491 |
{ |
|
492 |
//This job takes time to run. For example purposes, I put a delay in here. |
|
493 |
int milliseconds = 5000; |
|
494 |
|
|
495 |
public StatusChecker() |
|
496 |
{ |
|
497 |
} |
|
498 |
|
|
499 |
// This method is called by the timer delegate. |
|
500 |
public void CheckStatus(Object stateInfo) |
|
501 |
{ |
|
502 |
AutoResetEvent autoEvent = (AutoResetEvent)stateInfo; |
|
503 |
Console.WriteLine("{0} Start Checking status.", |
|
504 |
DateTime.Now.ToString("h:mm:ss.fff")); |
|
505 |
|
|
506 |
Thread.Sleep(milliseconds); |
|
507 |
//Job is now done running and the timer can now be reset to wait for the next interval |
|
508 |
Console.WriteLine("{0} Done Checking status.", |
|
509 |
DateTime.Now.ToString("h:mm:ss.fff")); |
|
510 |
autoEvent.Set(); |
|
511 |
} |
|
512 |
} |
|
513 |
|
|
514 | 513 |
#region Sleep 방지 |
515 | 514 |
//[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] |
516 | 515 |
//static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); |
내보내기 Unified diff