|
- 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
- {
- /// <summary>
- /// 网络信息数据
- /// </summary>
- public class InternetInfo
- {
- //private volatile static InternetInfo _Instance;
- //public static InternetInfo GetInstance => _Instance ?? (_Instance = new InternetInfo());
- //private InternetInfo() { }
-
- /// <summary>
- /// 配置初始化
- /// </summary>
- 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"];
- }
- catch (Exception ex)
- {
- MessageLog.GetInstance.Show(ex.ToString());
- Thread.Sleep(30000);
- }
- }
- }
-
-
-
- /// <summary>
- /// Consul 地址
- /// </summary>
- public static string ConsulAddress { get; set; }
-
- /// <summary>
- /// 网络连接状态
- /// </summary>
- public static bool NetworkConnectState { get; set; }
-
- /// <summary>
- /// 广告地址
- /// </summary>
- public static Uri SorbetesAddress { get; set; }
-
- /// <summary>
- /// 客户端ID
- /// </summary>
- public static int ClientId { get; set; }
-
- #region MQTT连接信息
- /// <summary>
- /// mqtt 服务地址
- /// </summary>
- public static string MqttAddress { get; set; }
-
- /// <summary>
- /// mqtt 用户名
- /// </summary>
- public static string MqttUserName { get; set; }
-
- /// <summary>
- /// mqtt 密码
- /// </summary>
- public static string MqttPassword { get; set; }
-
- /// <summary>
- /// mqtt 端口号
- /// </summary>
- public static int MqttPort { get; set; }
- #endregion
-
- #region API地址
-
- /// <summary>
- /// Api 网关地址
- /// </summary>
- public static string ApiAddress { get; set; }
-
- /// <summary>
- /// 订单服务
- /// </summary>
- public static string OrderServer { get; set; }
-
- /// <summary>
- /// 库存服务
- /// </summary>
- public static string StockServer { get; set; }
- #endregion
-
- }
- }
|