You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

148 lines
4.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Configuration;
  7. using BPA.Utility.Consul.YT;
  8. using System.IO;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.Configuration.Consul;
  11. using System.Threading;
  12. using HBLConsole.Service;
  13. namespace HBLConsole.GVL
  14. {
  15. /// <summary>
  16. /// 网络信息数据
  17. /// </summary>
  18. public class InternetInfo
  19. {
  20. //private volatile static InternetInfo _Instance;
  21. //public static InternetInfo GetInstance => _Instance ?? (_Instance = new InternetInfo());
  22. //private InternetInfo() { }
  23. /// <summary>
  24. /// 配置初始化
  25. /// </summary>
  26. public static void ConfigInit()
  27. {
  28. NetworkConnectState = UniversalHelper.GetInstance.GetNetworkState();
  29. while (!NetworkConnectState)
  30. {
  31. NetworkConnectState = UniversalHelper.GetInstance.GetNetworkState();
  32. Thread.Sleep(2000);
  33. }
  34. ConsulAddress = System.Configuration.ConfigurationManager.AppSettings["ConsulAddress"];
  35. ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]);
  36. ProductKey = System.Configuration.ConfigurationManager.AppSettings["ProductKey"];
  37. DeviceName = System.Configuration.ConfigurationManager.AppSettings["DeviceName"];
  38. DeviceSecret = System.Configuration.ConfigurationManager.AppSettings["DeviceSecret"];
  39. DeviceMS= System.Configuration.ConfigurationManager.AppSettings["DeviceMS"];
  40. while (StockServer == null)
  41. {
  42. try
  43. {
  44. IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/basic.json", false, 5_000);
  45. IConfiguration config = configurationBuilder.Build();
  46. MqttUserName = config["MQTT:TcpAccount"];
  47. MqttPassword = config["MQTT:TcpPwd"];
  48. MqttAddress = config["MQTT:IP"];
  49. MqttPort = int.Parse(config["MQTT:Client"]);
  50. ApiAddress = config["GateWay:BaseURL"];
  51. OrderServer = config["GateWay:Order"];
  52. StockServer = config["GateWay:Stock"];
  53. }
  54. catch (Exception ex)
  55. {
  56. MessageLog.GetInstance.Show(ex.ToString());
  57. Thread.Sleep(30000);
  58. }
  59. }
  60. }
  61. /// <summary>
  62. /// Consul 地址
  63. /// </summary>
  64. public static string ConsulAddress { get; set; }
  65. /// <summary>
  66. /// 网络连接状态
  67. /// </summary>
  68. public static bool NetworkConnectState { get; set; }
  69. /// <summary>
  70. /// 广告地址
  71. /// </summary>
  72. public static Uri SorbetesAddress { get; set; }
  73. /// <summary>
  74. /// 客户端ID
  75. /// </summary>
  76. public static int ClientId { get; set; }
  77. #region MQTT连接信息
  78. /// <summary>
  79. /// mqtt 服务地址
  80. /// </summary>
  81. public static string MqttAddress { get; set; }
  82. /// <summary>
  83. /// mqtt 用户名
  84. /// </summary>
  85. public static string MqttUserName { get; set; }
  86. /// <summary>
  87. /// mqtt 密码
  88. /// </summary>
  89. public static string MqttPassword { get; set; }
  90. /// <summary>
  91. /// mqtt 端口号
  92. /// </summary>
  93. public static int MqttPort { get; set; }
  94. #endregion
  95. #region API地址
  96. /// <summary>
  97. /// Api 网关地址
  98. /// </summary>
  99. public static string ApiAddress { get; set; }
  100. /// <summary>
  101. /// 订单服务
  102. /// </summary>
  103. public static string OrderServer { get; set; }
  104. /// <summary>
  105. /// 库存服务
  106. /// </summary>
  107. public static string StockServer { get; set; }
  108. #endregion
  109. #region IOT设备地址
  110. /// <summary>
  111. /// IOT ProductKey
  112. /// </summary>
  113. public static string ProductKey { get; set; }
  114. /// <summary>
  115. /// IOT DeviceName
  116. /// </summary>
  117. public static string DeviceName { get; set; }
  118. /// <summary>
  119. /// IOT DeviceSecret
  120. /// </summary>
  121. public static string DeviceSecret { get; set; }
  122. /// <summary>
  123. /// IOT DeviceMS
  124. /// </summary>
  125. public static string DeviceMS { get; set; }
  126. #endregion
  127. }
  128. }