GlobalConfig.cs 3.0 KB

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