GlobalConfig.cs 3.9 KB

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