Program.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Collections.Specialized;
  5. using System.Configuration;
  6. using System.Linq;
  7. using System.Net.WebSockets;
  8. using System.Runtime.Remoting.Messaging;
  9. using System.ServiceProcess;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using System.Xml;
  14. namespace AipGateway.FileJob.Scheduler
  15. {
  16. internal static class Program
  17. {
  18. /// <summary>
  19. /// 해당 애플리케이션의 주 진입점입니다.
  20. /// </summary>
  21. static void Main()
  22. {
  23. ReadSettingsFromConfig();
  24. loadConfiguration();
  25. ServiceBase[] ServicesToRun;
  26. ServicesToRun = new ServiceBase[]
  27. {
  28. new Service()
  29. };
  30. ServiceBase.Run(ServicesToRun);
  31. }
  32. private static void loadConfiguration()
  33. {
  34. const string settingDeleteMinute = "DeleteMinute";
  35. const string settingDeletePathCount = "DeletePathCount";
  36. const string settingDeletePath = "DeletePath";
  37. int DeleteMinute = 60 * 24;
  38. string[] DeletePathsToWatch;
  39. NameValueCollection nvc;
  40. DeletePathsToWatch = null;
  41. nvc = (NameValueCollection)ConfigurationManager.AppSettings;
  42. if (nvc.AllKeys.Contains(settingDeleteMinute))
  43. {
  44. string tmpMinute = nvc[settingDeleteMinute];
  45. DeleteMinute = Helper.TryInt(tmpMinute, DeleteMinute);
  46. if (DeleteMinute < 30)
  47. {
  48. Console.WriteLine($"삭제할 파일 생성 시간 기준이 너무작아 [{DeleteMinute}] 최소값인 30분으로 다시 설정합니다.");
  49. DeleteMinute = 30;
  50. }
  51. }
  52. if (nvc.AllKeys.Contains(settingDeletePathCount))
  53. {
  54. int pathCount = Helper.TryInt(nvc[settingDeletePathCount], 0);
  55. if (pathCount > 0)
  56. {
  57. string[] tmpDeletePathsToWatch = new string[pathCount];
  58. for (int ii = 0; ii < pathCount; ii++)
  59. {
  60. string key = settingDeletePath + (ii + 1).ToString();
  61. if (nvc.AllKeys.Contains(key))
  62. {
  63. tmpDeletePathsToWatch[ii] = nvc[key];
  64. }
  65. }
  66. DeletePathsToWatch = tmpDeletePathsToWatch;
  67. }
  68. }
  69. }
  70. private static void ReadSettingsFromConfig()
  71. {
  72. var applicationSettings = ConfigurationManager.GetSection("deleteSettings") as NameValueCollection;
  73. if (applicationSettings.Count == 0)
  74. {
  75. Console.WriteLine("Application Settings are not defined");
  76. }
  77. else
  78. {
  79. foreach (var key in applicationSettings.AllKeys)
  80. {
  81. Console.WriteLine(key + " = " + applicationSettings[key]);
  82. }
  83. }
  84. }
  85. }
  86. }