GlobalConfig.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. namespace EVCB_OCPP.WSServer
  6. {
  7. public static class GlobalConfig
  8. {
  9. public static List<string> ConfigKeys = new List<string>()
  10. {
  11. "WSPort",
  12. "WSSPort",
  13. "AlarmNotificationCond",
  14. "SMS_Receivers"
  15. };
  16. public static string TCC_API_URL = string.Empty;
  17. public static string TCC_SALTKEY = string.Empty;
  18. /// <summary>
  19. /// 預設心跳間隔時間 單位:秒
  20. /// </summary>
  21. private static int DEFAULT_HEARTBEAT_INTERVAL = 60;
  22. /// <summary>
  23. ///WS Port
  24. /// </summary>
  25. private static int WS_Port = 2012;
  26. /// <summary>
  27. ///WSS Port
  28. /// </summary>
  29. private static int WSS_Port = 2013;
  30. /// <summary>
  31. ///WS Port
  32. /// </summary>
  33. private static string AlarmNotificationCond = string.Empty;
  34. /// <summary>
  35. ///WSS Port
  36. /// </summary>
  37. private static string SMS_Receivers = string.Empty;
  38. /// <summary>
  39. /// Load setting from app.config
  40. /// </summary>
  41. public static bool LoadAPPConfig()
  42. {
  43. bool result = false;
  44. string key = string.Empty;
  45. try
  46. {
  47. for (int i = 0; i < ConfigKeys.Count; i++)
  48. {
  49. key = ConfigKeys[i];
  50. switch (key)
  51. {
  52. case "WSPort":// convert to int type
  53. {
  54. var value = ConfigurationManager.AppSettings[key];
  55. WS_Port = Convert.ToInt32(value);
  56. }
  57. break;
  58. case "WSSPort":
  59. {
  60. var value = ConfigurationManager.AppSettings[key];
  61. WSS_Port = Convert.ToInt32(value);
  62. }
  63. break;
  64. case "AlarmNotificationCond":// convert to int type
  65. {
  66. AlarmNotificationCond = ConfigurationManager.AppSettings[key];
  67. }
  68. break;
  69. case "SMS_Receivers":// convert to int type
  70. {
  71. SMS_Receivers = ConfigurationManager.AppSettings[key];
  72. }
  73. break;
  74. default://convert to string type
  75. break;
  76. }
  77. }
  78. result = true;
  79. }
  80. catch (Exception ex)
  81. {
  82. Console.WriteLine(key + " Load from APPConfig " + ex.ToString());
  83. }
  84. return result;
  85. }
  86. public static string GetAlarmNotification_Cond()
  87. {
  88. return AlarmNotificationCond;
  89. }
  90. public static string GetSMS_Receivers()
  91. {
  92. return SMS_Receivers;
  93. }
  94. public static int GetWS_Port()
  95. {
  96. return WS_Port;
  97. }
  98. public static int GetWSS_Port()
  99. {
  100. return WSS_Port;
  101. }
  102. public static int GetHEARTBEAT_INTERVAL()
  103. {
  104. return DEFAULT_HEARTBEAT_INTERVAL;
  105. }
  106. public static readonly int DB_DefaultConnectionTimeout = 60;
  107. public static readonly string UTC_DATETIMEFORMAT = "yyyy/MM/dd'T'HH':'mm':'ss'Z'";
  108. /// <summary>
  109. /// 預設 Null的 DateTime
  110. /// </summary>
  111. public static DateTime DefaultNullTime = new DateTime(1991, 1, 1);
  112. public static JsonSerializerSettings JSONSERIALIZER_FORMAT = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None };
  113. }
  114. }