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.
 
 

125 lines
3.7 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. }
  50. catch (Exception ex)
  51. {
  52. MessageLog.GetInstance.Show(ex.ToString());
  53. Thread.Sleep(30000);
  54. }
  55. }
  56. }
  57. /// <summary>
  58. /// Consul 地址
  59. /// </summary>
  60. public static string ConsulAddress { get; set; }
  61. /// <summary>
  62. /// 网络连接状态
  63. /// </summary>
  64. public static bool NetworkConnectState { get; set; }
  65. /// <summary>
  66. /// 广告地址
  67. /// </summary>
  68. public static Uri SorbetesAddress { get; set; }
  69. /// <summary>
  70. /// 客户端ID
  71. /// </summary>
  72. public static int ClientId { get; set; }
  73. #region MQTT连接信息
  74. /// <summary>
  75. /// mqtt 服务地址
  76. /// </summary>
  77. public static string MqttAddress { get; set; }
  78. /// <summary>
  79. /// mqtt 用户名
  80. /// </summary>
  81. public static string MqttUserName { get; set; }
  82. /// <summary>
  83. /// mqtt 密码
  84. /// </summary>
  85. public static string MqttPassword { get; set; }
  86. /// <summary>
  87. /// mqtt 端口号
  88. /// </summary>
  89. public static int MqttPort { get; set; }
  90. #endregion
  91. #region API地址
  92. /// <summary>
  93. /// Api 网关地址
  94. /// </summary>
  95. public static string ApiAddress { get; set; }
  96. /// <summary>
  97. /// 订单服务
  98. /// </summary>
  99. public static string OrderServer { get; set; }
  100. /// <summary>
  101. /// 库存服务
  102. /// </summary>
  103. public static string StockServer { get; set; }
  104. #endregion
  105. }
  106. }