master
smartwyy 6 months ago
parent 13da1bf688
commit e008fe6040

@ -0,0 +1,39 @@
using System.Collections.Concurrent;
namespace HybirdFrameworkDriver.Common;
public class MsgCache
{
private readonly ConcurrentDictionary<string, dynamic> _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);
}
}

@ -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();
}
}

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

@ -0,0 +1,11 @@
namespace Service.Cloud.Handler;
public interface IBaseHandler<in T>
{
public void Handler(T t);
public bool CanHandle(object obj)
{
return obj.GetType() == typeof(T);
}
}

@ -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<Model<SignInResp>>
{
public void Handler(Model<SignInResp> t)
{
}
}

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

@ -0,0 +1,25 @@
namespace Service.Cloud.Msg;
public class Header
{
/// <summary>
///
/// </summary>
public string cmd { get; set; }
/// <summary>
///
/// </summary>
public int id { get; set; }
/// <summary>
///
/// </summary>
public string sid { get; set; }
/// <summary>
///
/// </summary>
public int chipherFlag { get; set; }
/// <summary>
///
/// </summary>
public long timeStamp { get; set; }
}

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

@ -0,0 +1,6 @@
namespace Service.Cloud.Msg;
public interface ICmd
{
public string GetCmd();
}

@ -0,0 +1,8 @@
namespace Service.Cloud.Msg;
public class Model<T> where T : ICmd
{
public Header Header { get; set; }
public T body { get; set; }
public string dataSign { get; set; }
}

@ -14,6 +14,7 @@
<PackageReference Include="DotNetty.Handlers" Version="0.7.5"/>
<PackageReference Include="DotNetty.Transport" Version="0.7.5"/>
<PackageReference Include="log4net" Version="2.0.15"/>
<PackageReference Include="MQTTnet.AspNetCore" Version="4.3.5.1141" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.115"/>
<PackageReference Include="System.ServiceModel.Duplex" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.Http" Version="4.8.1" />
@ -28,4 +29,9 @@
<ProjectReference Include="..\Repository\Repository.csproj"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Cloud\Msg\Cloud\Req\" />
<Folder Include="Cloud\Msg\Host\Resp\" />
</ItemGroup>
</Project>

@ -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
}
/// <summary>
///
/// </summary>
/// <param name="key">GroupCode#code</param>
/// <returns></returns>
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;
}
/// <summary>
///
/// </summary>
/// <param name="key">GroupCode#code</param>
/// <param name="value"></param>
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);
}
}
}
}

@ -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": []
}
Loading…
Cancel
Save