GlobalConfig.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_1",
  13. "WSSPort_2",
  14. "OCPP20_WSUrl",
  15. "OCPP20_WSSUrl",
  16. "SecurityProfileLevel",
  17. "SecurityPassword"
  18. };
  19. public static List<string> DenyModelNames = new List<string>();
  20. public static string UTC_DATETIMEFORMAT = "yyyy-MM-dd'T'HH':'mm':'ss'Z'";
  21. public static string TCC_API_URL = string.Empty;
  22. public static string TCC_SALTKEY = string.Empty;
  23. public static string OCPP20_WSUrl = string.Empty;
  24. public static string OCPP20_WSSUrl = string.Empty;
  25. public static int SecurityProfileLevel = 0;
  26. public static string SecurityPassword = string.Empty;
  27. public static JsonSerializerSettings JSONSERIALIZER_FORMAT = new JsonSerializerSettings()
  28. {
  29. NullValueHandling = NullValueHandling.Ignore,
  30. Formatting = Formatting.None,
  31. DateFormatString = UTC_DATETIMEFORMAT
  32. };
  33. /// <summary>
  34. /// 預設心跳間隔時間 單位:秒
  35. /// </summary>
  36. private static int DEFAULT_HEARTBEAT_INTERVAL = 60;
  37. /// <summary>
  38. ///WS Port
  39. /// </summary>
  40. private static int WS_Port = 2012;
  41. /// <summary>
  42. ///WSS Port 1
  43. /// </summary>
  44. private static int WSS_Port_1 = 2013;
  45. /// <summary>
  46. ///WSS Port 2
  47. /// </summary>
  48. private static int WSS_Port_2 = 2014;
  49. /// <summary>
  50. /// Load setting from app.config
  51. /// </summary>
  52. public static bool LoadAPPConfig()
  53. {
  54. bool result = false;
  55. string key = string.Empty;
  56. try
  57. {
  58. for (int i = 0; i < ConfigKeys.Count; i++)
  59. {
  60. key = ConfigKeys[i];
  61. switch (key)
  62. {
  63. case "WSPort":// convert to int type
  64. {
  65. var value = ConfigurationManager.AppSettings[key];
  66. WS_Port = Convert.ToInt32(value);
  67. }
  68. break;
  69. case "WSSPort_1":
  70. {
  71. var value = ConfigurationManager.AppSettings[key].Split(',')[0];
  72. WSS_Port_1 = Convert.ToInt32(value);
  73. }
  74. break;
  75. case "WSSPort_2":
  76. {
  77. var value = ConfigurationManager.AppSettings[key].Split(',')[1];
  78. WSS_Port_2 = Convert.ToInt32(value);
  79. }
  80. break;
  81. case "OCPP20_WSUrl":// convert to int type
  82. {
  83. var value = ConfigurationManager.AppSettings[key];
  84. OCPP20_WSUrl = value;
  85. }
  86. break;
  87. case "OCPP20_WSSUrl":// convert to int type
  88. {
  89. var value = ConfigurationManager.AppSettings[key];
  90. OCPP20_WSSUrl = value;
  91. }
  92. break;
  93. case "SecurityProfileLevel":
  94. {
  95. var value = ConfigurationManager.AppSettings[key];
  96. SecurityProfileLevel = Convert.ToInt32(value);
  97. }
  98. break;
  99. case "SecurityPassword":
  100. {
  101. var value = ConfigurationManager.AppSettings[key];
  102. SecurityPassword = value;
  103. }
  104. break;
  105. default://convert to string type
  106. break;
  107. }
  108. }
  109. result = true;
  110. }
  111. catch (Exception ex)
  112. {
  113. Console.WriteLine(key + " Load from APPConfig " + ex.ToString());
  114. }
  115. return result;
  116. }
  117. public static int GetWS_Port()
  118. {
  119. return WS_Port;
  120. }
  121. public static int GetWSS_Port_1()
  122. {
  123. return WSS_Port_1;
  124. }
  125. public static int GetWSS_Port_2()
  126. {
  127. return WSS_Port_2;
  128. }
  129. public static int GetHEARTBEAT_INTERVAL()
  130. {
  131. return DEFAULT_HEARTBEAT_INTERVAL;
  132. }
  133. public static readonly int DB_DefaultConnectionTimeout = 60;
  134. /// <summary>
  135. /// 預設 Null的 DateTime
  136. /// </summary>
  137. public static DateTime DefaultNullTime = new DateTime(1991, 1, 1);
  138. }
  139. }