using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Configuration; using BPA.Utility.Consul.YT; using System.IO; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Consul; using System.Threading; using HBLConsole.Service; namespace HBLConsole.GVL { /// /// 网络信息数据 /// public class InternetInfo { //private volatile static InternetInfo _Instance; //public static InternetInfo GetInstance => _Instance ?? (_Instance = new InternetInfo()); //private InternetInfo() { } /// /// 配置初始化 /// public static void ConfigInit() { NetworkConnectState = UniversalHelper.GetInstance.GetNetworkState(); while (!NetworkConnectState) { NetworkConnectState = UniversalHelper.GetInstance.GetNetworkState(); Thread.Sleep(2000); } ConsulAddress = System.Configuration.ConfigurationManager.AppSettings["ConsulAddress"]; ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]); while (StockServer == null) { try { IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddConsul(ConsulAddress, "root/basic.json", false, 5_000); IConfiguration config = configurationBuilder.Build(); MqttUserName = config["MQTT:TcpAccount"]; MqttPassword = config["MQTT:TcpPwd"]; MqttAddress = config["MQTT:IP"]; MqttPort = int.Parse(config["MQTT:Client"]); ApiAddress = config["GateWay:BaseURL"]; OrderServer = config["GateWay:Order"]; StockServer = config["GateWay:Stock"]; IotApiAddress = config["IOT:Address"]; } catch (Exception ex) { MessageLog.GetInstance.Show(ex.ToString()); Thread.Sleep(30000); } } } /// /// Consul 地址 /// public static string ConsulAddress { get; set; } /// /// 网络连接状态 /// public static bool NetworkConnectState { get; set; } /// /// 广告地址 /// public static Uri SorbetesAddress { get; set; } /// /// 客户端ID /// public static int ClientId { get; set; } /// /// IOTAPI 地址 /// public static string IotApiAddress { get; set; } #region MQTT连接信息 /// /// mqtt 服务地址 /// public static string MqttAddress { get; set; } /// /// mqtt 用户名 /// public static string MqttUserName { get; set; } /// /// mqtt 密码 /// public static string MqttPassword { get; set; } /// /// mqtt 端口号 /// public static int MqttPort { get; set; } #endregion #region API地址 /// /// Api 网关地址 /// public static string ApiAddress { get; set; } /// /// 订单服务 /// public static string OrderServer { get; set; } /// /// 库存服务 /// public static string StockServer { get; set; } #endregion } }