静态数据读写

master
smartwyy 6 months ago
parent 9442d9515c
commit f09f2cfde3

@ -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

@ -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<SysConfigService>();
CloudClient = AppInfo.Container.Resolve<CloudClient>();
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();
}
}

@ -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<SysConfigService>();
}
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>();
}
_sysConfigService.Set(key, value);
}
#endregion
}

@ -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
}

@ -182,7 +182,7 @@ namespace Service.System
/// </summary>
/// <param name="key">GroupCode.code</param>
/// <param name="value"></param>
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);
}

Loading…
Cancel
Save