终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

133 rindas
4.5 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. if (deviceConfigModelJsons?.Count > 0)
  48. {
  49. ClientId = int.Parse(deviceConfigModelJsons.ElementAt(0).ShopId);
  50. }
  51. //ClientId = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ClientId"]);
  52. apolloUri = System.Configuration.ConfigurationManager.AppSettings["ApolloUri"].ToString();
  53. apoid = System.Configuration.ConfigurationManager.AppSettings["AppId"].ToString();
  54. namespa = System.Configuration.ConfigurationManager.AppSettings["Namespaces"].ToString();
  55. InternetInfo.IsEnableTest = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["IsEnableTest"].ToString());
  56. InitDeviceModel();
  57. InitConfig();
  58. }
  59. public List<DeviceConfig> GetDeviceConfigs()
  60. {
  61. if (null == deviceConfigs)
  62. InitDeviceModel();
  63. return deviceConfigs;
  64. }
  65. /// <summary>
  66. /// 加载设备模型
  67. /// </summary>
  68. private void InitDeviceModel()
  69. {
  70. }
  71. public void InitConfig()
  72. {
  73. IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory());
  74. configurationBuilder.AddApolloConfiguration(p =>
  75. {
  76. p.AppId = apoid;
  77. p.MetaServer = apolloUri;
  78. p.Namespaces = new List<string>() { "application", namespa };
  79. });
  80. IConfiguration config = configurationBuilder.Build();
  81. MQTT_Config = config.GetSection("BrokerHostSettings").Value.FromJSON<MQTT_Entity>();
  82. Mqtt_Account = config.GetSection("MqttAccount").Value.FromJSON<MQTT_Account>();
  83. uriConfig = config.GetSection("URL").Value.FromJSON<UriConfig>();
  84. if (uriConfig != null)
  85. {
  86. InternetInfo.OrderServer = uriConfig.OrderServiceUrl;
  87. InternetInfo.StockServer = uriConfig.StockServiceUrl;
  88. InternetInfo.BroadcastPubTopic = uriConfig.BroadcastPubTopic;
  89. InternetInfo.DataVApiAddress = uriConfig.DataVServiceUrl;
  90. InternetInfo.WebServiceUri = uriConfig.WebServiceUrl;
  91. ActionManage.GetInstance.Send("配置初始化完成Iot启动");
  92. }
  93. }
  94. public void Start()
  95. {
  96. }
  97. public class MQTT_Entity
  98. {
  99. public string Host { get; set; }
  100. public int Port { get; set; }
  101. }
  102. public class MQTT_Account
  103. {
  104. public string UserName { get; set; }
  105. public string Password { get; set; }
  106. }
  107. public class UriConfig
  108. {
  109. public string OrderServiceUrl { get; set; }
  110. public string StockServiceUrl { get; set; }
  111. public string DataVServiceUrl { get; set; }
  112. public string WebServiceUrl { get; set; }
  113. public string BroadcastPubTopic { get; set; }
  114. }
  115. }
  116. }