GlobalConfig.cs 3.8 KB

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