From b4093bc3cbe7e1c347bd9d366528a74b8a18f570 Mon Sep 17 00:00:00 2001 From: ningshuxia <ningshuxia0927@outlook.com> Date: 星期五, 18 十一月 2022 17:24:26 +0800 Subject: [PATCH] 苏州金庭电磁流量计对接(未完成!) --- Server/IStation.DataDocking.Socket.Custom/helper/ConfigHelper.cs | 41 + Socket/IStation.DataDockingSocket4SZJT_KT/helper/HandleDataHelper.cs | 288 ++++----- Server/IStation.DataDocking.Socket/IStation.DataDocking.Socket.csproj | 1 Server/IStation.DataDocking.Socket.Custom/Job/ServiceJobHelper.cs | 65 ++ Socket/IStation.DataDockingSocket4KQ/HandleHelper.cs | 5 Server/IStation.DataDocking.Socket.Custom/helper/CorpHelper.cs | 33 + Server/IStation.DataDocking.Socket.Custom/IStation.DataDocking.Socket.Custom.csproj | 24 Model/IStation.Model.Monitor/data_docking/DataDockingConfigure_Model.cs | 22 TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Program.cs | 15 Socket/IStation.DataDockingSocket4SZJT_KT/helper/MsgHelper.cs | 29 TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/IStation.TopShelf.DataDocking.Socket.Custom.csproj | 17 TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Properties/PublishProfiles/FolderProfile.pubxml | 12 Server/IStation.DataDocking.Socket.Custom/Job/PackageHandleHelper.cs | 73 ++ Server/IStation.DataDocking.Socket.Custom/PipeLineFilterFactory/MyPipeLineFilterFactory.cs | 19 Server/IStation.DataDocking.Socket.Custom/helper/SocketJobHelper.cs | 34 + Socket/IStation.DataDockingSocket4NT/HandleHelper.cs | 7 TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Service.cs | 40 + Server/IStation.DataDocking.Socket.Custom/PackageInfo/PackageInfo.cs | 24 TopShelf/IStation.TopShelf.DataDocking4Socket/Properties/PublishProfiles/FolderProfile.pubxml.user | 2 Socket/IStation.DataDockingSocket4SZJT_KT/HandleHelper.cs | 51 + IStation.DataDocking.Socket.sln | 14 Server/IStation.DataDocking.Socket.Custom/AppSession/MySession.cs | 103 +++ Server/IStation.DataDocking.Socket.Custom/Job/ServiceJob.cs | 132 ++++ /dev/null | 108 --- Socket/IStation.DataDockingSocket4SZJT_KT/paras_datadocking_socket_szjt_kt.json | 207 ------- Server/IStation.DataDocking.Socket.Custom/AppServer/MyServer.cs | 42 + Socket/IStation.DataDockingSocket4SZJT_KT/paras/AppParas.cs | 152 ---- TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Properties/PublishProfiles/FolderProfile.pubxml.user | 10 Socket/IStation.DataDockingSocket4SZZS/HandleHelper.cs | 10 Socket/IStation.IDataDockingSocket/IHandleHelper.cs | 9 Server/IStation.DataDocking.Socket.Custom/PipeLineFilter/MyPipeLineFilter.cs | 35 + Server/IStation.DataDocking.Socket.Custom/Program.cs | 9 32 files changed, 970 insertions(+), 663 deletions(-) diff --git a/IStation.DataDocking.Socket.sln b/IStation.DataDocking.Socket.sln index 55f5b46..99bed8b 100644 --- a/IStation.DataDocking.Socket.sln +++ b/IStation.DataDocking.Socket.sln @@ -101,7 +101,11 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IStation.DataDockingSocket4NT", "Socket\IStation.DataDockingSocket4NT\IStation.DataDockingSocket4NT.csproj", "{F5C46CF6-BB42-411D-B1D2-A42AD4A34148}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IStation.DataDockingSocket4SZJT_KT", "Socket\IStation.DataDockingSocket4SZJT_KT\IStation.DataDockingSocket4SZJT_KT.csproj", "{52EB70CF-DA75-4B9A-9518-FAB3C6B2C840}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IStation.DataDockingSocket4SZJT_KT", "Socket\IStation.DataDockingSocket4SZJT_KT\IStation.DataDockingSocket4SZJT_KT.csproj", "{52EB70CF-DA75-4B9A-9518-FAB3C6B2C840}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IStation.DataDocking.Socket.Custom", "Server\IStation.DataDocking.Socket.Custom\IStation.DataDocking.Socket.Custom.csproj", "{6CC5E54B-495E-4E77-8F59-BC9875AAF09C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IStation.TopShelf.DataDocking.Socket.Custom", "TopShelf\IStation.TopShelf.DataDocking.Socket.Custom\IStation.TopShelf.DataDocking.Socket.Custom.csproj", "{EE97C373-86B6-4D5B-A053-CFEE9DE45555}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -273,6 +277,14 @@ {52EB70CF-DA75-4B9A-9518-FAB3C6B2C840}.Debug|Any CPU.Build.0 = Debug|Any CPU {52EB70CF-DA75-4B9A-9518-FAB3C6B2C840}.Release|Any CPU.ActiveCfg = Release|Any CPU {52EB70CF-DA75-4B9A-9518-FAB3C6B2C840}.Release|Any CPU.Build.0 = Release|Any CPU + {6CC5E54B-495E-4E77-8F59-BC9875AAF09C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CC5E54B-495E-4E77-8F59-BC9875AAF09C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CC5E54B-495E-4E77-8F59-BC9875AAF09C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CC5E54B-495E-4E77-8F59-BC9875AAF09C}.Release|Any CPU.Build.0 = Release|Any CPU + {EE97C373-86B6-4D5B-A053-CFEE9DE45555}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE97C373-86B6-4D5B-A053-CFEE9DE45555}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE97C373-86B6-4D5B-A053-CFEE9DE45555}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE97C373-86B6-4D5B-A053-CFEE9DE45555}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Model/IStation.Model.Monitor/data_docking/DataDockingConfigure_Model.cs b/Model/IStation.Model.Monitor/data_docking/DataDockingConfigure_Model.cs index cc6ac8b..3cd4389 100644 --- a/Model/IStation.Model.Monitor/data_docking/DataDockingConfigure_Model.cs +++ b/Model/IStation.Model.Monitor/data_docking/DataDockingConfigure_Model.cs @@ -63,7 +63,7 @@ /// /// </summary> public StandardConfigureParameters(StandardConfigureParameters rhs) - { + { this.RegisterCode = rhs.RegisterCode; } @@ -88,7 +88,7 @@ /// /// </summary> public ApiConfigureParameters(ApiConfigureParameters rhs) - { + { this.Frequency = rhs.Frequency; this.DependencyFile = rhs.DependencyFile; } @@ -120,8 +120,8 @@ public MiddleLibConfigureParameters(MiddleLibConfigureParameters rhs) { this.Frequency = rhs.Frequency; - this.DependencyFile= rhs.DependencyFile; - } + this.DependencyFile = rhs.DependencyFile; + } /// <summary> /// 杞棰戠巼 绉� @@ -149,11 +149,12 @@ /// /// </summary> public SocketConfigureParameters(SocketConfigureParameters rhs) - { + { this.ServerPort = rhs.ServerPort; - this.RegisterCode= rhs.RegisterCode; - this.Heartbeat= rhs.Heartbeat; - this.DependencyFile=rhs.DependencyFile; + this.RegisterCode = rhs.RegisterCode; + this.Heartbeat = rhs.Heartbeat; + this.DependencyFile = rhs.DependencyFile; + this.IsCustom = rhs.IsCustom; } /// <summary> @@ -176,6 +177,11 @@ /// </summary> public string DependencyFile { get; set; } + /// <summary> + /// 鏄惁鑷畾涔� + /// </summary> + public bool IsCustom { get; set; } + } } diff --git a/Server/IStation.DataDocking.Socket.Custom/AppServer/MyServer.cs b/Server/IStation.DataDocking.Socket.Custom/AppServer/MyServer.cs new file mode 100644 index 0000000..7d369d3 --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/AppServer/MyServer.cs @@ -0,0 +1,42 @@ +锘縰sing System; +using System.Threading.Tasks; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using SuperSocket; +using SuperSocket.Channel; +using SuperSocket.ProtoBase; +using SuperSocket.Server; + +namespace IStation.Server +{ + internal class MyServer : SuperSocketService<PackageInfo> + { + + public MyServer(IServiceProvider serviceProvider, IOptions<ServerOptions> serverOptions) + : base(serviceProvider, serverOptions) + { + } + protected override async ValueTask OnSessionConnectedAsync(IAppSession session) + { + await base.OnSessionConnectedAsync(session); + } + protected override async ValueTask OnSessionClosedAsync(IAppSession session, CloseEventArgs e) + { + await base.OnSessionClosedAsync(session, e); + } + protected override ValueTask OnStartedAsync() + { + LogHelper.Info($"Socket鏁版嵁瀵规帴鏈嶅姟,绔彛:{this.Options.Listeners.First().Port},寮�鍚紒"); + return base.OnStartedAsync(); + } + protected override ValueTask OnStopAsync() + { + LogHelper.Info($"Socket鏁版嵁瀵规帴鏈嶅姟,绔彛:{this.Options.Listeners.First().Port},鍏抽棴锛�"); + return base.OnStopAsync(); + } + + + + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/AppSession/MySession.cs b/Server/IStation.DataDocking.Socket.Custom/AppSession/MySession.cs new file mode 100644 index 0000000..07585a2 --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/AppSession/MySession.cs @@ -0,0 +1,103 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IStation.Model; +using SuperSocket; +using SuperSocket.Channel; +using SuperSocket.ProtoBase; +using SuperSocket.Server; + +namespace IStation.Server +{ + /// <summary> + /// Session浼氳瘽 + /// </summary> + internal class MySession : AppSession,Model.IMonitorDataDockingSession + { + /// <summary> + /// 浼氳瘽鍚嶇О + /// </summary> + public string SessionName { get; set; } + + /// <summary> + /// 娉ㄥ唽鐮� + /// </summary> + public string RegisterCode { get; set; } + + /// <summary> + /// 蹇冭烦鍖� + /// </summary> + public string Heartbeat { get; set; } + + /// <summary> + /// 鏄惁杩炴帴 + /// </summary> + public bool IsConnected + { + get + { + return this.State == SessionState.Connected; + } + } + + /// <summary> + /// 鍏抽棴浜嬩欢 + /// </summary> + public event Action SessionClosedEvent; + + protected override ValueTask OnSessionConnectedAsync() + { + LogHelper.Info(this.RemoteEndPoint.ToString() + "杩炴帴鎴愬姛锛�"); + return base.OnSessionConnectedAsync(); + } + + protected override ValueTask OnSessionClosedAsync(CloseEventArgs e) + { + this.SessionClosedEvent?.Invoke(); + LogHelper.Info($"{this.SessionName},Socket杩炴帴鍏抽棴锛屽叧闂師鍥狅細{e.Reason}"); + return base.OnSessionClosedAsync(e); + } + + /// <summary> + /// 鍙戦�佹枃鏈� + /// </summary> + public async void Send(string message) + { + var bts=Encoding.UTF8.GetBytes(message); + var memory=new ReadOnlyMemory<byte>(bts); + await ((IAppSession)this).SendAsync(memory); + } + + /// <summary> + /// 鍙戦�佸瓧鑺� + /// </summary> + public async void Send(byte[] data) + { + var memory = new ReadOnlyMemory<byte>(data); + await ((IAppSession)this).SendAsync(memory); + } + + /// <summary> + /// 鍙戦�佸瓧鑺� + /// </summary> + public void Send(byte[] data, int offset, int length) + { + var bts = new byte[length]; + Buffer.BlockCopy(data, offset, bts, 0, length); + Send(bts); + } + + /// <summary> + /// 鍏抽棴 + /// </summary> + public async void Close(string reason) + { + LogHelper.Info($"{this.SessionName} 鍑嗗鍏抽棴浼氳瘽锛屽師鍥�:{reason}"); + await base.CloseAsync(); + } + + + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/IStation.DataDocking.Socket.Custom.csproj b/Server/IStation.DataDocking.Socket.Custom/IStation.DataDocking.Socket.Custom.csproj new file mode 100644 index 0000000..3186cb1 --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/IStation.DataDocking.Socket.Custom.csproj @@ -0,0 +1,24 @@ +锘�<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>disable</Nullable> + </PropertyGroup> + + <ItemGroup> + <Compile Remove="AppSession\AppSession.cs" /> + </ItemGroup> + + <ItemGroup> + <ProjectReference Include="..\..\Component\IStation.Quartz\IStation.Quartz.csproj" /> + <ProjectReference Include="..\..\Component\IStation.RabbitMq\IStation.RabbitMq.csproj" /> + <ProjectReference Include="..\..\Component\IStation.SuperSocket\IStation.SuperSocket.csproj" /> + <ProjectReference Include="..\..\Service\IStation.Service.Monitor\IStation.Service.Monitor.csproj" /> + <ProjectReference Include="..\..\Service\IStation.Service.Organize\IStation.Service.Organize.csproj" /> + <ProjectReference Include="..\..\Socket\IStation.DataDockingSocket4SZJT_KT\IStation.DataDockingSocket4SZJT_KT.csproj" /> + <ProjectReference Include="..\..\Socket\IStation.DataDockingSocketFactory\IStation.DataDockingSocketFactory.csproj" /> + </ItemGroup> + +</Project> diff --git a/Server/IStation.DataDocking.Socket.Custom/Job/PackageHandleHelper.cs b/Server/IStation.DataDocking.Socket.Custom/Job/PackageHandleHelper.cs new file mode 100644 index 0000000..c2d06a4 --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/Job/PackageHandleHelper.cs @@ -0,0 +1,73 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using IStation.Untity; +using SuperSocket; +using static Org.BouncyCastle.Math.EC.ECCurve; + +namespace IStation.Server +{ + /// <summary> + /// 鎺ユ敹淇℃伅杈呭姪绫� + /// </summary> + internal class PackageHandleHelper + { + public static List<Model.DataDockingConfigureExSocket> ConfigureList { get; set; } + + //鎺ユ敹鏁版嵁 + public async ValueTask Handle(IAppSession session, PackageInfo requestInfo) + { + await Task.Run(() => + { + var mySession = (MySession)session; + if (ConfigureList == null || ConfigureList.Count < 1) + { + LogHelper.Info("Socket鏁版嵁瀵规帴浠诲姟涓紝鏈绱㈠埌閲囩敤Socket鏂瑰紡鐨勬暟鎹鎺ラ厤缃紒"); + return; + } + + var message_str = BytesTransfer.ToString(requestInfo.Body); + var message_bts = BitTransfer.ToString(requestInfo.Body); + LogHelper.Info($"Socket鏁版嵁瀵规帴鏈嶅姟绔彛:{session.Server.Options.Listeners.First().Port}锛屾帴鏀跺埌鏁版嵁锛歿message_bts}锛�"); + + bool reslut = false; + foreach (var config in ConfigureList) + { + var customDataDocking = DataDockingSocketFactory.CreateSocket<IDataDockingSocket.IHandleHelper>(config.ConfigureParas.DependencyFile); + if (customDataDocking.Valid(requestInfo.Body)) + { + LogHelper.Info($"Socket鏁版嵁瀵规帴涓�,{config.Name}锛屾帴鏀跺埌鏁版嵁锛歿message_bts}"); + customDataDocking.HandleData(mySession, requestInfo.Body, config.Mappers, (receive_list) => + { + if (receive_list == null || receive_list.Count < 1) + { + LogHelper.Info($"Socket鏁版嵁瀵规帴涓紝娉ㄥ唽鐮�:{config.Name},鑾峰彇娴嬬偣璁板綍澶辫触锛�"); + return; + } + var queue = new RabbitMqQueueHelper(); + queue.Push(ConfigHelper.QueueName, new Model.MonitorDataDockingCorpRecord() + { + CorpID = config.CorpID, + ConfigureID = config.ID, + Records = receive_list + }); + LogHelper.Info($"Socket鏁版嵁瀵规帴涓�:{config.Name}锛屾垚鍔熸帹鍏ラ�氶亾{receive_list.Count()}鏉℃暟鎹紒"); + }); + return; + } + } + + if (!reslut) + { + LogHelper.Info($"鑷畾涔塖ocket鏁版嵁瀵规帴浠诲姟涓�,绔彛锛歿mySession.Server.Options.Listeners.First().Port},鏀跺埌涓�鏉℃棤娉曡瘑鍒殑娑堟伅锛歿message_str}"); + } + + }); + + } + + + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/Job/ServiceJob.cs b/Server/IStation.DataDocking.Socket.Custom/Job/ServiceJob.cs new file mode 100644 index 0000000..9d00ad0 --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/Job/ServiceJob.cs @@ -0,0 +1,132 @@ +锘縰sing Quartz; +using SuperSocket; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Server +{ + [DisallowConcurrentExecution]//姝ょ壒鎬ф爣璇� 蹇呴』绛夊緟杩欐浠诲姟鎵ц瀹屾垚鍚庯紝鎵嶈兘鎵ц涓嬫浠诲姟 + internal class ServiceJob : IJob + { + private static List<IServer> _appServers = new List<IServer>();//鎵�鏈夌殑鏈嶅姟 + public Task Execute(IJobExecutionContext context) + { + + return Task.Run(() => + { + try + { + //瀹㈡埛鏍囪瘑鍒楄〃 + var corpIds = CorpHelper.GetCorpIds(); + if (corpIds == null || corpIds.Count < 1) + { + LogHelper.Info($"Socket鏁版嵁瀵规帴浠诲姟绠$悊鍣ㄤ腑,鏈绱㈠埌闇�瑕佸鎺ョ殑瀹㈡埛鏍囪瘑淇℃伅锛�"); + CancelServers(); + return; + } + + //鏁版嵁瀵规帴閰嶇疆鍒楄〃 + var service_configure = new Service.DataDockingConfigure(); + var configure_list = service_configure.GetByCorpIds(corpIds); + if (configure_list == null || configure_list.Count < 1) + { + LogHelper.Info($"Socket鏁版嵁瀵规帴浠诲姟绠$悊鍣ㄤ腑,鏈绱㈠埌鏁版嵁瀵规帴閰嶇疆锛�"); + CancelServers(); + return; + } + configure_list = configure_list.Where(x => x.DockingMode == Model.DataDockingConfigure.eDockingMode.Socket).ToList(); + if (configure_list == null || configure_list.Count < 1) + { + LogHelper.Info($"Socket鏁版嵁瀵规帴浠诲姟绠$悊鍣ㄤ腑,鏈绱㈠埌Socket鏁版嵁瀵规帴閰嶇疆锛�"); + CancelServers(); + return; + } + configure_list = configure_list.Where(x => x.UseStatus == Model.eUseStatus.Enable).ToList(); + if (configure_list == null || configure_list.Count < 1) + { + LogHelper.Info($"Socket鏁版嵁瀵规帴浠诲姟绠$悊鍣ㄤ腑,鏈绱㈠埌鏈夋晥鐨凷ocket鏁版嵁瀵规帴閰嶇疆锛�"); + CancelServers(); + return; + } + + var configure_socket_list = configure_list.Select(x => new Model.DataDockingConfigureExSocket(x)).ToList(); + configure_socket_list = configure_socket_list.Where(x=>x.ConfigureParas.IsCustom).ToList(); + if (configure_socket_list == null || configure_socket_list.Count < 1) + { + LogHelper.Info($"Socket鏁版嵁瀵规帴浠诲姟绠$悊鍣ㄤ腑,鏈绱㈠埌鏈夋晥鐨勮嚜瀹氫箟Socket鏁版嵁瀵规帴閰嶇疆锛�"); + CancelServers(); + return; + } + + PackageHandleHelper.ConfigureList = configure_socket_list; + + //闇�瑕佸紑鍚殑绔彛 + var port_list = configure_socket_list.Select(x => x.ConfigureParas.ServerPort).Distinct().ToList(); + + //寰幆寮�鍚湇鍔� + port_list.ForEach(async x => + { + var server = _appServers.Find(t => t.Options.Listeners.First().Port == x); + if (server == null) + { + var host = SuperSocketHostBuilder.Create<PackageInfo>(); + host.UsePipelineFilterFactory<MyPipeLineFilterFactory>(); + host.UseSession<MySession>(); + host.UseHostedService<MyServer>(); + host.ConfigureSuperSocket(options => + { + options.MaxPackageLength = 1000000; + options.ReceiveBufferSize = 1000000; + options.SendBufferSize = 1000000; + options.Listeners = new List<ListenOptions>() + { + new ListenOptions(){ Ip="Any",Port=x} + }; + }); + host.UsePackageHandler(new PackageHandleHelper().Handle); + server = host.BuildAsServer(); + await server.StartAsync(); + _appServers.Add(server); + LogHelper.Info(string.Format("Socket鏈嶅姟锛岀鍙�:{0} 寮�鍚紒", x)); + } + }); + + //寰幆鍙栨秷鏈嶅姟 + _appServers.ToList().ForEach(async x => + { + if (!port_list.Contains(x.Options.Listeners.First().Port)) + { + await x.StopAsync(); + _appServers.Remove(x); + LogHelper.Info(string.Format("Socket鏈嶅姟锛岀鍙�:{0} 鍏抽棴锛�", x)); + } + }); + LogHelper.Info($"Socket鏁版嵁瀵规帴鏈嶅姟绠$悊鍣ㄤ腑锛屾湇鍔″紑鍚暟閲忎负{_appServers.Count}!"); + } + catch (Exception ex) + { + LogHelper.Error("Socket鏁版嵁瀵规帴鏈嶅姟绠$悊鍣ㄤ腑锛屼换鍔℃墽琛屽嚭閿欙紒", ex); + var e = new JobExecutionException(ex); + throw e; + } + }); + } + + + + /// <summary> + /// 鍙栨秷鎵�鏈夋湇鍔� + /// </summary> + public static void CancelServers() + { + if (_appServers == null || _appServers.Count < 1) + return; + _appServers.ForEach(async x =>await x.StopAsync()); + _appServers.Clear(); + } + + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/Job/ServiceJobHelper.cs b/Server/IStation.DataDocking.Socket.Custom/Job/ServiceJobHelper.cs new file mode 100644 index 0000000..e44e703 --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/Job/ServiceJobHelper.cs @@ -0,0 +1,65 @@ +锘縰sing Quartz; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Server +{ + /// <summary> + /// Socket鏁版嵁瀵规帴鏈嶅姟浠诲姟杈呭姪绫� + /// </summary> + internal class ServiceJobHelper + { + private const string _jobName = "SocketServiceJob"; + private const string _jobGroup = "SocketServiceJobGroup"; + private const string _triggerName = "SocketServiceJobTrigger"; + private static IScheduler _sched;//璋冨害鍣� + + public async Task StartJob() + { + if (_sched != null) + return; + + // 1.鍒涘缓scheduler鐨勫紩鐢� + var fac = new Quartz.Impl.StdSchedulerFactory(); + _sched = await fac.GetScheduler(); + + //2.鍚姩 scheduler + await _sched.Start(); + + //3.鍒涘缓浠诲姟 + var job = JobBuilder.Create<ServiceJob>() + .WithIdentity(_jobName, _jobGroup) + .Build(); + + //4.鍒涘缓Trigger + var trigger = TriggerBuilder.Create() + .WithIdentity(_triggerName, _jobGroup) + .WithSimpleSchedule(x => x.WithIntervalInMinutes(ConfigHelper.ResetFrequency) + .RepeatForever() + .WithMisfireHandlingInstructionNextWithRemainingCount()) + .Build(); + + //5.鍔犲叆璋冨害绠$悊鍣� + await _sched.ScheduleJob(job, trigger); + } + + /// <summary> + /// 鍙栨秷浠诲姟 + /// </summary> + public async Task CancelJob() + { + if (_sched == null) + return; + var triggerKey = new TriggerKey(_triggerName, _jobGroup); + if (await _sched.CheckExists(triggerKey)) + { + await _sched.UnscheduleJob(triggerKey); + } + ServiceJob.CancelServers(); + } + + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/PackageInfo/PackageInfo.cs b/Server/IStation.DataDocking.Socket.Custom/PackageInfo/PackageInfo.cs new file mode 100644 index 0000000..949235a --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/PackageInfo/PackageInfo.cs @@ -0,0 +1,24 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; + +namespace IStation.Server +{ + /// <summary> + /// 鍖呬俊鎭� + /// </summary> + public class PackageInfo + { + public PackageInfo() { } + public PackageInfo(byte[] buffer) + { + this.Body = buffer?.ToArray(); + } + + public byte[] Body { get; set; } + + + + + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/PipeLineFilter/MyPipeLineFilter.cs b/Server/IStation.DataDocking.Socket.Custom/PipeLineFilter/MyPipeLineFilter.cs new file mode 100644 index 0000000..748b35e --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/PipeLineFilter/MyPipeLineFilter.cs @@ -0,0 +1,35 @@ +锘縰sing SuperSocket.ProtoBase; +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Text; +using System.Linq; + +namespace IStation.Server +{ + public class MyPipeLineFilter : TerminatorPipelineFilter<PackageInfo> + { + public MyPipeLineFilter() :base(null) + { } + + public MyPipeLineFilter(ReadOnlyMemory<byte> terminator) : base(terminator) + { + + } + + public override PackageInfo Filter(ref SequenceReader<byte> reader) + { + var sequeue = reader.Sequence; + var info = DecodePackage(ref sequeue); + reader.AdvanceToEnd(); + return info; + } + + protected override PackageInfo DecodePackage(ref ReadOnlySequence<byte> buffer) + { + var bts = buffer.ToArray(); + return new PackageInfo(bts); + } + + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/PipeLineFilterFactory/MyPipeLineFilterFactory.cs b/Server/IStation.DataDocking.Socket.Custom/PipeLineFilterFactory/MyPipeLineFilterFactory.cs new file mode 100644 index 0000000..afeccec --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/PipeLineFilterFactory/MyPipeLineFilterFactory.cs @@ -0,0 +1,19 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using SuperSocket; +using SuperSocket.ProtoBase; + +namespace IStation.Server +{ + /// <summary> + /// 绠¢亾杩囨护宸ュ巶 + /// </summary> + public class MyPipeLineFilterFactory : IPipelineFilterFactory<PackageInfo> + { + public IPipelineFilter<PackageInfo> Create(object client) + { + return new MyPipeLineFilter(null); + } + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/Program.cs b/Server/IStation.DataDocking.Socket.Custom/Program.cs new file mode 100644 index 0000000..0006872 --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/Program.cs @@ -0,0 +1,9 @@ +锘�// See https://aka.ms/new-console-template for more information +using IStation; +using IStation.Server; + +LogHelper.Info("鏈嶅姟姝e湪鍚姩..."); +var jobHelper = new SocketJobHelper(); +await jobHelper.StartJob(); +LogHelper.Info("鏈嶅姟鍚姩鎴愬姛锛�"); +Console.ReadLine(); diff --git a/Server/IStation.DataDocking.Socket.Custom/helper/ConfigHelper.cs b/Server/IStation.DataDocking.Socket.Custom/helper/ConfigHelper.cs new file mode 100644 index 0000000..79c501b --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/helper/ConfigHelper.cs @@ -0,0 +1,41 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; + +namespace IStation.Server +{ + /// <summary> + /// 閰嶇疆鏂囦欢杈呭姪绫� + /// </summary> + internal class ConfigHelper + { + + + /// <summary> + /// 閲嶇疆棰戠巼 鍒嗛挓 + /// </summary> + public static int ResetFrequency + { + get + { + return Settings.DataDocking.Task.ResetFrequency; + } + } + + /// <summary> + /// 閫氶亾鍚嶇О + /// </summary> + public static string QueueName + { + get + { + return Settings.Queue.DataDockingQueueName; + } + } + + + + + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/helper/CorpHelper.cs b/Server/IStation.DataDocking.Socket.Custom/helper/CorpHelper.cs new file mode 100644 index 0000000..3af2dcd --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/helper/CorpHelper.cs @@ -0,0 +1,33 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Server +{ + /// <summary> + /// 瀹㈡埛杈呭姪绫� + /// </summary> + internal class CorpHelper + { + /// <summary> + /// 鑾峰彇瀹㈡埛鏍囪瘑鍒楄〃 + /// </summary> + public static List<long> GetCorpIds() + { + var corpIds = Settings.DataDocking.Target.CorpIds; + if (corpIds == null || corpIds.Count < 1) + { + return default; + } + if (Settings.DataDocking.Target.ContainsChildren) + { + corpIds = new Service.Corpration().GetChildAndSelfIdsByIds(corpIds); + } + return corpIds; + } + + + } +} diff --git a/Server/IStation.DataDocking.Socket.Custom/helper/SocketJobHelper.cs b/Server/IStation.DataDocking.Socket.Custom/helper/SocketJobHelper.cs new file mode 100644 index 0000000..5cbd070 --- /dev/null +++ b/Server/IStation.DataDocking.Socket.Custom/helper/SocketJobHelper.cs @@ -0,0 +1,34 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace IStation.Server +{ + /// <summary> + /// + /// </summary> + public class SocketJobHelper : Model.IMonitorDataDockingJobHelper + { + private ServiceJobHelper _jobHelper = new ServiceJobHelper(); + + /// <summary> + /// + /// </summary> + public async Task StartJob() + { + await _jobHelper.StartJob(); + } + + /// <summary> + /// + /// </summary> + public async Task CancelJob() + { + await _jobHelper.CancelJob(); + } + + + } +} diff --git a/Server/IStation.DataDocking.Socket/IStation.DataDocking.Socket.csproj b/Server/IStation.DataDocking.Socket/IStation.DataDocking.Socket.csproj index 0bf08e4..275ec33 100644 --- a/Server/IStation.DataDocking.Socket/IStation.DataDocking.Socket.csproj +++ b/Server/IStation.DataDocking.Socket/IStation.DataDocking.Socket.csproj @@ -19,7 +19,6 @@ <ProjectReference Include="..\..\Service\IStation.Service.Organize\IStation.Service.Organize.csproj" /> <ProjectReference Include="..\..\Socket\IStation.DataDockingSocket4KQ\IStation.DataDockingSocket4KQ.csproj" /> <ProjectReference Include="..\..\Socket\IStation.DataDockingSocket4NT\IStation.DataDockingSocket4NT.csproj" /> - <ProjectReference Include="..\..\Socket\IStation.DataDockingSocket4SZJT_KT\IStation.DataDockingSocket4SZJT_KT.csproj" /> <ProjectReference Include="..\..\Socket\IStation.DataDockingSocket4SZZS\IStation.DataDockingSocket4SZZS.csproj" /> <ProjectReference Include="..\..\Socket\IStation.DataDockingSocketFactory\IStation.DataDockingSocketFactory.csproj" /> </ItemGroup> diff --git a/Socket/IStation.DataDockingSocket4KQ/HandleHelper.cs b/Socket/IStation.DataDockingSocket4KQ/HandleHelper.cs index c460c10..65b76bd 100644 --- a/Socket/IStation.DataDockingSocket4KQ/HandleHelper.cs +++ b/Socket/IStation.DataDockingSocket4KQ/HandleHelper.cs @@ -116,7 +116,10 @@ } } - + public bool Valid(byte[] bytes) + { + return false; + } diff --git a/Socket/IStation.DataDockingSocket4NT/HandleHelper.cs b/Socket/IStation.DataDockingSocket4NT/HandleHelper.cs index 6918589..e6e8eda 100644 --- a/Socket/IStation.DataDockingSocket4NT/HandleHelper.cs +++ b/Socket/IStation.DataDockingSocket4NT/HandleHelper.cs @@ -120,7 +120,10 @@ } - } + public bool Valid(byte[] bytes) + { + return false; + } - + } } diff --git a/Socket/IStation.DataDockingSocket4SZJT_KT/HandleHelper.cs b/Socket/IStation.DataDockingSocket4SZJT_KT/HandleHelper.cs index 4ddf606..5c7875a 100644 --- a/Socket/IStation.DataDockingSocket4SZJT_KT/HandleHelper.cs +++ b/Socket/IStation.DataDockingSocket4SZJT_KT/HandleHelper.cs @@ -12,12 +12,41 @@ public class HandleHelper : IDataDockingSocket.IHandleHelper { /// <summary> + /// 楠岃瘉 + /// </summary> + public bool Valid(byte[] bytes) + { + SZJTKTLogHelper.Info($"瀛楄妭闀垮害:{bytes.Count()}"); + if (bytes == null || bytes.Count() < 1) + return false; + var appParas = AppParasHelper.Get(); + SZJTKTLogHelper.Info($"鑾峰彇鍙傛暟"); + if (appParas == null) + return false; + var bytePrefix = new byte[8]; + Array.Copy(bytes, 0, bytePrefix, 0, 8); + var prefix = Encoding.ASCII.GetString(bytePrefix); + SZJTKTLogHelper.Info($"鍓嶇紑:{prefix}"); + if (prefix != appParas.Prefix) + return false; + + byte[] byteProductID = new byte[4]; + Array.Copy(bytes, 9, byteProductID, 0, 4); + var productId = HandleDataHelper.Bytes2Int4(byteProductID); + SZJTKTLogHelper.Info($"璁惧缂栧彿:{productId}"); + if (productId.ToString() != appParas.ProductID) + return false; + + return true; + } + + /// <summary> /// 澶勭悊娉ㄥ唽鐮� /// </summary> public void HandleRegisterCode(IMonitorDataDockingSession session) { try - { + { if (session == null) { SZJTKTLogHelper.Error("session == null"); @@ -49,12 +78,6 @@ return; } - SZJTKTLogHelper.Info("寮�濮嬭В鏋愮殑浣嶇疆!"); - foreach (var item in appParas.InstructionItems) - { - SendInstructionJobHelper.StartJob(session, item); - Thread.Sleep(appParas.InstructionSendSpace * 1000); - } } catch (Exception ex) @@ -70,8 +93,8 @@ { } + - /// <summary> /// 澶勭悊鏁版嵁 @@ -89,9 +112,7 @@ if (!session.IsConnected) return; if (bytes == null) - return; - if (!AppParas.Verify(bytes)) - return; + return; if (mappers == null || mappers.Count < 1) return; var appParas = AppParasHelper.Get(); @@ -101,10 +122,9 @@ return; } - var item = appParas.InstructionItems.Find(x => x.Verify(bytes)); - if (item == null) - return; - var src_list = HandleDataHelper.HandleData(item, bytes); + SZJTKTLogHelper.Info($"寮�濮嬪鐞嗘暟鎹�:{BitConverter.ToString(bytes)}"); + + var src_list = HandleDataHelper.HandleData(bytes); if (src_list != null && src_list.Count > 0) { var receive_list = new List<Model.MonitorDataDockingReceiveRecord>(); @@ -134,6 +154,7 @@ } } + } } diff --git a/Socket/IStation.DataDockingSocket4SZJT_KT/helper/HandleDataHelper.cs b/Socket/IStation.DataDockingSocket4SZJT_KT/helper/HandleDataHelper.cs index 1fdaea5..d2b5c4f 100644 --- a/Socket/IStation.DataDockingSocket4SZJT_KT/helper/HandleDataHelper.cs +++ b/Socket/IStation.DataDockingSocket4SZJT_KT/helper/HandleDataHelper.cs @@ -16,8 +16,7 @@ /// 澶勭悊鏁版嵁 /// </summary> public static List<Model.MonitorDataDockingSrcRecord> HandleData - ( - InstructionItem item, + ( byte[] bts ) { @@ -25,220 +24,156 @@ var list = new List<Model.MonitorDataDockingSrcRecord>(); //灏嗘寚浠よ浆鍖栦负瀛楄妭鏁扮粍 - var instrution_bts = BitTransfer.FromString(item.Instruction); - + var instrution_bts = bts; + var byte4 = new byte[4]; + var byte2 = new byte[2]; + var byte1 = new byte[1]; + //鏁版嵁璇诲彇鏃ユ湡 - byte[] byte_data2 = new byte[4]; - Array.Copy(instrution_bts, 13, byte_data2, 0, 4); - var int_data2 = bytesToInt4(byte_data2.Reverse().ToArray()); + Array.Copy(instrution_bts, 13, byte4, 0, 4); + var date = Bytes2Int4(byte4); - //鏁版嵁璇诲彇鏃堕棿 - byte[] byte_data3 = new byte[4]; - Array.Copy(instrution_bts, 17, byte_data3, 0, 4); - var int_data3 = bytesToInt4(byte_data3.Reverse().ToArray()); + //鏁版嵁璇诲彇鏃堕棿 + Array.Copy(instrution_bts, 17, byte4, 0, 4); + var time = Bytes2Int4(byte4); - - var hms = int_data3.ToString(); + var hms = time.ToString(); if (hms.Length < 6) - { hms = "0" + hms; - } var ttt = hms.Substring(0, 2) + ":" + hms.Substring(2, 2) + ":" + hms.Substring(4, 2); - var strTime = $"{int_data2} {ttt}"; - DateTime time = DateTime.ParseExact(strTime.ToString(), "yyyyMMdd hh:mm:ss", System.Globalization.CultureInfo.CurrentCulture); - DateTime time2 = DateTime.ParseExact(ttt, "hhmmss", System.Globalization.CultureInfo.CurrentCulture); + var strTime = $"{date} {ttt}"; + DateTime dataTime = DateTime.ParseExact(strTime.ToString(), "yyyyMMdd hh:mm:ss", System.Globalization.CultureInfo.CurrentCulture); - /* //鐬椂娴侀噺锛宮3/h - byte[] byte_data4 = new byte[4]; - Array.Copy(instrution_bts, 21, byte_data4, 0, 4); - var int_data4 = GetDouble1(byte_data4.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //鐬椂娴侀噺锛宮3/h + Array.Copy(instrution_bts, 21, byte4, 0, 4); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1590274355240243200, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data4.ToString() + SignId = "1590274355240243200", + SrcValue = Bytes2Double(byte4).ToString() + }); + + //鐬椂鍘嬪姏锛孧pa + Array.Copy(instrution_bts, 25, byte4, 0, 4); + list.Add(new Model.MonitorDataDockingSrcRecord() + { + SignId = "1589903942416994304", + SrcValue = Bytes2Double(byte4).ToString() }); - //鐬椂鍘嬪姏锛孧pa - byte[] byte_data5 = new byte[4]; - Array.Copy(instrution_bts, 25, byte_data5, 0, 4); - var int_data5 = GetDouble1(byte_data5.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //鐬椂娴侀�燂紝m3/h + Array.Copy(instrution_bts, 29, byte4, 0, 4); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589903942416994304, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data5.ToString() + SignId = "1589904380742733824", + SrcValue = Bytes2Double(byte4).ToString() }); - //鐬椂娴侀�燂紝m3/h - byte[] byte_data6 = new byte[4]; - Array.Copy(instrution_bts, 29, byte_data6, 0, 4); - var int_data6 = GetDouble1(byte_data6.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //姝e悜绱鏁存暟 + Array.Copy(instrution_bts, 33, byte4, 0, 4); + var ForwardCumulativeFlowInteger = Bytes2Int4(byte4); + //姝e悜绱鐨勫皬鏁�/1000 + Array.Copy(instrution_bts, 41, byte2, 0, 2); + var ForwardCumulativeFlowDecimal = Bytes2Int32(byte2); + //姝e悜绱Н娴侀噺 + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589904380742733824, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data6.ToString() + SignId = "1589903863446638592", + SrcValue = (ForwardCumulativeFlowInteger + ForwardCumulativeFlowDecimal * 0.001).ToString() }); - //姝e悜绱鏁存暟 - byte[] byte_data7 = new byte[4]; - Array.Copy(instrution_bts, 33, byte_data7, 0, 4); - var int_data7 = GetDouble1(byte_data7.Reverse().ToArray()); - - //鍙嶅悜绱鏁存暟 - byte[] byte_data8 = new byte[4]; - Array.Copy(instrution_bts, 37, byte_data8, 0, 4); - var int_data8 = GetDouble1(byte_data8.Reverse().ToArray()); - - //姝e悜绱鐨勫皬鏁�/1000 - byte[] byte_data9 = new byte[2]; - Array.Copy(instrution_bts, 41, byte_data9, 0, 2); - var int_data9 = GetDouble1(byte_data9.Reverse().ToArray()); - - //娣诲姞灏忔暟 - int_data7 += int_data9; - list.Add(new Model.MonitorDataDockingReceiveRecord() + //鍙嶅悜绱鏁存暟 + Array.Copy(instrution_bts, 37, byte4, 0, 4); + var ReverseCumulativeFlowInteger = Bytes2Int4(byte4); + //鍙嶅悜绱鐨勫皬鏁� /1000 + Array.Copy(instrution_bts, 43, byte2, 0, 2); + var ReverseCumulativeFlowDecimal = Bytes2Int32(byte2); + //鍙嶅悜绱Н娴侀噺 + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589903863446638592, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data7.ToString() + SignId = "1589904635718668288", + SrcValue = (ReverseCumulativeFlowInteger + ReverseCumulativeFlowDecimal * 0.001).ToString() }); - //鍙嶅悜绱鐨勫皬鏁�/1000 - byte[] byte_data10 = new byte[2]; - Array.Copy(instrution_bts, 43, byte_data10, 0, 2); - var int_data10 = GetDouble1(byte_data10.Reverse().ToArray()); - - //娣诲姞灏忔暟 - int_data8 += int_data10; - list.Add(new Model.MonitorDataDockingReceiveRecord() + //姘磋〃鐢垫睜鐢甸噺 + Array.Copy(instrution_bts, 45, byte1, 0, 1); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589904635718668288, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data8.ToString() + SignId = "1589906693322575872", + SrcValue = Bytes2Int32(byte1).ToString() }); - //姘磋〃鐢垫睜鐢甸噺 - byte[] byte_data11 = new byte[1]; - Array.Copy(instrution_bts, 45, byte_data11, 0, 1); - var int_data11 = GetDouble1(byte_data11.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //GPRS鐢垫睜鐢甸噺 + Array.Copy(instrution_bts, 46, byte1, 0, 1); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589906693322575872, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data11.ToString() + SignId = "1589906830698614784", + SrcValue = Bytes2Int32(byte1).ToString() }); - //GPRS鐢垫睜鐢甸噺 - byte[] byte_data12 = new byte[1]; - Array.Copy(instrution_bts, 46, byte_data12, 0, 1); - var int_data12 = GetDouble1(byte_data12.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //绯荤粺鎶ヨ + Array.Copy(instrution_bts, 47, byte1, 0, 1); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589906830698614784, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data12.ToString() + SignId = "1589905499946618880", + SrcValue = Bytes2Int32(byte1).ToString() }); - //绯荤粺鎶ヨ - byte[] byte_data13 = new byte[1]; - Array.Copy(instrution_bts, 47, byte_data13, 0, 1); - var int_data13 = GetDouble1(byte_data13.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //姘磋〃绌虹鎶ヨ + Array.Copy(instrution_bts, 48, byte1, 0, 1); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589905499946618880, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data13.ToString() + SignId = "1589905855032201216", + SrcValue = Bytes2Int32(byte1).ToString() }); - //姘磋〃绌虹鎶ヨ - byte[] byte_data14 = new byte[1]; - Array.Copy(instrution_bts, 48, byte_data14, 0, 1); - var int_data14 = GetDouble1(byte_data14.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //鏂姳纾佹姤璀� + Array.Copy(instrution_bts, 49, byte1, 0, 1); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589905855032201216, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data14.ToString() + SignId = "1589905963715006464", + SrcValue = Bytes2Int32(byte1).ToString() }); - //鏂姳纾佹姤璀� - byte[] byte_data15 = new byte[1]; - Array.Copy(instrution_bts, 49, byte_data15, 0, 1); - var int_data15 = GetDouble1(byte_data15.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //娴侀噺涓婄嚎鎶ヨ + Array.Copy(instrution_bts, 50, byte1, 0, 1); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589905963715006464, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data15.ToString() + SignId = "1589906172004143104", + SrcValue = Bytes2Int32(byte1).ToString() }); - //娴侀噺涓婄嚎鎶ヨ - byte[] byte_data16 = new byte[1]; - Array.Copy(instrution_bts, 50, byte_data16, 0, 1); - var int_data16 = GetDouble1(byte_data16.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //娴侀噺涓嬬嚎鎶ヨ + Array.Copy(instrution_bts, 51, byte1, 0, 1); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589906172004143104, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data16.ToString() + SignId = "1589906236487372800", + SrcValue = Bytes2Int32(byte1).ToString() }); - //娴侀噺涓嬬嚎鎶ヨ - byte[] byte_data17 = new byte[1]; - Array.Copy(instrution_bts, 51, byte_data17, 0, 1); - var int_data17 = GetDouble1(byte_data17.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //鍘嬪姏涓婇檺鎶ヨ + Array.Copy(instrution_bts, 52, byte1, 0, 1); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589906236487372800, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data17.ToString() + SignId = "1589906299754254336", + SrcValue = Bytes2Int32(byte1).ToString() }); - //鍘嬪姏涓婇檺鎶ヨ - byte[] byte_data18 = new byte[1]; - Array.Copy(instrution_bts, 52, byte_data18, 0, 1); - var int_data18 = GetDouble1(byte_data18.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() + //鍘嬪姏涓嬮檺鎶ヨ + Array.Copy(instrution_bts, 53, byte1, 0, 1); + list.Add(new Model.MonitorDataDockingSrcRecord() { - SysId = 1589906299754254336, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data18.ToString() + SignId = "1589906389663354880", + SrcValue = Bytes2Int32(byte1).ToString() }); - - //鍘嬪姏涓嬮檺鎶ヨ - byte[] byte_data19 = new byte[1]; - Array.Copy(instrution_bts, 53, byte_data19, 0, 1); - var int_data19 = GetDouble1(byte_data19.Reverse().ToArray()); - list.Add(new Model.MonitorDataDockingReceiveRecord() - { - SysId = 1589906389663354880, - RecordType = Model.eMonitorType.General, - SrcTime = now, - SrcValue = int_data19.ToString() - });*/ return list; } - public static int bytesToInt4(byte[] src, int offset = 0) + public static int Bytes2Int4(byte[] src, int offset = 0) { + src = src.Reverse().ToArray(); int value; value = (int)(((src[offset] & 0xFF) << 24) | ((src[offset + 1] & 0xFF) << 16) @@ -247,6 +182,31 @@ return value; } + public static double Bytes2Double(byte[] value, int offset = 0) + { + return BitConverter.ToSingle(value.Reverse().ToArray(), 0);//閲囩敤浜咺EEE-754浜岃繘鍒舵诞鐐规暟绠楁湳鏍囧噯 + } + + public static int Bytes2Int32(byte[] bytes) + { + return Convert.ToInt32(Byte2HexStr(bytes.Reverse().ToArray()), 16); ; + } + + /// <summary> + /// byte[]杞负16杩涘埗瀛楃涓� + /// </summary> + public static string Byte2HexStr(byte[] bytes) + { + string returnStr = ""; + if (bytes != null) + { + for (int i = 0; i < bytes.Length; i++) + { + returnStr += bytes[i].ToString("X2"); + } + } + return returnStr; + } } } diff --git a/Socket/IStation.DataDockingSocket4SZJT_KT/MsgHelper.cs b/Socket/IStation.DataDockingSocket4SZJT_KT/helper/MsgHelper.cs similarity index 95% rename from Socket/IStation.DataDockingSocket4SZJT_KT/MsgHelper.cs rename to Socket/IStation.DataDockingSocket4SZJT_KT/helper/MsgHelper.cs index 920f2a4..b8af244 100644 --- a/Socket/IStation.DataDockingSocket4SZJT_KT/MsgHelper.cs +++ b/Socket/IStation.DataDockingSocket4SZJT_KT/helper/MsgHelper.cs @@ -4,10 +4,13 @@ using System.Text; using System.Threading.Tasks; -namespace IStation.DataDockingSocket +namespace IStation.DataDockingSocket.helper { + /// <summary> + /// 浣滃簾 + /// </summary> public class MsgHelper - { + { public bool Msg(string msg) { @@ -15,7 +18,7 @@ string error_info = null; var byteMessage = StringToHexValuve(strMsg, out error_info); if (byteMessage == null) - { + { return false; } @@ -27,7 +30,7 @@ private void AnaMsg(byte[] byteMessage) { - + if (byteMessage == null) return; if (byteMessage.Length < 70) @@ -44,7 +47,7 @@ return; if (byteMessage[8] != 0x0F) return; - + //GPRS妯″潡璇嗗埆鐮� byte[] byte_data1 = new byte[4]; Array.Copy(byteMessage, 9, byte_data1, 0, 4); @@ -70,7 +73,7 @@ RecordType = Model.eMonitorType.General, SrcTime = now, SrcValue = int_data4.ToString() - }) ; + }); //鐬椂鍘嬪姏锛孧pa byte[] byte_data5 = new byte[4]; @@ -85,7 +88,7 @@ }); //鐬椂娴侀�燂紝m3/h - byte[] byte_data6= new byte[4]; + byte[] byte_data6 = new byte[4]; Array.Copy(byteMessage, 29, byte_data6, 0, 4); var int_data6 = GetDouble1(byte_data6.Reverse().ToArray(), 0); list.Add(new Model.MonitorDataDockingReceiveRecord() @@ -163,7 +166,7 @@ //绯荤粺鎶ヨ byte[] byte_data13 = new byte[1]; Array.Copy(byteMessage, 47, byte_data13, 0, 1); - var int_data13= GetDouble1(byte_data13.Reverse().ToArray(), 0); + var int_data13 = GetDouble1(byte_data13.Reverse().ToArray(), 0); list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1589905499946618880, @@ -187,7 +190,7 @@ //鏂姳纾佹姤璀� byte[] byte_data15 = new byte[1]; Array.Copy(byteMessage, 49, byte_data15, 0, 1); - var int_data15= GetDouble1(byte_data15.Reverse().ToArray(), 0); + var int_data15 = GetDouble1(byte_data15.Reverse().ToArray(), 0); list.Add(new Model.MonitorDataDockingReceiveRecord() { SysId = 1589905963715006464, @@ -248,10 +251,10 @@ public static int bytesToInt4(byte[] src, int offset = 0) { int value; - value = (int)(((src[offset] & 0xFF) << 24) - | ((src[offset + 1] & 0xFF) << 16) - | ((src[offset + 2] & 0xFF) << 8) - | (src[offset + 3] & 0xFF)); + value = (src[offset] & 0xFF) << 24 + | (src[offset + 1] & 0xFF) << 16 + | (src[offset + 2] & 0xFF) << 8 + | src[offset + 3] & 0xFF; return value; } diff --git a/Socket/IStation.DataDockingSocket4SZJT_KT/instruction/SendInstructionJobHelper.cs b/Socket/IStation.DataDockingSocket4SZJT_KT/instruction/SendInstructionJobHelper.cs deleted file mode 100644 index a2215fc..0000000 --- a/Socket/IStation.DataDockingSocket4SZJT_KT/instruction/SendInstructionJobHelper.cs +++ /dev/null @@ -1,108 +0,0 @@ -锘縰sing Quartz; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using IStation.Untity; - -namespace IStation.DataDockingSocket -{ - /// <summary> - /// Modbus杈呭姪绫� - /// </summary> - public class SendInstructionJobHelper - { - private static IScheduler _sched;//璋冨害鍣� - - /// <summary> - /// 寮�濮嬩换鍔� - /// </summary> - public static async void StartJob(Model.IMonitorDataDockingSession session, InstructionItem item) - { - if (session == null) - return; - if (!session.IsConnected) - return; - if (item == null) - return; - if (string.IsNullOrEmpty(item.Instruction)) - return; - if (item.RuleItems == null || item.RuleItems.Count < 1) - return; - - SZJTKTLogHelper.Info($"{session.SessionName} 寮�濮嬪鐞嗗彂閫佹寚浠や换鍔★紝鎸囦护:{item.Instruction} !"); - - var jobName = SendInstructionJobNameHelper.GetJobName(session, item.Instruction); - var jobGroupName = SendInstructionJobNameHelper.GetJobGroupName(session, item.Instruction); - var triggerName = SendInstructionJobNameHelper.GetTriggerName(session, item.Instruction); - - //鍒ゆ柇鏄惁瀛樺湪 - if (_sched != null) - { - var triggerKey = new TriggerKey(triggerName, jobGroupName); - if (await _sched.CheckExists(triggerKey)) - { - SZJTKTLogHelper.Info($"{session.SessionName} 涓紝鎸囦护锛歿item.Instruction} 鐨勪富鍔ㄨ姹傛暟鎹换鍔″凡缁忓紑鍚紝鏃犻渶閲嶅寮�鍚紒"); - return; - } - } - - //鍒ゆ柇鏄惁寮�鍚皟鍙栧櫒 - if (_sched == null) - { - // 1.鍒涘缓scheduler鐨勫紩鐢� - var fac = new Quartz.Impl.StdSchedulerFactory(); - _sched = await fac.GetScheduler(); - - //2.鍚姩 scheduler - await _sched.Start(); - } - - //3.鍒涘缓浠诲姟 - var job = JobBuilder.Create<SendInstructionJob>() - .WithIdentity(jobName, jobGroupName) - .Build(); - job.JobDataMap.Put(SendInstructionJob.Session, session); - job.JobDataMap.Put(SendInstructionJob.Instruction, BitTransfer.FromString(item.Instruction)); - - //4.鍒涘缓Trigger - var trigger = TriggerBuilder.Create() - .WithIdentity(triggerName, jobGroupName) - .WithSimpleSchedule(x => x.WithIntervalInSeconds(item.Frequency).RepeatForever() - .WithMisfireHandlingInstructionNextWithRemainingCount()) - .Build(); - - //5.鍔犲叆璋冨害绠$悊鍣� - await _sched.ScheduleJob(job, trigger); - session.SessionClosedEvent += () => CancelJob(session, item.Instruction); - SZJTKTLogHelper.Info($"{session.SessionName} 涓紝鎸囦护:{item.Instruction} 鐨勪富鍔ㄨ姹傛暟鎹嚎绋嬪紑鍚垚鍔燂紒"); - } - - /// <summary> - /// 鍙栨秷浠诲姟 - /// </summary> - private static async void CancelJob(Model.IMonitorDataDockingSession session, string instruction) - { - if (_sched == null) - return; - SZJTKTLogHelper.Info($"{session.SessionName} 姝f墦绠楃粓姝富鍔ㄨ姹傛暟鎹换鍔�"); - var triggerName = SendInstructionJobNameHelper.GetTriggerName(session, instruction); - var jobGroupName = SendInstructionJobNameHelper.GetJobGroupName(session, instruction); - var triggerKey = new TriggerKey(triggerName, jobGroupName); - if (await _sched.CheckExists(triggerKey)) - { - await _sched.UnscheduleJob(triggerKey); - SZJTKTLogHelper.Info($"{session.SessionName},鎸囦护:{instruction} 涓诲姩璇锋眰鏁版嵁浠诲姟缁堟鎴愬姛"); - } - else - { - SZJTKTLogHelper.Info($"{session.SessionName},鎸囦护:{instruction} 涓诲姩璇锋眰鏁版嵁浠诲姟涓嶅瓨鍦�"); - } - } - - - - - } -} diff --git a/Socket/IStation.DataDockingSocket4SZJT_KT/paras/AppParas.cs b/Socket/IStation.DataDockingSocket4SZJT_KT/paras/AppParas.cs index b453ee8..a422517 100644 --- a/Socket/IStation.DataDockingSocket4SZJT_KT/paras/AppParas.cs +++ b/Socket/IStation.DataDockingSocket4SZJT_KT/paras/AppParas.cs @@ -8,22 +8,30 @@ namespace IStation.DataDockingSocket { - /// <summary> /// app鍙傛暟锛堝彲閰嶅埗锛� /// </summary> public class AppParas - { - + { /// <summary> /// 鎸囦护鍙戦�侀棿闅� /// </summary> public int InstructionSendSpace { get; set; } /// <summary> - /// 鎸囦护椤瑰垪琛� + /// 鍓嶇紑 /// </summary> - public List<InstructionItem> InstructionItems { get; set; } + public string Prefix { get; set; } + + /// <summary> + /// 鍓嶇紑 + /// </summary> + public string ProductID { get; set; } + + /// <summary> + /// 杩斿洖鎸囦护 + /// </summary> + public string ReturnInstruction { get; set; } /// <summary> /// 鏄惁淇濆瓨鍘熷 @@ -35,138 +43,6 @@ /// </summary> public bool Debug { get; set; } - /// <summary> - /// 楠岃瘉 - /// </summary> - public static bool Verify(byte[] bts) - { - if (bts == null) - return default; - if (bts.Length < 8) - return false; - if (!ModBusRtuHelper.CheckReceivedMessage(bts)) - return false; - return true; - } - } - - /// <summary> - /// 瑙f瀽瑙勫垯鏋氫妇 - /// </summary> - public enum eRule - { - /// <summary> - /// 涓や釜瀛楄妭涓轰竴缁勶紝涓ょ粍琛ㄧず涓�涓暟鎹紝閫氳繃寰楀埌鐨勫洓涓瓧鑺傚弽杞悗锛孊itConvert.Single()鑾峰彇鍊� - /// </summary> - [Display(Name = "鍙屽瓧瑙f瀽涓烘诞鐐规暟", Description = "鍙屽瓧瑙f瀽涓烘诞鐐规暟 ")] - Float = 1, - - /// <summary> - /// 涓や釜瀛楄妭琛ㄧず涓�涓暣鏁板�硷紝閫氳繃寰楀埌鐨�2涓瓧鑺傚弽杞悗锛孊itConvert.ToInt16()鑾峰彇鍊� - /// </summary> - [Display(Name = "鍗曞瓧瑙f瀽涓烘暣鏁�", Description = "鍗曞瓧琛ㄧず涓�涓暣鏁板��")] - Short = 2, - - /// <summary> - /// 涓や釜瀛楄妭涓轰竴缁勶紝涓ょ粍琛ㄧず涓�涓暟鎹紝閫氳繃寰楀埌鐨勫洓涓瓧鑺傚弽杞悗锛孊itConverter.ToInt32();鑾峰彇鍊� - /// </summary> - [Display(Name = "鍙屽瓧瑙f瀽涓烘暣鏁�", Description = "鍙屽瓧琛ㄧず涓�涓暣鏁板��")] - Int = 3, - } - - /// <summary> - /// 瑙f瀽椤� - /// </summary> - public class RuleItem - { - /// <summary> - /// 鏍囪鏍囪瘑 - /// </summary> - public string SignId { get; set; } - - /// <summary> - /// 绱㈠紩 浠�1寮�濮� - /// </summary> - public int Index { get; set; } - - /// <summary> - /// 瑙f瀽瑙勫垯 - /// </summary> - public eRule? Rule { get; set; } - } - - /// <summary> - /// 鎸囦护椤� - /// </summary> - public class InstructionItem - { - /// <summary> - /// 鎸囦护 - /// </summary> - public string Instruction { get; set; } - - /// <summary> - /// 鎸囦护鍙戦�侀鐜� 绉� - /// </summary> - public int Frequency { get; set; } - - /// <summary> - /// 榛樿瑙f瀽瑙勫垯 - /// </summary> - public eRule DefaultRule { get; set; } - - /// <summary> - /// 瑙f瀽椤� - /// </summary> - public List<RuleItem> RuleItems { get; set; } - - /// <summary> - /// 楠岃瘉 - /// </summary> - public bool Verify(byte[] bts) - { - if (bts == null) - return default; - if (bts.Length < 6) - return false; - if (bts.Length - 5 != bts[2]) - return false; - if (string.IsNullOrEmpty(this.Instruction)) - return default; - - var instruction = BitTransfer.FromString(this.Instruction); - if (bts[0] == instruction[0]) - { - if (bts[1] == instruction[1]) - { - //璇锋眰鐨勬暟鎹瓧鑺傛暟閲� - var requestDataCount = BitConverter.ToInt16(instruction.Skip(4).Take(2).Reverse().ToArray(), 0) * 2; - if (requestDataCount == bts[2]) - { - return true; - } - } - } - return default; - } - } - - - /// <summary> - /// 鎸囦护瑙勫垯 - /// </summary> - public class DirectiveRules - { - /// <summary> - /// 鍓嶇紑 - /// </summary> - public string Prefix { get; set; } - - /// <summary> - /// GPRS 妯″潡璇嗗埆鐮� - /// </summary> - public string ProductID { get; set; } - } - + } diff --git a/Socket/IStation.DataDockingSocket4SZJT_KT/paras_datadocking_socket_szjt_kt.json b/Socket/IStation.DataDockingSocket4SZJT_KT/paras_datadocking_socket_szjt_kt.json index 3930cb2..eea486f 100644 --- a/Socket/IStation.DataDockingSocket4SZJT_KT/paras_datadocking_socket_szjt_kt.json +++ b/Socket/IStation.DataDockingSocket4SZJT_KT/paras_datadocking_socket_szjt_kt.json @@ -1,209 +1,8 @@ { "InstructionSendSpace": 10, - "InstructionItems": [ - { - "Instruction": "01-03-00-00-00-64-44-21", - "Frequency": 60, - "DefaultRule": 2, - "RuleItems": [ - { - "SignId": "kq_1_30", - "Index": 30, - "Rule": 1 - }, - { - "SignId": "kq_1_32", - "Index": 32, - "Rule": 3 - }, - { - "SignId": "kq_1_58", - "Index": 58, - "Rule": 2 - }, - { - "SignId": "kq_1_59", - "Index": 59, - "Rule": 2 - }, - { - "SignId": "kq_1_60", - "Index": 60, - "Rule": 2 - }, - { - "SignId": "kq_1_61", - "Index": 61, - "Rule": 2 - }, - { - "SignId": "kq_1_62", - "Index": 62, - "Rule": 2 - }, - { - "SignId": "kq_1_63", - "Index": 63, - "Rule": 2 - }, - { - "SignId": "kq_1_66", - "Index": 66, - "Rule": 2 - }, - { - "SignId": "kq_1_80", - "Index": 80, - "Rule": 2 - }, - { - "SignId": "kq_1_81", - "Index": 81, - "Rule": 2 - }, - { - "SignId": "kq_1_90", - "Index": 90, - "Rule": 2 - }, - { - "SignId": "kq_1_91", - "Index": 91, - "Rule": 2 - }, - { - "SignId": "kq_1_92", - "Index": 92, - "Rule": 2 - }, - { - "SignId": "kq_1_93", - "Index": 93, - "Rule": 2 - }, - { - "SignId": "kq_1_94", - "Index": 94, - "Rule": 2 - }, - { - "SignId": "kq_1_95", - "Index": 95, - "Rule": 2 - }, - { - "SignId": "kq_1_97", - "Index": 97, - "Rule": 3 - } - ] - }, - { - "Instruction": "01-03-00-64-00-63-44-3C", - "Frequency": 60, - "DefaultRule": 2, - "RuleItems": [ - { - "SignId": "kq_2_124", - "Index": 124, - "Rule": 2 - }, - { - "SignId": "kq_2_102", - "Index": 102, - "Rule": 2 - }, - { - "SignId": "kq_2_111", - "Index": 111, - "Rule": 2 - }, - { - "SignId": "kq_2_122", - "Index": 122, - "Rule": 2 - }, - { - "SignId": "kq_2_123", - "Index": 123, - "Rule": 2 - }, - { - "SignId": "kq_2_125", - "Index": 125, - "Rule": 2 - }, - { - "SignId": "kq_2_131", - "Index": 131, - "Rule": 2 - }, - { - "SignId": "kq_2_138", - "Index": 138, - "Rule": 2 - }, - { - "SignId": "kq_2_140", - "Index": 140, - "Rule": 2 - }, - { - "SignId": "kq_2_167", - "Index": 167, - "Rule": 2 - }, - { - "SignId": "kq_2_168", - "Index": 168, - "Rule": 2 - }, - { - "SignId": "kq_2_132", - "Index": 132, - "Rule": 2 - }, - { - "SignId": "kq_2_148", - "Index": 148, - "Rule": 2 - }, - { - "SignId": "kq_2_133", - "Index": 133, - "Rule": 2 - }, - { - "SignId": "kq_2_149", - "Index": 149, - "Rule": 2 - }, - { - "SignId": "kq_2_134", - "Index": 134, - "Rule": 2 - }, - { - "SignId": "kq_2_150", - "Index": 150, - "Rule": 2 - }, - { - "SignId": "kq_2_135", - "Index": 135, - "Rule": 2 - }, - { - "SignId": "kq_2_151", - "Index": 151, - "Rule": 2 - } - ] - } - ], - "Encoder": { - "Success": "OK" - }, + "ReturnInstruction": "OK", + "Prefix": "AT+Data=", + "ProductID": "10001313", "Debug": true, "Src": true } diff --git a/Socket/IStation.DataDockingSocket4SZZS/HandleHelper.cs b/Socket/IStation.DataDockingSocket4SZZS/HandleHelper.cs index 96e11e8..962b588 100644 --- a/Socket/IStation.DataDockingSocket4SZZS/HandleHelper.cs +++ b/Socket/IStation.DataDockingSocket4SZZS/HandleHelper.cs @@ -118,10 +118,10 @@ } - - - - - + public bool Valid(byte[] bytes) + { + return false; + } + } } diff --git a/Socket/IStation.IDataDockingSocket/IHandleHelper.cs b/Socket/IStation.IDataDockingSocket/IHandleHelper.cs index 428dba4..ddbf58e 100644 --- a/Socket/IStation.IDataDockingSocket/IHandleHelper.cs +++ b/Socket/IStation.IDataDockingSocket/IHandleHelper.cs @@ -10,6 +10,11 @@ public interface IHandleHelper { /// <summary> + /// 楠岃瘉鏁版嵁 + /// </summary> + bool Valid(byte[] bytes); + + /// <summary> /// 澶勭悊娉ㄥ唽鍖� /// </summary> void HandleRegisterCode(IMonitorDataDockingSession session); @@ -24,9 +29,9 @@ /// </summary> void HandleData ( - IMonitorDataDockingSession session, + IMonitorDataDockingSession session, byte[] bytes, - List<DataDockingConfigure.Mapper> mappers, + List<DataDockingConfigure.Mapper> mappers, Action<List<MonitorDataDockingReceiveRecord>> receive ); } diff --git a/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/IStation.TopShelf.DataDocking.Socket.Custom.csproj b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/IStation.TopShelf.DataDocking.Socket.Custom.csproj new file mode 100644 index 0000000..9328a87 --- /dev/null +++ b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/IStation.TopShelf.DataDocking.Socket.Custom.csproj @@ -0,0 +1,17 @@ +锘�<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + <AssemblyName>IStation.TopShelf.DataDocking.Socket.Custom</AssemblyName> + <RootNamespace>IStation.TopShelf</RootNamespace> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\..\Component\IStation.TopShelf\IStation.TopShelf.csproj" /> + <ProjectReference Include="..\..\Server\IStation.DataDocking.Socket.Custom\IStation.DataDocking.Socket.Custom.csproj" /> + </ItemGroup> + +</Project> diff --git a/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Program.cs b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Program.cs new file mode 100644 index 0000000..1c76a6c --- /dev/null +++ b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Program.cs @@ -0,0 +1,15 @@ +锘�// See https://aka.ms/new-console-template for more information + +using IStation.TopShelf; +using Topshelf; + +HostFactory.Run(x => +{ + x.Service<Service>(); + x.RunAsLocalSystem(); + x.SetDescription("鏅烘収娉电珯Core鐗圫ocket瀵规帴绋嬪簭"); + x.SetDisplayName("IStation.Core.DataDocking.Socket.Custom"); + x.SetServiceName("IStation.Core.DataDocking.Socket.Custom"); + x.EnableServiceRecovery(r => r.RestartService(TimeSpan.FromSeconds(120))); + x.StartAutomatically(); +}); diff --git a/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Properties/PublishProfiles/FolderProfile.pubxml b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..639934f --- /dev/null +++ b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,12 @@ +锘�<?xml version="1.0" encoding="utf-8"?> +<!-- +https://go.microsoft.com/fwlink/?LinkID=208121. +--> +<Project> + <PropertyGroup> + <Configuration>Release</Configuration> + <Platform>Any CPU</Platform> + <PublishDir>bin\Release\net6.0\publish\</PublishDir> + <PublishProtocol>FileSystem</PublishProtocol> + </PropertyGroup> +</Project> \ No newline at end of file diff --git a/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Properties/PublishProfiles/FolderProfile.pubxml.user b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Properties/PublishProfiles/FolderProfile.pubxml.user new file mode 100644 index 0000000..b660ff4 --- /dev/null +++ b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -0,0 +1,10 @@ +锘�<?xml version="1.0" encoding="utf-8"?> +<!-- +https://go.microsoft.com/fwlink/?LinkID=208121. +--> +<Project> + <PropertyGroup> + <History>True|2022-11-07T06:19:02.7595787Z;True|2022-11-07T14:16:18.9629209+08:00;True|2022-11-07T14:10:58.7927593+08:00;True|2022-11-07T13:40:15.7710087+08:00;True|2022-11-04T10:51:31.2128411+08:00;True|2022-11-04T10:50:48.9390883+08:00;False|2022-11-04T10:45:25.5349335+08:00;False|2022-11-04T10:38:09.7881861+08:00;False|2022-11-04T10:32:57.3163779+08:00;True|2022-10-31T13:50:19.2799744+08:00;True|2022-10-28T18:12:41.9095520+08:00;True|2022-10-28T15:43:16.2950292+08:00;True|2022-10-28T15:41:52.2233941+08:00;True|2022-10-28T15:30:14.2215199+08:00;True|2022-10-28T11:51:16.0785196+08:00;True|2022-10-28T11:44:51.8315664+08:00;True|2022-10-28T10:33:52.2698494+08:00;True|2022-10-28T09:35:47.1875028+08:00;True|2022-10-28T09:10:26.0008427+08:00;True|2022-10-27T18:39:24.9534804+08:00;True|2022-10-27T18:33:34.4681116+08:00;True|2022-10-27T18:13:21.7875951+08:00;True|2022-10-27T18:12:44.3890244+08:00;True|2022-10-27T18:07:26.1755739+08:00;True|2022-10-27T17:57:58.0347320+08:00;True|2022-10-27T17:34:58.8259465+08:00;True|2022-10-27T17:22:06.3154634+08:00;False|2022-10-27T17:20:19.9004059+08:00;True|2022-10-27T17:18:10.4716763+08:00;True|2022-10-27T17:05:00.4099257+08:00;True|2022-10-27T16:54:07.3727699+08:00;True|2022-10-27T16:42:08.7868428+08:00;True|2022-10-27T16:20:40.9187590+08:00;True|2022-10-27T16:15:48.8887876+08:00;True|2022-10-27T15:32:23.6326778+08:00;True|2022-10-27T15:31:21.2898598+08:00;True|2022-10-27T15:31:06.9752171+08:00;True|2022-10-27T15:30:12.3351290+08:00;True|2022-10-27T15:16:06.6376480+08:00;True|2022-10-27T15:04:16.6181644+08:00;True|2022-10-27T14:56:07.3371453+08:00;True|2022-10-27T14:55:40.9994920+08:00;True|2022-10-26T14:21:13.7358061+08:00;True|2022-10-26T13:58:17.8518712+08:00;True|2022-10-26T10:50:57.8305616+08:00;True|2022-10-26T10:41:24.0512951+08:00;True|2022-10-26T10:36:18.9669938+08:00;True|2022-10-26T10:23:42.5700603+08:00;True|2022-10-26T09:49:18.1242267+08:00;True|2022-10-24T17:44:25.5039390+08:00;True|2022-07-02T00:06:16.6338790+08:00;True|2022-07-02T00:02:49.1000053+08:00;True|2022-07-01T23:23:53.1924783+08:00;True|2022-07-01T14:02:38.1190102+08:00;True|2022-07-01T13:55:33.4591108+08:00;</History> + <LastFailureDetails /> + </PropertyGroup> +</Project> \ No newline at end of file diff --git a/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Service.cs b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Service.cs new file mode 100644 index 0000000..2f732b9 --- /dev/null +++ b/TopShelf/IStation.TopShelf.DataDocking.Socket.Custom/Service.cs @@ -0,0 +1,40 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Topshelf; +using IStation.Server; + +namespace IStation.TopShelf +{ + /// <summary> + /// + /// </summary> + public class Service : ServiceControl + { + private readonly SocketJobHelper _jobHelper = new SocketJobHelper(); + + /// <summary> + /// + /// </summary> + public bool Start(HostControl hostControl) + { + LogHelper.Info("寮�濮�"); + _ = _jobHelper.StartJob(); + return true; + } + + /// <summary> + /// + /// </summary> + public bool Stop(HostControl hostControl) + { + LogHelper.Info("缁撴潫"); + _ = _jobHelper.CancelJob(); + return true; + } + + + } +} diff --git a/TopShelf/IStation.TopShelf.DataDocking4Socket/Properties/PublishProfiles/FolderProfile.pubxml.user b/TopShelf/IStation.TopShelf.DataDocking4Socket/Properties/PublishProfiles/FolderProfile.pubxml.user index b660ff4..bbe0b59 100644 --- a/TopShelf/IStation.TopShelf.DataDocking4Socket/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/TopShelf/IStation.TopShelf.DataDocking4Socket/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -4,7 +4,7 @@ --> <Project> <PropertyGroup> - <History>True|2022-11-07T06:19:02.7595787Z;True|2022-11-07T14:16:18.9629209+08:00;True|2022-11-07T14:10:58.7927593+08:00;True|2022-11-07T13:40:15.7710087+08:00;True|2022-11-04T10:51:31.2128411+08:00;True|2022-11-04T10:50:48.9390883+08:00;False|2022-11-04T10:45:25.5349335+08:00;False|2022-11-04T10:38:09.7881861+08:00;False|2022-11-04T10:32:57.3163779+08:00;True|2022-10-31T13:50:19.2799744+08:00;True|2022-10-28T18:12:41.9095520+08:00;True|2022-10-28T15:43:16.2950292+08:00;True|2022-10-28T15:41:52.2233941+08:00;True|2022-10-28T15:30:14.2215199+08:00;True|2022-10-28T11:51:16.0785196+08:00;True|2022-10-28T11:44:51.8315664+08:00;True|2022-10-28T10:33:52.2698494+08:00;True|2022-10-28T09:35:47.1875028+08:00;True|2022-10-28T09:10:26.0008427+08:00;True|2022-10-27T18:39:24.9534804+08:00;True|2022-10-27T18:33:34.4681116+08:00;True|2022-10-27T18:13:21.7875951+08:00;True|2022-10-27T18:12:44.3890244+08:00;True|2022-10-27T18:07:26.1755739+08:00;True|2022-10-27T17:57:58.0347320+08:00;True|2022-10-27T17:34:58.8259465+08:00;True|2022-10-27T17:22:06.3154634+08:00;False|2022-10-27T17:20:19.9004059+08:00;True|2022-10-27T17:18:10.4716763+08:00;True|2022-10-27T17:05:00.4099257+08:00;True|2022-10-27T16:54:07.3727699+08:00;True|2022-10-27T16:42:08.7868428+08:00;True|2022-10-27T16:20:40.9187590+08:00;True|2022-10-27T16:15:48.8887876+08:00;True|2022-10-27T15:32:23.6326778+08:00;True|2022-10-27T15:31:21.2898598+08:00;True|2022-10-27T15:31:06.9752171+08:00;True|2022-10-27T15:30:12.3351290+08:00;True|2022-10-27T15:16:06.6376480+08:00;True|2022-10-27T15:04:16.6181644+08:00;True|2022-10-27T14:56:07.3371453+08:00;True|2022-10-27T14:55:40.9994920+08:00;True|2022-10-26T14:21:13.7358061+08:00;True|2022-10-26T13:58:17.8518712+08:00;True|2022-10-26T10:50:57.8305616+08:00;True|2022-10-26T10:41:24.0512951+08:00;True|2022-10-26T10:36:18.9669938+08:00;True|2022-10-26T10:23:42.5700603+08:00;True|2022-10-26T09:49:18.1242267+08:00;True|2022-10-24T17:44:25.5039390+08:00;True|2022-07-02T00:06:16.6338790+08:00;True|2022-07-02T00:02:49.1000053+08:00;True|2022-07-01T23:23:53.1924783+08:00;True|2022-07-01T14:02:38.1190102+08:00;True|2022-07-01T13:55:33.4591108+08:00;</History> + <History>True|2022-11-18T09:16:08.2357388Z;True|2022-11-18T17:10:16.7111998+08:00;True|2022-11-18T17:04:10.5678845+08:00;True|2022-11-18T17:01:48.4283015+08:00;True|2022-11-18T16:52:07.1424550+08:00;True|2022-11-07T14:19:02.7595787+08:00;True|2022-11-07T14:16:18.9629209+08:00;True|2022-11-07T14:10:58.7927593+08:00;True|2022-11-07T13:40:15.7710087+08:00;True|2022-11-04T10:51:31.2128411+08:00;True|2022-11-04T10:50:48.9390883+08:00;False|2022-11-04T10:45:25.5349335+08:00;False|2022-11-04T10:38:09.7881861+08:00;False|2022-11-04T10:32:57.3163779+08:00;True|2022-10-31T13:50:19.2799744+08:00;True|2022-10-28T18:12:41.9095520+08:00;True|2022-10-28T15:43:16.2950292+08:00;True|2022-10-28T15:41:52.2233941+08:00;True|2022-10-28T15:30:14.2215199+08:00;True|2022-10-28T11:51:16.0785196+08:00;True|2022-10-28T11:44:51.8315664+08:00;True|2022-10-28T10:33:52.2698494+08:00;True|2022-10-28T09:35:47.1875028+08:00;True|2022-10-28T09:10:26.0008427+08:00;True|2022-10-27T18:39:24.9534804+08:00;True|2022-10-27T18:33:34.4681116+08:00;True|2022-10-27T18:13:21.7875951+08:00;True|2022-10-27T18:12:44.3890244+08:00;True|2022-10-27T18:07:26.1755739+08:00;True|2022-10-27T17:57:58.0347320+08:00;True|2022-10-27T17:34:58.8259465+08:00;True|2022-10-27T17:22:06.3154634+08:00;False|2022-10-27T17:20:19.9004059+08:00;True|2022-10-27T17:18:10.4716763+08:00;True|2022-10-27T17:05:00.4099257+08:00;True|2022-10-27T16:54:07.3727699+08:00;True|2022-10-27T16:42:08.7868428+08:00;True|2022-10-27T16:20:40.9187590+08:00;True|2022-10-27T16:15:48.8887876+08:00;True|2022-10-27T15:32:23.6326778+08:00;True|2022-10-27T15:31:21.2898598+08:00;True|2022-10-27T15:31:06.9752171+08:00;True|2022-10-27T15:30:12.3351290+08:00;True|2022-10-27T15:16:06.6376480+08:00;True|2022-10-27T15:04:16.6181644+08:00;True|2022-10-27T14:56:07.3371453+08:00;True|2022-10-27T14:55:40.9994920+08:00;True|2022-10-26T14:21:13.7358061+08:00;True|2022-10-26T13:58:17.8518712+08:00;True|2022-10-26T10:50:57.8305616+08:00;True|2022-10-26T10:41:24.0512951+08:00;True|2022-10-26T10:36:18.9669938+08:00;True|2022-10-26T10:23:42.5700603+08:00;True|2022-10-26T09:49:18.1242267+08:00;True|2022-10-24T17:44:25.5039390+08:00;True|2022-07-02T00:06:16.6338790+08:00;True|2022-07-02T00:02:49.1000053+08:00;True|2022-07-01T23:23:53.1924783+08:00;True|2022-07-01T14:02:38.1190102+08:00;True|2022-07-01T13:55:33.4591108+08:00;</History> <LastFailureDetails /> </PropertyGroup> </Project> \ No newline at end of file -- Gitblit v1.9.3