GlobalConfig.cs 2.9 KB

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