GlobalConfig.cs 3.0 KB

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