GlobalConfig.cs 3.1 KB

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