终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

134 rader
4.6 KiB

  1. using BPA.ApolloClient;
  2. using BPA.Message;
  3. using BPASmartClient.Helper;
  4. using BPASmartClient.Message;
  5. using BPASmartClient.Model;
  6. using Microsoft.Extensions.Configuration;
  7. using Newtonsoft.Json;
  8. using System.Collections.ObjectModel;
  9. using System.Xml.Linq;
  10. using System.Xml.XPath;
  11. namespace BPASmartClient.Business
  12. {
  13. /// <summary>
  14. /// 配置管理器
  15. /// </summary>
  16. public class ConfigMgr : IPlugin
  17. {
  18. /// <summary>
  19. /// 门店ID
  20. /// </summary>
  21. public int ClientId { get; set; }
  22. /// <summary>
  23. /// MQTT Broker
  24. /// </summary>
  25. public MQTT_Entity MQTT_Config { get; set; }
  26. public MQTT_Account Mqtt_Account { get; set; }
  27. public UriConfig uriConfig { get; set; }
  28. public ObservableCollection<DeviceConfigModelJson> deviceConfigModelJsons { get; set; }
  29. //Apollo地址
  30. private string apolloUri;
  31. private string apoid;
  32. private string namespa;
  33. //设备集合
  34. private List<DeviceConfig> deviceConfigs;
  35. public void Dispose()
  36. {
  37. }
  38. public void Initialize()
  39. {
  40. var text = TextHelper.GetInstance.ReadTextInfo("StartShop", "DeviceConfig");
  41. string path = $"{LocaPath.GetInstance().GetDeviceConfigPath}{text}.json";
  42. if (File.Exists(path))
  43. {
  44. string JsonString = File.ReadAllText(path);
  45. deviceConfigModelJsons = JsonConvert.DeserializeObject<ObservableCollection<DeviceConfigModelJson>>(JsonString);
  46. }
  47. else deviceConfigModelJsons = new ObservableCollection<DeviceConfigModelJson>();
  48. if (deviceConfigModelJsons?.Count > 0)
  49. {
  50. ClientId = int.Parse(deviceConfigModelJsons.ElementAt(0).ShopId);
  51. }
  52. //ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]);
  53. apolloUri = System.Configuration.ConfigurationManager.AppSettings["ApolloUri"].ToString();
  54. apoid = System.Configuration.ConfigurationManager.AppSettings["AppId"].ToString();
  55. namespa = System.Configuration.ConfigurationManager.AppSettings["Namespaces"].ToString();
  56. InternetInfo.IsEnableTest = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["IsEnableTest"].ToString());
  57. InitDeviceModel();
  58. InitConfig();
  59. }
  60. public List<DeviceConfig> GetDeviceConfigs()
  61. {
  62. if (null == deviceConfigs)
  63. InitDeviceModel();
  64. return deviceConfigs;
  65. }
  66. /// <summary>
  67. /// 加载设备模型
  68. /// </summary>
  69. private void InitDeviceModel()
  70. {
  71. }
  72. public void InitConfig()
  73. {
  74. IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory());
  75. configurationBuilder.AddApolloConfiguration(p =>
  76. {
  77. p.AppId = apoid;
  78. p.MetaServer = apolloUri;
  79. p.Namespaces = new List<string>() { "application", namespa };
  80. });
  81. IConfiguration config = configurationBuilder.Build();
  82. MQTT_Config = config.GetSection("BrokerHostSettings").Value.FromJSON<MQTT_Entity>();
  83. Mqtt_Account = config.GetSection("MqttAccount").Value.FromJSON<MQTT_Account>();
  84. uriConfig = config.GetSection("URL").Value.FromJSON<UriConfig>();
  85. if (uriConfig != null)
  86. {
  87. InternetInfo.OrderServer = uriConfig.OrderServiceUrl;
  88. InternetInfo.StockServer = uriConfig.StockServiceUrl;
  89. InternetInfo.BroadcastPubTopic = uriConfig.BroadcastPubTopic;
  90. InternetInfo.DataVApiAddress = uriConfig.DataVServiceUrl;
  91. InternetInfo.WebServiceUri = uriConfig.WebServiceUrl;
  92. ActionManage.GetInstance.Send("配置初始化完成Iot启动");
  93. }
  94. }
  95. public void Start()
  96. {
  97. }
  98. public class MQTT_Entity
  99. {
  100. public string Host { get; set; }
  101. public int Port { get; set; }
  102. }
  103. public class MQTT_Account
  104. {
  105. public string UserName { get; set; }
  106. public string Password { get; set; }
  107. }
  108. public class UriConfig
  109. {
  110. public string OrderServiceUrl { get; set; }
  111. public string StockServiceUrl { get; set; }
  112. public string DataVServiceUrl { get; set; }
  113. public string WebServiceUrl { get; set; }
  114. public string BroadcastPubTopic { get; set; }
  115. }
  116. }
  117. }