diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs index 5892147..49e2c8f 100644 --- a/Service/Cloud/Client/CloudClient.cs +++ b/Service/Cloud/Client/CloudClient.cs @@ -34,11 +34,11 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR public int ServerPort { get; set; } public string ClientId { get; set; } public string? Username { get; set; } - public string Password { get; set; } - public int KeepalivePeriod { get; set; } - public int Timeout { get; set; } - public string Version { get; set; } - public bool IsCleanSession { get; set; } + public string? Password { get; set; } + public int KeepalivePeriod { get; set; } = 30; + public int Timeout { get; set; } = 60; + public string Version { get; set; } = "5.0.16"; + public bool IsCleanSession { get; set; } = false; #endregion diff --git a/Service/Cloud/Client/CloudClientMgr.cs b/Service/Cloud/Client/CloudClientMgr.cs index 14fd7d9..d694665 100644 --- a/Service/Cloud/Client/CloudClientMgr.cs +++ b/Service/Cloud/Client/CloudClientMgr.cs @@ -1,6 +1,8 @@ using Autofac; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; +using Service.Init; +using Service.System; namespace Service.Cloud.Client; @@ -11,7 +13,21 @@ public class CloudClientMgr public static void Init() { + SysConfigService sysConfigService = AppInfo.Container.Resolve(); CloudClient = AppInfo.Container.Resolve(); + + CloudClient.ServerIp = StaticStationInfo.CloudServerIp; + CloudClient.ServerPort = StaticStationInfo.CloudServerPort; + CloudClient.ClientId = StaticStationInfo.CloudClientId; + CloudClient.Username = StaticStationInfo.CloudUsername; + CloudClient.Password = StaticStationInfo.CloudPassword; + CloudClient.SubTopic = StaticStationInfo.CloudSubTopic; + CloudClient.PubTopic = StaticStationInfo.CloudPubTopic; + CloudClient.StationNo = StaticStationInfo.StationNo; + + CloudClient.AutoReConnect = true; + CloudClient.InitHandler(); + CloudClient.Connect(); } } \ No newline at end of file diff --git a/Service/Init/StaticStationInfo.cs b/Service/Init/StaticStationInfo.cs index 8f52904..c2bf035 100644 --- a/Service/Init/StaticStationInfo.cs +++ b/Service/Init/StaticStationInfo.cs @@ -1,4 +1,8 @@ +using Autofac; using Entity.Constant; +using HybirdFrameworkCore.Autofac; +using Service.Station; +using Service.System; namespace Service.Init; @@ -13,7 +17,94 @@ public class StaticStationInfo public static StationConstant.StationModel StationModel; - public static string StationName; - - public static string StationNo; + public static string StationName + { + get => Resolve(StationParamConst.StationName); + set => Set(StationParamConst.StationName, value); + } + + public static string StationNo + { + get => Resolve(StationParamConst.StationNo); + set => Set(StationParamConst.StationNo, value); + } + + + #region cloud + + public static string CloudServerIp + { + get => Resolve(StationParamConst.CloudServerIp); + set => Set(StationParamConst.CloudServerIp, value); + } + + public static int CloudServerPort + { + get => int.Parse(Resolve(StationParamConst.CloudServerPort)); + set => Set(StationParamConst.CloudServerPort, value); + } + + public static string CloudClientId + { + get => Resolve(StationParamConst.CloudClientId); + set => Set(StationParamConst.CloudClientId, value); + } + + public static string CloudUsername + { + get => Resolve(StationParamConst.CloudUsername); + set => Set(StationParamConst.CloudUsername, value); + } + + public static string CloudPassword + { + get => Resolve(StationParamConst.CloudPassword); + set => Set(StationParamConst.CloudPassword, value); + } + + public static string CloudSubTopic + { + get => Resolve(StationParamConst.CloudSubTopic); + set => Set(StationParamConst.CloudSubTopic, value); + } + + public static string CloudPubTopic + { + get => Resolve(StationParamConst.CloudPubTopic); + set => Set(StationParamConst.CloudPubTopic, value); + } + + #endregion + + #region db method + + private static SysConfigService _sysConfigService; + + private static string Resolve(string key) + { + if (_sysConfigService == null) + { + _sysConfigService = AppInfo.Container.Resolve(); + } + + string? s = _sysConfigService.Get(key); + if (s != null) + { + return s; + } + + return "33000"; + } + + private static void Set(string key, object value) + { + if (_sysConfigService == null) + { + _sysConfigService = AppInfo.Container.Resolve(); + } + + _sysConfigService.Set(key, value); + } + + #endregion } \ No newline at end of file diff --git a/Service/Station/StationParamConst.cs b/Service/Station/StationParamConst.cs index d99cfe0..822e1a3 100644 --- a/Service/Station/StationParamConst.cs +++ b/Service/Station/StationParamConst.cs @@ -4,4 +4,16 @@ public class StationParamConst { public static readonly string StationNo = "Station.StationNo"; public static readonly string StationName = "Station.StationName"; + + #region cloud param + + public static readonly string CloudServerIp = "Cloud.CloudServerIp"; + public static readonly string CloudServerPort = "Cloud.CloudServerPort"; + public static readonly string CloudClientId = "Cloud.CloudClientId"; + public static readonly string CloudUsername = "Cloud.CloudUsername"; + public static readonly string CloudPassword = "Cloud.CloudPassword"; + public static readonly string CloudSubTopic = "Cloud.CloudSubTopic"; + public static readonly string CloudPubTopic = "Cloud.CloudPubTopic"; + + #endregion } \ No newline at end of file diff --git a/Service/System/SysConfigService.cs b/Service/System/SysConfigService.cs index e4e0b87..bff4456 100644 --- a/Service/System/SysConfigService.cs +++ b/Service/System/SysConfigService.cs @@ -182,7 +182,7 @@ namespace Service.System /// /// GroupCode.code /// - public void Set(string key, string value) + public void Set(string key, object value) { string[] keys = key.Split('.'); if (keys.Length !=2) @@ -197,14 +197,14 @@ namespace Service.System { GroupCode = keys[0], Code = keys[1], - Value = value, + Value = value.ToString(), SysFlag = YesNoEnum.N, Name = key }); } else { - sysConfig.Value = value; + sysConfig.Value = value.ToString(); _sysConfigRep.Update(sysConfig); }