UrlManager.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace NEIntelligentControl2.Service.WebSocket
  9. {
  10. /// <summary>
  11. /// 链接管理
  12. /// </summary>
  13. public class UrlManager
  14. {
  15. private string servicePath;
  16. /// <summary>
  17. /// 后台服务地址
  18. /// </summary>
  19. public string ServicePath
  20. {
  21. get
  22. {
  23. if (servicePath == null)
  24. {
  25. servicePath = GetConfigurationValue();
  26. }
  27. return servicePath;
  28. }
  29. }
  30. private string dataServicePath;
  31. /// <summary>
  32. /// 数据地址
  33. /// </summary>
  34. public string DataServicePath
  35. {
  36. get
  37. {
  38. if (dataServicePath == null)
  39. {
  40. dataServicePath = GetConfigurationValue();
  41. }
  42. return dataServicePath;
  43. }
  44. }
  45. private string alarmPath;
  46. /// <summary>
  47. /// 报警地址
  48. /// </summary>
  49. public string AlarmPath
  50. {
  51. get
  52. {
  53. if (alarmPath == null)
  54. {
  55. alarmPath = GetConfigurationValue();
  56. }
  57. return alarmPath;
  58. }
  59. }
  60. private string serviceSocketPath;
  61. /// <summary>
  62. /// 后台推送地址
  63. /// </summary>
  64. public string ServiceSocketPath
  65. {
  66. get
  67. {
  68. if (serviceSocketPath == null)
  69. {
  70. serviceSocketPath = GetConfigurationValue();
  71. }
  72. return serviceSocketPath;
  73. }
  74. }
  75. private string adapterSocketPath;
  76. /// <summary>
  77. /// 数据推送地址
  78. /// </summary>
  79. public string AdapterSocketPath
  80. {
  81. get
  82. {
  83. if (adapterSocketPath == null)
  84. {
  85. adapterSocketPath = GetConfigurationValue();
  86. }
  87. return adapterSocketPath;
  88. }
  89. }
  90. private int windturbineDetailsInterval = -777;
  91. /// <summary>
  92. /// 风机详情页弹窗时间间隔
  93. /// </summary>
  94. public int WindturbineDetailsInterval
  95. {
  96. get
  97. {
  98. if (windturbineDetailsInterval == -777)
  99. {
  100. windturbineDetailsInterval = GetConfigurationValueInt();
  101. }
  102. return windturbineDetailsInterval;
  103. }
  104. }
  105. private int GetConfigurationValueInt([CallerMemberName] string name = null)
  106. {
  107. if (name == null) return 0;
  108. try
  109. {
  110. var v = ConfigurationManager.AppSettings[name];
  111. int.TryParse(v, out int d);
  112. return d;
  113. }
  114. catch (Exception ex)
  115. {
  116. Console.WriteLine($"读取配置文件[{name}]出错!", ex);
  117. return 0;
  118. }
  119. }
  120. /// <summary>
  121. /// 获取配置文件值
  122. /// </summary>
  123. private string GetConfigurationValue([CallerMemberName] string name = null)
  124. {
  125. if (name == null) return "";
  126. try
  127. {
  128. #if (DEBUG)
  129. name += "Debug";
  130. #endif
  131. return ConfigurationManager.AppSettings[name];
  132. }
  133. catch (Exception ex)
  134. {
  135. Console.WriteLine($"读取配置文件[{name}]出错!", ex);
  136. return "";
  137. }
  138. }
  139. }
  140. }