GlobalConfig.cs 3.1 KB

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