GlobalConfig.cs 5.1 KB

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