Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

132 řádky
3.9 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. while (StockServer == null)
  37. {
  38. try
  39. {
  40. IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/basic.json", false, 5_000);
  41. IConfiguration config = configurationBuilder.Build();
  42. MqttUserName = config["MQTT:TcpAccount"];
  43. MqttPassword = config["MQTT:TcpPwd"];
  44. MqttAddress = config["MQTT:IP"];
  45. MqttPort = int.Parse(config["MQTT:Client"]);
  46. ApiAddress = config["GateWay:BaseURL"];
  47. OrderServer = config["GateWay:Order"];
  48. StockServer = config["GateWay:Stock"];
  49. IotApiAddress = config["IOT:Address"];
  50. }
  51. catch (Exception ex)
  52. {
  53. MessageLog.GetInstance.Show(ex.ToString());
  54. Thread.Sleep(30000);
  55. }
  56. }
  57. }
  58. /// <summary>
  59. /// Consul 地址
  60. /// </summary>
  61. public static string ConsulAddress { get; set; }
  62. /// <summary>
  63. /// 网络连接状态
  64. /// </summary>
  65. public static bool NetworkConnectState { get; set; }
  66. /// <summary>
  67. /// 广告地址
  68. /// </summary>
  69. public static Uri SorbetesAddress { get; set; }
  70. /// <summary>
  71. /// 客户端ID
  72. /// </summary>
  73. public static int ClientId { get; set; }
  74. /// <summary>
  75. /// IOTAPI 地址
  76. /// </summary>
  77. public static string IotApiAddress { get; set; }
  78. #region MQTT连接信息
  79. /// <summary>
  80. /// mqtt 服务地址
  81. /// </summary>
  82. public static string MqttAddress { get; set; }
  83. /// <summary>
  84. /// mqtt 用户名
  85. /// </summary>
  86. public static string MqttUserName { get; set; }
  87. /// <summary>
  88. /// mqtt 密码
  89. /// </summary>
  90. public static string MqttPassword { get; set; }
  91. /// <summary>
  92. /// mqtt 端口号
  93. /// </summary>
  94. public static int MqttPort { get; set; }
  95. #endregion
  96. #region API地址
  97. /// <summary>
  98. /// Api 网关地址
  99. /// </summary>
  100. public static string ApiAddress { get; set; }
  101. /// <summary>
  102. /// 订单服务
  103. /// </summary>
  104. public static string OrderServer { get; set; }
  105. /// <summary>
  106. /// 库存服务
  107. /// </summary>
  108. public static string StockServer { get; set; }
  109. #endregion
  110. }
  111. }