From e008fe6040cf16112dbc0da8d202bc5fb9468ede Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Tue, 21 May 2024 19:53:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HybirdFrameworkDriver/Common/MsgCache.cs | 39 +++++++++++++ Service/Cloud/Client/CloudClient.cs | 56 ++++++++++++++++++ Service/Cloud/Common/CloudConst.cs | 11 ++++ Service/Cloud/Handler/IBaseHandler.cs | 11 ++++ Service/Cloud/Handler/SignInRespHandler.cs | 13 +++++ Service/Cloud/Msg/Cloud/Resp/SignInResp.cs | 16 ++++++ Service/Cloud/Msg/Header.cs | 25 ++++++++ Service/Cloud/Msg/Host/Req/SignIn.cs | 17 ++++++ Service/Cloud/Msg/ICmd.cs | 6 ++ Service/Cloud/Msg/Model.cs | 8 +++ Service/Service.csproj | 6 ++ Service/System/SysConfigService.cs | 57 ++++++++++++++++++- .../Debug/net6.0/staticwebassets.build.json | 12 +--- 13 files changed, 265 insertions(+), 12 deletions(-) create mode 100644 HybirdFrameworkDriver/Common/MsgCache.cs create mode 100644 Service/Cloud/Client/CloudClient.cs create mode 100644 Service/Cloud/Common/CloudConst.cs create mode 100644 Service/Cloud/Handler/IBaseHandler.cs create mode 100644 Service/Cloud/Handler/SignInRespHandler.cs create mode 100644 Service/Cloud/Msg/Cloud/Resp/SignInResp.cs create mode 100644 Service/Cloud/Msg/Header.cs create mode 100644 Service/Cloud/Msg/Host/Req/SignIn.cs create mode 100644 Service/Cloud/Msg/ICmd.cs create mode 100644 Service/Cloud/Msg/Model.cs diff --git a/HybirdFrameworkDriver/Common/MsgCache.cs b/HybirdFrameworkDriver/Common/MsgCache.cs new file mode 100644 index 0000000..29a1e26 --- /dev/null +++ b/HybirdFrameworkDriver/Common/MsgCache.cs @@ -0,0 +1,39 @@ +using System.Collections.Concurrent; + +namespace HybirdFrameworkDriver.Common; + +public class MsgCache +{ + private readonly ConcurrentDictionary _dictionary = new(); + private static readonly string MsgKey = "msg_"; + + public void Add(string key, dynamic value) + { + _dictionary[key] = value; + } + + public bool TryGet(string key, out dynamic? value) + { + return _dictionary.TryGetValue(key, out value); + } + + public void Remove(string key) + { + _dictionary.Remove(key, out var value); + } + + public void AddByMsgId(int key, dynamic value) + { + _dictionary[MsgKey + key] = value; + } + + public bool TryGetMsgId(int key, out dynamic? value) + { + return _dictionary.TryGetValue(MsgKey + key, out value); + } + + public void RemoveMsgId(int key) + { + _dictionary.Remove(MsgKey + key, out var value); + } +} \ No newline at end of file diff --git a/Service/Cloud/Client/CloudClient.cs b/Service/Cloud/Client/CloudClient.cs new file mode 100644 index 0000000..04776d0 --- /dev/null +++ b/Service/Cloud/Client/CloudClient.cs @@ -0,0 +1,56 @@ +using System.Text; +using MQTTnet.Client; +using MQTTnet.Formatter; + +namespace Service.Cloud.Client; + +public class CloudClient +{ + #region client param + + public string ServerIp { get; set; } + 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; } + + #endregion + + + private MqttClientOptions BuildOptions() + { + MqttClientOptionsBuilder builder = + new MqttClientOptionsBuilder().WithTcpServer(ServerIp, ServerPort).WithClientId(ClientId); + if (!string.IsNullOrWhiteSpace(Username)) + { + builder.WithCredentials(Username, Encoding.UTF8.GetBytes(Password)); + } + + if (IsCleanSession) + { + builder.WithCleanSession(); + } + + builder.WithKeepAlivePeriod(TimeSpan.FromSeconds(KeepalivePeriod)).WithTimeout(TimeSpan.FromSeconds(Timeout)); + switch (Version) + { + case "3.1.0": + builder.WithProtocolVersion(MqttProtocolVersion.V310); + break; + + case "5.0.16": + builder.WithProtocolVersion(MqttProtocolVersion.V500); + break; + + default: + builder.WithProtocolVersion(MqttProtocolVersion.V311); + break; + } + + return builder.Build(); + } +} \ No newline at end of file diff --git a/Service/Cloud/Common/CloudConst.cs b/Service/Cloud/Common/CloudConst.cs new file mode 100644 index 0000000..1a6bc8b --- /dev/null +++ b/Service/Cloud/Common/CloudConst.cs @@ -0,0 +1,11 @@ +namespace Service.Cloud.Common; + +public class CloudConst +{ + #region cmd definition + + public static readonly string signIn = "signIn"; + public static readonly string signInRes = "signInRes"; + + #endregion +} \ No newline at end of file diff --git a/Service/Cloud/Handler/IBaseHandler.cs b/Service/Cloud/Handler/IBaseHandler.cs new file mode 100644 index 0000000..fcbb96d --- /dev/null +++ b/Service/Cloud/Handler/IBaseHandler.cs @@ -0,0 +1,11 @@ +namespace Service.Cloud.Handler; + +public interface IBaseHandler +{ + public void Handler(T t); + + public bool CanHandle(object obj) + { + return obj.GetType() == typeof(T); + } +} \ No newline at end of file diff --git a/Service/Cloud/Handler/SignInRespHandler.cs b/Service/Cloud/Handler/SignInRespHandler.cs new file mode 100644 index 0000000..fc3ade3 --- /dev/null +++ b/Service/Cloud/Handler/SignInRespHandler.cs @@ -0,0 +1,13 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using Service.Cloud.Msg; +using Service.Cloud.Msg.Cloud.Resp; + +namespace Service.Cloud.Handler; + +[Scope("InstancePerDependency")] +public class SignInRespHandler : IBaseHandler> +{ + public void Handler(Model t) + { + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Cloud/Resp/SignInResp.cs b/Service/Cloud/Msg/Cloud/Resp/SignInResp.cs new file mode 100644 index 0000000..18882c3 --- /dev/null +++ b/Service/Cloud/Msg/Cloud/Resp/SignInResp.cs @@ -0,0 +1,16 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg.Cloud.Resp; + +public class SignInResp : ICmd +{ + public int re { get; set; } + public int dl_up { get; set; } + public DateTime ti { get; set; } + public int ew { get; set; } + + public string GetCmd() + { + return CloudConst.signInRes; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Header.cs b/Service/Cloud/Msg/Header.cs new file mode 100644 index 0000000..8ffd0f8 --- /dev/null +++ b/Service/Cloud/Msg/Header.cs @@ -0,0 +1,25 @@ +namespace Service.Cloud.Msg; + +public class Header +{ + /// + /// + /// + public string cmd { get; set; } + /// + /// + /// + public int id { get; set; } + /// + /// + /// + public string sid { get; set; } + /// + /// + /// + public int chipherFlag { get; set; } + /// + /// + /// + public long timeStamp { get; set; } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Host/Req/SignIn.cs b/Service/Cloud/Msg/Host/Req/SignIn.cs new file mode 100644 index 0000000..a53f263 --- /dev/null +++ b/Service/Cloud/Msg/Host/Req/SignIn.cs @@ -0,0 +1,17 @@ +using Service.Cloud.Common; + +namespace Service.Cloud.Msg; + +public class SignIn : ICmd +{ + public string sn { get; set; } + public string ky { get; set; } + public string st { get; set; } + public string dv { get; set; } + public string sv { get; set; } + + public string GetCmd() + { + return CloudConst.signIn; + } +} \ No newline at end of file diff --git a/Service/Cloud/Msg/ICmd.cs b/Service/Cloud/Msg/ICmd.cs new file mode 100644 index 0000000..8a12f60 --- /dev/null +++ b/Service/Cloud/Msg/ICmd.cs @@ -0,0 +1,6 @@ +namespace Service.Cloud.Msg; + +public interface ICmd +{ + public string GetCmd(); +} \ No newline at end of file diff --git a/Service/Cloud/Msg/Model.cs b/Service/Cloud/Msg/Model.cs new file mode 100644 index 0000000..374a576 --- /dev/null +++ b/Service/Cloud/Msg/Model.cs @@ -0,0 +1,8 @@ +namespace Service.Cloud.Msg; + +public class Model where T : ICmd +{ + public Header Header { get; set; } + public T body { get; set; } + public string dataSign { get; set; } +} \ No newline at end of file diff --git a/Service/Service.csproj b/Service/Service.csproj index 136039a..8694b81 100644 --- a/Service/Service.csproj +++ b/Service/Service.csproj @@ -14,6 +14,7 @@ + @@ -28,4 +29,9 @@ + + + + + diff --git a/Service/System/SysConfigService.cs b/Service/System/SysConfigService.cs index 627ab9e..0128e45 100644 --- a/Service/System/SysConfigService.cs +++ b/Service/System/SysConfigService.cs @@ -1,16 +1,15 @@ using System.ComponentModel; using Autofac; -using Common.Const; using Common.Enum; using Entity.Base; using Entity.DbModel.System.SysBaseObject; using Entity.Dto.Req; -using Furion.FriendlyException; using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Redis; using Mapster; using Microsoft.AspNetCore.Mvc; +using Org.BouncyCastle.Security; using Repository.System; using Service.Mgr; using SqlSugar; @@ -156,5 +155,59 @@ namespace Service.System } + /// + /// + /// + /// GroupCode#code + /// + public string? Get(string key) + { + string[] keys = key.Split("#"); + if (keys.Length !=2) + { + throw new InvalidParameterException("配置数据key格式错误"); + } + + SysConfig sysConfig = _sysConfigRep.QueryByClause(i => i.GroupCode == keys[0] && i.Code == keys[1]); + if (sysConfig == null) + { + return null; + } + + return sysConfig.Value; + } + + /// + /// + /// + /// GroupCode#code + /// + public void Set(string key, string value) + { + string[] keys = key.Split("#"); + if (keys.Length !=2) + { + throw new InvalidParameterException("配置数据key格式错误"); + } + + SysConfig sysConfig = _sysConfigRep.QueryByClause(i => i.GroupCode == keys[0] && i.Code == keys[1]); + if (sysConfig == null) + { + _sysConfigRep.Insert(new SysConfig() + { + GroupCode = keys[0], + Code = keys[1], + Value = value, + SysFlag = YesNoEnum.N, + Name = key + }); + } + else + { + sysConfig.Value = value; + _sysConfigRep.Update(sysConfig); + } + + } } } diff --git a/WebStarter/obj/Debug/net6.0/staticwebassets.build.json b/WebStarter/obj/Debug/net6.0/staticwebassets.build.json index 572be60..309b0b1 100644 --- a/WebStarter/obj/Debug/net6.0/staticwebassets.build.json +++ b/WebStarter/obj/Debug/net6.0/staticwebassets.build.json @@ -1,19 +1,11 @@ { "Version": 1, - "Hash": "FS59OvTZ9B6lpwaxIjb4jYpPMI2uWVuvwpvRJoWtEFc=", + "Hash": "7euZr+Skxn+CPwHhQ3H6LZuur9IzJqC+CYg6oY75X7A=", "Source": "WebStarter", "BasePath": "_content/WebStarter", "Mode": "Default", "ManifestType": "Build", "ReferencedProjectsConfiguration": [], - "DiscoveryPatterns": [ - { - "Name": "WebStarter\\wwwroot", - "Source": "WebStarter", - "ContentRoot": "D:\\Desktop\\huannengMain\\WebStarter\\wwwroot\\", - "BasePath": "_content/WebStarter", - "Pattern": "**" - } - ], + "DiscoveryPatterns": [], "Assets": [] } \ No newline at end of file