GlobalConfig.cs 4.6 KB

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