优化
This commit is contained in:
parent
2c4f401a55
commit
ff1d0f37c6
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -19,7 +19,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
config.SetListenIPHosts(int.Parse(configuration["TCP:Port"] ?? "10500"))
|
||||
.ConfigureContainer(a => //容器的配置顺序应该在最前面
|
||||
{
|
||||
a.AddConsoleLogger(); //添加一个控制台日志注入(注意:在maui中控制台日志不可用)
|
||||
|
||||
//a.AddFileLogger(fileLogger =>
|
||||
//{
|
||||
// fileLogger.MaxSize = 1024 * 1024;
|
||||
// fileLogger.LogLevel = LogLevel.Debug;
|
||||
// fileLogger.CreateLogFolder = level => $"logs\\{DateTime.Now:yyyy-MM-dd}\\{level}";
|
||||
//});
|
||||
a.AddConsoleLogger();
|
||||
})
|
||||
.ConfigurePlugins(a =>
|
||||
{
|
||||
@ -50,7 +57,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
config.SetBindIPHost(int.Parse(configuration["UDP:Port"] ?? "10500"))
|
||||
.ConfigureContainer(a => //容器的配置顺序应该在最前面
|
||||
{
|
||||
a.AddConsoleLogger(); //添加一个控制台日志注入(注意:在maui中控制台日志不可用)
|
||||
//a.AddConsoleLogger();
|
||||
})
|
||||
.ConfigurePlugins(a =>
|
||||
{
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -28,6 +30,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\JiShe.CollectBus.ClickHouse\JiShe.CollectBus.ClickHouse.csproj" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Core\JiShe.CollectBus.Core.csproj" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj" />
|
||||
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
|
||||
|
||||
@ -33,7 +33,6 @@ namespace JiShe.CollectBus.Console
|
||||
services.PluginServiceRegister();
|
||||
services.AddTcp(configuration);
|
||||
services.AddUdp(configuration);
|
||||
|
||||
services.AddStackExchangeRedisCache(options =>
|
||||
{
|
||||
options.Configuration = configuration["RedisCache:ConnectionString"];
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"Default": "Data Source=192.168.111.248;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true"
|
||||
"Default": "Data Source=192.168.111.248;Port=3306;Database=JiSheCollectBus;uid=root;pwd=123456abcD;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true",
|
||||
"ClickHouse": "host=localhost;port=8123;user=default;password=;database=default"
|
||||
},
|
||||
|
||||
"TCP": {
|
||||
|
||||
@ -4,9 +4,10 @@ using TouchSocket.Sockets;
|
||||
|
||||
namespace JiShe.CollectBus.Core.Plugins
|
||||
{
|
||||
public class TcpClosePlugin(ILog logger) : PluginBase, ITcpReceivedPlugin
|
||||
public partial class TcpClosePlugin(ILog logger) : PluginBase
|
||||
{
|
||||
public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e)
|
||||
[GeneratorPlugin(typeof(ITcpReceivedPlugin))]
|
||||
public async Task OnTcpReceived(ITcpSessionClient client, ReceivedDataEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -27,8 +28,9 @@ namespace JiShe.CollectBus.Core.Plugins
|
||||
}
|
||||
}
|
||||
|
||||
public class UdpClosePlugin(ILog logger) : PluginBase, IUdpReceivedPlugin
|
||||
public partial class UdpClosePlugin(ILog logger) : PluginBase
|
||||
{
|
||||
[GeneratorPlugin(typeof(IUdpReceivedPlugin))]
|
||||
public Task OnUdpReceived(IUdpSessionBase client, UdpReceivedDataEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
@ -5,10 +5,10 @@ using TouchSocket.Sockets;
|
||||
|
||||
namespace JiShe.CollectBus.Core.Plugins
|
||||
{
|
||||
public class TcpServiceReceivedPlugin(IServiceProvider serviceProvider) : PluginBase, ITcpReceivedPlugin,
|
||||
ITcpConnectingPlugin, ITcpConnectedPlugin, ITcpClosedPlugin
|
||||
public partial class TcpServiceReceivedPlugin(IServiceProvider serviceProvider) : PluginBase
|
||||
{
|
||||
public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e)
|
||||
[GeneratorPlugin(typeof(ITcpReceivedPlugin))]
|
||||
public async Task OnTcpReceived(ITcpSessionClient client, ReceivedDataEventArgs e)
|
||||
{
|
||||
//TODO: 电表主站到集中器的协议都是376.1协议,集中器下发到电表协议分为645-07和modbus
|
||||
//TODO: 水表主站到集中器的协议分为118和645-97协议
|
||||
@ -18,43 +18,36 @@ namespace JiShe.CollectBus.Core.Plugins
|
||||
|
||||
var protocolPlugin = serviceProvider.GetKeyedService<IProtocolPlugin>(protocolType);
|
||||
client.Logger.Info($"{protocolPlugin?.Get().Name},{protocolPlugin?.Get().RegularExpression}");
|
||||
|
||||
//从客户端收到信息
|
||||
var messageHexString = Convert.ToHexString(e.ByteBlock.Span);
|
||||
client.Logger.Info($"[TCP] 已从{client.GetIPPort()}接收到信息:{messageHexString}");
|
||||
|
||||
protocolPlugin?.Received(e);
|
||||
protocolPlugin?.Received(client,e);
|
||||
await e.InvokeNext();
|
||||
}
|
||||
|
||||
public async Task OnTcpConnecting(ITcpSession client, ConnectingEventArgs e)
|
||||
[GeneratorPlugin(typeof(ITcpConnectingPlugin))]
|
||||
public async Task OnTcpConnecting(ITcpSessionClient client, ConnectingEventArgs e)
|
||||
{
|
||||
if (client is ITcpSessionClient sessionClient)
|
||||
{
|
||||
client.Logger.Info($"[TCP] ID:{sessionClient.Id} IP:{client.GetIPPort()}正在连接中...");
|
||||
}
|
||||
client.Logger.Info($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}正在连接中...");
|
||||
|
||||
await e.InvokeNext();
|
||||
|
||||
}
|
||||
|
||||
public async Task OnTcpConnected(ITcpSession client, ConnectedEventArgs e)
|
||||
[GeneratorPlugin(typeof(ITcpConnectedPlugin))]
|
||||
public async Task OnTcpConnected(ITcpSessionClient client, ConnectedEventArgs e)
|
||||
{
|
||||
if (client is ITcpSessionClient sessionClient)
|
||||
{
|
||||
client.Logger.Info($"[TCP] ID:{sessionClient.Id} IP:{client.GetIPPort()}已连接");
|
||||
}
|
||||
client.Logger.Info($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}已连接");
|
||||
|
||||
await e.InvokeNext();
|
||||
}
|
||||
|
||||
public async Task OnTcpClosed(ITcpSession client, ClosedEventArgs e)
|
||||
[GeneratorPlugin(typeof(ITcpClosedPlugin))]
|
||||
public async Task OnTcpClosed(ITcpSessionClient client, ClosedEventArgs e)
|
||||
{
|
||||
if (client is ITcpSessionClient sessionClient)
|
||||
{
|
||||
client.Logger.Info($"[TCP] ID:{sessionClient.Id} IP:{client.GetIPPort()}已关闭连接");
|
||||
client.Logger.Info($"[TCP] ID:{client.Id} IP:{client.GetIPPort()}已关闭连接");
|
||||
|
||||
}
|
||||
await e.InvokeNext();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,11 +4,11 @@ using TouchSocket.Sockets;
|
||||
|
||||
namespace JiShe.CollectBus.Core.Plugins
|
||||
{
|
||||
public class UdpServiceReceivedPlugin : PluginBase, IUdpReceivedPlugin
|
||||
public partial class UdpServiceReceivedPlugin : PluginBase
|
||||
{
|
||||
[GeneratorPlugin(typeof(IUdpReceivedPlugin))]
|
||||
public async Task OnUdpReceived(IUdpSessionBase client, UdpReceivedDataEventArgs e)
|
||||
{
|
||||
|
||||
var udpSession = client as UdpSession;
|
||||
udpSession?.Logger.Info($"[UDP] 收到:{e.ByteBlock.Span.ToString(Encoding.UTF8)}");
|
||||
await udpSession.SendAsync("[UDP] 收到");
|
||||
|
||||
@ -8,8 +8,9 @@ using TouchSocket.Sockets;
|
||||
|
||||
namespace JiShe.CollectBus.Core.Services
|
||||
{
|
||||
public class BusService : PluginBase, IServerStartedPlugin, IServerStopedPlugin
|
||||
public partial class BusService : PluginBase
|
||||
{
|
||||
[GeneratorPlugin(typeof(IServerStartedPlugin))]
|
||||
public Task OnServerStarted(IServiceBase sender, ServiceStateEventArgs e)
|
||||
{
|
||||
switch (sender)
|
||||
@ -34,6 +35,7 @@ namespace JiShe.CollectBus.Core.Services
|
||||
return e.InvokeNext();
|
||||
}
|
||||
|
||||
[GeneratorPlugin(typeof(IServerStopedPlugin))]
|
||||
public Task OnServerStoped(IServiceBase sender, ServiceStateEventArgs e)
|
||||
{
|
||||
Console.WriteLine("服务已停止");
|
||||
|
||||
@ -9,7 +9,6 @@ namespace JiShe.CollectBus.EntityFrameworkCore.AuditLogs
|
||||
{
|
||||
public class AuditLog : EntityBase<Guid>,ICreationAudited<long?>
|
||||
{
|
||||
public string Re
|
||||
public long? CreatorId { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Abstracts
|
||||
|
||||
public abstract ProtocolInfo Get();
|
||||
|
||||
public abstract void Received(ReceivedDataEventArgs e);
|
||||
public abstract void Received(ITcpSessionClient client, ReceivedDataEventArgs e);
|
||||
|
||||
public abstract void Send();
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ namespace JiShe.CollectBus.Protocol.Contracts.Interfaces
|
||||
|
||||
void Load();
|
||||
|
||||
void Received(ReceivedDataEventArgs e);
|
||||
void Received(ITcpSessionClient client, ReceivedDataEventArgs e);
|
||||
|
||||
void Send();
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ namespace JiShe.CollectBus.Protocol.Test
|
||||
return new ProtocolInfo("Test", "376.1", "TCP", "376.1协议", "DTSU1980");
|
||||
}
|
||||
|
||||
public override void Received(ReceivedDataEventArgs e)
|
||||
public override void Received(ITcpSessionClient client, ReceivedDataEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@ -26,6 +26,8 @@ namespace JiShe.CollectBus.Protocol
|
||||
static List<int> MSA = new List<int>();
|
||||
static Dictionary<string, List<int>> usingMSA = new Dictionary<string, List<int>>();
|
||||
|
||||
private ITcpSessionClient tcpSessionClient;
|
||||
|
||||
static StandardProtocolPlugin()
|
||||
{
|
||||
for (int i = 1; i <= 127; i++)
|
||||
@ -45,8 +47,9 @@ namespace JiShe.CollectBus.Protocol
|
||||
base.Load();
|
||||
}
|
||||
|
||||
public override void Received(ReceivedDataEventArgs e)
|
||||
public override void Received(ITcpSessionClient client, ReceivedDataEventArgs e)
|
||||
{
|
||||
tcpSessionClient = client;
|
||||
var messageHexString = Convert.ToHexString(e.ByteBlock.Span);
|
||||
var cmdResult = AnalysisCmd(messageHexString);
|
||||
if (cmdResult == null)
|
||||
@ -54,7 +57,6 @@ namespace JiShe.CollectBus.Protocol
|
||||
return;
|
||||
}
|
||||
AnalysisData(cmdResult);
|
||||
|
||||
}
|
||||
|
||||
public override void Send()
|
||||
@ -282,7 +284,7 @@ namespace JiShe.CollectBus.Protocol
|
||||
{
|
||||
TpV = TpV.附加信息域中无时间标签,
|
||||
FIRFIN = FIRFIN.单帧,
|
||||
CON = CON.不需要对该帧进行确认,
|
||||
CON = CON.需要对该帧进行确认,
|
||||
PRSEQ = commandReulst.Seq.PRSEQ,
|
||||
},
|
||||
MSA = commandReulst.MSA,
|
||||
@ -290,6 +292,8 @@ namespace JiShe.CollectBus.Protocol
|
||||
Fn = 1
|
||||
};
|
||||
commandReulst.ReplyBytes = GetCommandBytes(reqParam);
|
||||
tcpSessionClient.SendAsync(tcpSessionClient.Id,commandReulst.ReplyBytes);
|
||||
|
||||
}
|
||||
else if (commandReulst.Fn == 2)//退出登录
|
||||
{
|
||||
|
||||
@ -19,7 +19,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "core", "core", "{C7DEC9FB-3
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.Protocol.Test", "JiShe.CollectBus.Protocol.Test\JiShe.CollectBus.Protocol.Test.csproj", "{289196B4-FFBE-4E40-A3A1-FCFADBE945ED}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.EntityFrameworkCore", "JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj", "{16D42BCF-EDB8-4153-B37D-0B10FB6DF36C}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiShe.CollectBus.EntityFrameworkCore", "JiShe.CollectBus.EntityFrameworkCore\JiShe.CollectBus.EntityFrameworkCore.csproj", "{16D42BCF-EDB8-4153-B37D-0B10FB6DF36C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JiShe.CollectBus.ClickHouse", "JiShe.CollectBus.ClickHouse\JiShe.CollectBus.ClickHouse.csproj", "{65A2837C-A5EE-475B-8079-EE5A1BCD2E8F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -55,6 +57,10 @@ Global
|
||||
{16D42BCF-EDB8-4153-B37D-0B10FB6DF36C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{16D42BCF-EDB8-4153-B37D-0B10FB6DF36C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{16D42BCF-EDB8-4153-B37D-0B10FB6DF36C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{65A2837C-A5EE-475B-8079-EE5A1BCD2E8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{65A2837C-A5EE-475B-8079-EE5A1BCD2E8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{65A2837C-A5EE-475B-8079-EE5A1BCD2E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{65A2837C-A5EE-475B-8079-EE5A1BCD2E8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -67,6 +73,7 @@ Global
|
||||
{1D3A5A4E-B977-4E33-A1AF-62508110C3B7} = {C7DEC9FB-3F75-4584-85B0-16EA3CB222E5}
|
||||
{289196B4-FFBE-4E40-A3A1-FCFADBE945ED} = {3A04FB29-EA75-4499-BBF3-AF24C7D46A1D}
|
||||
{16D42BCF-EDB8-4153-B37D-0B10FB6DF36C} = {C7DEC9FB-3F75-4584-85B0-16EA3CB222E5}
|
||||
{65A2837C-A5EE-475B-8079-EE5A1BCD2E8F} = {C7DEC9FB-3F75-4584-85B0-16EA3CB222E5}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {33261859-9CD1-4A43-B181-AB75C247D1CD}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user