GlobalConfig.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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
  42. /// </summary>
  43. private static List<int> WSS_Ports = null;
  44. /// <summary>
  45. /// Load setting from app.config
  46. /// </summary>
  47. public static bool LoadAPPConfig()
  48. {
  49. bool result = false;
  50. string key = string.Empty;
  51. try
  52. {
  53. for (int i = 0; i < ConfigKeys.Count; i++)
  54. {
  55. key = ConfigKeys[i];
  56. switch (key)
  57. {
  58. case "WSPort":// convert to int type
  59. {
  60. var value = ConfigurationManager.AppSettings[key];
  61. WS_Port = 0;
  62. Int32.TryParse(value, out WS_Port);
  63. }
  64. break;
  65. case "WSSPort":
  66. {
  67. var ports = ConfigurationManager.AppSettings[key].Split(',');
  68. WSS_Ports = new List<int>();
  69. foreach(var port in ports)
  70. {
  71. WSS_Ports.Add(Convert.ToInt32(port));
  72. }
  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 List<int> GetWSS_Ports()
  116. {
  117. return WSS_Ports;
  118. }
  119. public static int GetHEARTBEAT_INTERVAL()
  120. {
  121. return DEFAULT_HEARTBEAT_INTERVAL;
  122. }
  123. public static readonly int DB_DefaultConnectionTimeout = 60;
  124. /// <summary>
  125. /// 預設 Null的 DateTime
  126. /// </summary>
  127. public static DateTime DefaultNullTime = new DateTime(1991, 1, 1);
  128. }
  129. }