GlobalConfig.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using Microsoft.Extensions.Configuration;
  2. using Newtonsoft.Json;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. namespace EVCB_OCPP.WSServer
  7. {
  8. public static class GlobalConfig
  9. {
  10. public static List<string> ConfigKeys = new List<string>()
  11. {
  12. "WSPort",
  13. "WSSPort",
  14. "OCPP20_WSUrl",
  15. "OCPP20_WSSUrl"
  16. };
  17. public static List<string> DenyModelNames = new List<string>();
  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 JsonSerializerSettings JSONSERIALIZER_FORMAT = new JsonSerializerSettings()
  24. {
  25. NullValueHandling = NullValueHandling.Ignore,
  26. Formatting = Formatting.None,
  27. DateFormatString = UTC_DATETIMEFORMAT
  28. };
  29. /// <summary>
  30. /// 預設心跳間隔時間 單位:秒
  31. /// </summary>
  32. private static int DEFAULT_HEARTBEAT_INTERVAL = 60;
  33. /// <summary>
  34. ///WS Port
  35. /// </summary>
  36. private static int WS_Port = 80;
  37. /// <summary>
  38. ///WSS Port
  39. /// </summary>
  40. private static int WSS_Port = 443;
  41. public static bool LoadAPPConfig(IConfiguration configuration)
  42. {
  43. bool result = false;
  44. string key = string.Empty;
  45. try
  46. {
  47. for (int i = 0; i < ConfigKeys.Count; i++)
  48. {
  49. key = ConfigKeys[i];
  50. switch (key)
  51. {
  52. case "WSPort":// convert to int type
  53. {
  54. var value = configuration[key];
  55. WS_Port = string.IsNullOrEmpty(value) ? WS_Port : Convert.ToInt32(value);
  56. }
  57. break;
  58. case "WSSPort":
  59. {
  60. var value = configuration[key];
  61. WSS_Port = string.IsNullOrEmpty(value) ? WS_Port : Convert.ToInt32(value);
  62. }
  63. break;
  64. case "OCPP20_WSUrl":// convert to int type
  65. {
  66. var value = configuration[key];
  67. OCPP20_WSUrl = value;
  68. }
  69. break;
  70. case "OCPP20_WSSUrl":// convert to int type
  71. {
  72. var value = configuration[key];
  73. OCPP20_WSSUrl = value;
  74. }
  75. break;
  76. default://convert to string type
  77. break;
  78. }
  79. }
  80. result = true;
  81. }
  82. catch (Exception ex)
  83. {
  84. Console.WriteLine(key + " Load from APPConfig " + ex.ToString());
  85. }
  86. return result;
  87. }
  88. public static int GetWS_Port()
  89. {
  90. return WS_Port;
  91. }
  92. public static int GetWSS_Port()
  93. {
  94. return WSS_Port;
  95. }
  96. public static int GetHEARTBEAT_INTERVAL()
  97. {
  98. return DEFAULT_HEARTBEAT_INTERVAL;
  99. }
  100. public static readonly int DB_DefaultConnectionTimeout = 60;
  101. /// <summary>
  102. /// 預設 Null的 DateTime
  103. /// </summary>
  104. public static DateTime DefaultNullTime = new DateTime(1991, 1, 1);
  105. }
  106. }