GlobalConfig.cs 3.9 KB

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