GlobalConfig.cs 2.6 KB

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