Browse Source

1. 异常CORE中的REDIS
2. 新增 扩展工具 Redis
3. 修改RPC扩展工具细节

Shun 2 years ago
parent
commit
43d263a1a7

+ 6 - 1
README.md

@@ -484,4 +484,9 @@ while(true)
 
 #### 2023-11-21
 1. 新增基于DotNetty实现的RPC(远程过程调用) 支持一对多,支持身份验证
-2. RabbitMQ 依赖库更新
+2. RabbitMQ 依赖库更新
+
+#### 2023-11-23
+1. 异常CORE中的REDIS
+2. 新增 扩展工具 Redis
+3. 修改RPC扩展工具细节

+ 2 - 3
src/YSAI.Core/YSAI.Core.csproj

@@ -3,7 +3,7 @@
     <TargetFrameworks>net6.0;net8.0</TargetFrameworks>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
-    <Version>23.320.34643</Version>
+    <Version>23.327.10601</Version>
     <PackageOutputPath Condition="'$(Configuration)' == 'Release'">../YSAI.Publish/Release</PackageOutputPath>
     <PackageOutputPath Condition="'$(Configuration)' == 'Debug'">../YSAI.Publish/Debug</PackageOutputPath>
     <Authors>Shun</Authors>
@@ -12,11 +12,10 @@
     <GenerateDocumentationFile>True</GenerateDocumentationFile>
     <DescriptionType>核心组件</DescriptionType>
     <DescriptionName>Core</DescriptionName>
-    <DescriptionDetails>特性、数据结构、处理、接口、Redis、反射、脚本、订阅、虚拟地址、TCP、UDP、HTTP、WS、串口</DescriptionDetails>
+    <DescriptionDetails>特性、数据结构、处理、接口、反射、脚本、订阅、虚拟地址、TCP、UDP、HTTP、WS、串口</DescriptionDetails>
     <Description>$(DescriptionType):$(DescriptionName) ( $(DescriptionDetails) )</Description>
   </PropertyGroup>
   <ItemGroup>
-    <PackageReference Include="StackExchange.Redis" Version="2.7.4" />
     <PackageReference Include="Microsoft.ClearScript" Version="7.4.4" />
     <PackageReference Include="System.IO.Ports" Version="8.0.0" />
     <PackageReference Include="YSAI.Log" Version="23.319.17368" />

+ 0 - 26
src/YSAI.Core/redis/RedisData.cs

@@ -1,26 +0,0 @@
-namespace YSAI.Core.redis
-{
-    public class RedisData
-    {
-        /// <summary>
-        /// 基础数据
-        /// </summary>
-        public class Basics
-        {
-            /// <summary>
-            /// 连接字符串
-            /// </summary>
-            public string ConnectStr { get; set; }
-
-            /// <summary>
-            /// 前缀
-            /// </summary>
-            public string Prefix { get; set; } = "YSAI:";
-
-            /// <summary>
-            /// 选择的数据库
-            /// </summary>
-            public int SelectDB { get; set; } = 0;
-        }
-    }
-}

File diff suppressed because it is too large
+ 0 - 1965
src/YSAI.Core/redis/RedisOperate.cs


+ 9 - 2
src/YSAI.DAQ.sln

@@ -127,9 +127,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "extend", "extend", "{F23C35
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YSAI.Rpc", "YSAI.Rpc\YSAI.Rpc.csproj", "{87606DDA-82DA-4BCD-87B3-E7CEFB05EADC}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YSAI.Test.RPC.Server", "YSAI.Test.RPC.Server\YSAI.Test.RPC.Server.csproj", "{30AB5928-8D59-4D35-8866-D42EF3273433}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YSAI.Test.RPC.Server", "YSAI.Test.RPC.Server\YSAI.Test.RPC.Server.csproj", "{30AB5928-8D59-4D35-8866-D42EF3273433}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YSAI.Test.RPC.Client", "YSAI.Test.RPC.Client\YSAI.Test.RPC.Client.csproj", "{E3F6DC4A-57F4-436F-86C5-6B2F782AA2C9}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YSAI.Test.RPC.Client", "YSAI.Test.RPC.Client\YSAI.Test.RPC.Client.csproj", "{E3F6DC4A-57F4-436F-86C5-6B2F782AA2C9}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YSAI.Redis", "YSAI.Redis\YSAI.Redis.csproj", "{F917D5C2-A067-47F3-8E18-1CD2C95FEC29}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -353,6 +355,10 @@ Global
 		{E3F6DC4A-57F4-436F-86C5-6B2F782AA2C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{E3F6DC4A-57F4-436F-86C5-6B2F782AA2C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{E3F6DC4A-57F4-436F-86C5-6B2F782AA2C9}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F917D5C2-A067-47F3-8E18-1CD2C95FEC29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F917D5C2-A067-47F3-8E18-1CD2C95FEC29}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F917D5C2-A067-47F3-8E18-1CD2C95FEC29}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F917D5C2-A067-47F3-8E18-1CD2C95FEC29}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -417,6 +423,7 @@ Global
 		{87606DDA-82DA-4BCD-87B3-E7CEFB05EADC} = {F23C3553-3FE7-4ECC-9BBA-8C498C3B4398}
 		{30AB5928-8D59-4D35-8866-D42EF3273433} = {12CB0510-7B1E-4518-AA3B-412A4D323D42}
 		{E3F6DC4A-57F4-436F-86C5-6B2F782AA2C9} = {12CB0510-7B1E-4518-AA3B-412A4D323D42}
+		{F917D5C2-A067-47F3-8E18-1CD2C95FEC29} = {F23C3553-3FE7-4ECC-9BBA-8C498C3B4398}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {5D5D3927-6714-40C0-84EA-44C5BA4C5E87}

+ 9 - 0
src/YSAI.Redis/IRedis.cs

@@ -0,0 +1,9 @@
+using YSAI.Core.@interface;
+
+namespace YSAI.Redis
+{
+    /// <summary>
+    /// 接口
+    /// </summary>
+    public interface IRedis : IOn, IOff, IGetStatus, IDisposable { }
+}

+ 32 - 0
src/YSAI.Redis/RedisData.cs

@@ -0,0 +1,32 @@
+namespace YSAI.Redis
+{
+    public class RedisData
+    {
+        /// <summary>
+        /// 基础数据
+        /// </summary>
+        public class Basics
+        {
+            /// <summary>
+            /// 标识 前缀
+            /// </summary>
+            public string TAG { get; set; } = "S:";
+            /// <summary>
+            /// 使用标识前缀
+            /// </summary>
+            public bool UseTAG { get; set; } = true;
+            /// <summary>
+            /// 连接字符串
+            /// </summary>
+            public string CStr { get; set; }
+            /// <summary>
+            /// 选择的数据
+            /// </summary>
+            public int DBI { get; set; } = 0;
+            /// <summary>
+            /// 有效时间 ms
+            /// </summary>
+            public int Expiry { get; set; } = 86400000;
+        }
+    }
+}

File diff suppressed because it is too large
+ 1721 - 0
src/YSAI.Redis/RedisOperate.cs


+ 22 - 0
src/YSAI.Redis/YSAI.Redis.csproj

@@ -0,0 +1,22 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <TargetFrameworks>net6.0;net8.0</TargetFrameworks>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+    <Version>23.327.10475</Version>
+    <PackageOutputPath Condition="'$(Configuration)' == 'Release'">../YSAI.Publish/Release</PackageOutputPath>
+    <PackageOutputPath Condition="'$(Configuration)' == 'Debug'">../YSAI.Publish/Debug</PackageOutputPath>
+    <Authors>Shun</Authors>
+    <Company>YSAI</Company>
+    <Product>SCADA</Product>
+    <GenerateDocumentationFile>True</GenerateDocumentationFile>
+    <DescriptionType>扩展工具</DescriptionType>
+    <DescriptionName>Redis</DescriptionName>
+    <DescriptionDetails>非关系型数据库,用于数据快速出站入站存储</DescriptionDetails>
+    <Description>$(DescriptionType):$(DescriptionName) ( $(DescriptionDetails) )</Description>
+  </PropertyGroup>
+  <ItemGroup>
+    <PackageReference Include="StackExchange.Redis" Version="2.7.4" />
+    <PackageReference Include="YSAI.Core" Version="23.320.34643" />
+  </ItemGroup>
+</Project>

+ 3 - 3
src/YSAI.Rpc/client/RpcClient.cs

@@ -11,7 +11,6 @@ using System.Reflection;
 using System.Text;
 using YSAI.Core.data;
 using YSAI.Core.@interface;
-using YSAI.Log;
 using YSAI.Rpc.data;
 using YSAI.Rpc.@interface;
 using YSAI.Rpc.unility;
@@ -22,7 +21,7 @@ namespace YSAI.Rpc.client
     /// <summary>
     /// RPC客户端
     /// </summary>
-    public class RpcClient : IOrAbstract, IRpc
+    public class RpcClient : IBaseAbstract, IRpc
     {
         protected override string TAG => "RpcClient";
 
@@ -191,6 +190,7 @@ namespace YSAI.Rpc.client
                 //代理
                 Proxy proxy = Proxy.Instance(new ProxyData.Basics
                 {
+                    Main = this,
                     Await = Await,
                     channel = Channel,
                     iName = iname,
@@ -297,7 +297,7 @@ namespace YSAI.Rpc.client
         }
         public void Exception(Exception ex)
         {
-            LogHelper.Error(ex.Message, $"{TAG}.log", ex);
+            OnEventHandler(this, new EventResult(false, ex.Message, ex, Core.@enum.ResultType.Object));
             Dispose();
         }
 

+ 4 - 0
src/YSAI.Rpc/data/ProxyData.cs

@@ -13,6 +13,10 @@ namespace YSAI.Rpc.data
         /// </summary>
         public class Basics
         {
+            /// <summary>
+            /// 控制端对象
+            /// </summary>
+            public object Main { get; set; }
             /// <summary>
             /// 通道
             /// </summary>

+ 3 - 3
src/YSAI.Rpc/service/RpcService.cs

@@ -10,7 +10,6 @@ using System.Reflection;
 using System.Text;
 using YSAI.Core.data;
 using YSAI.Core.@interface;
-using YSAI.Log;
 using YSAI.Rpc.data;
 using YSAI.Rpc.@interface;
 using YSAI.Rpc.unility;
@@ -21,7 +20,7 @@ namespace YSAI.Rpc.service
     /// <summary>
     /// RPC服务端
     /// </summary>
-    public class RpcService : IOrAbstract, IRpc
+    public class RpcService : IBaseAbstract, IRpc
     {
         protected override string TAG => "RpcService";
 
@@ -192,6 +191,7 @@ namespace YSAI.Rpc.service
 
                 Proxy proxy = Proxy.Instance(new ProxyData.Basics
                 {
+                    Main = this,
                     Await = Await,
                     channel = channel,
                     iName = iname,
@@ -353,7 +353,7 @@ namespace YSAI.Rpc.service
 
         public void Exception(Exception ex)
         {
-            LogHelper.Error(ex.Message, $"{TAG}.log", ex, false);
+            OnEventHandler(this, new EventResult(false, ex.Message, ex, Core.@enum.ResultType.Object));
         }
 
         public void Dispose()

+ 29 - 8
src/YSAI.Rpc/unility/Proxy.cs

@@ -2,7 +2,9 @@
 using Newtonsoft.Json;
 using System.Dynamic;
 using System.Text;
+using YSAI.Rpc.client;
 using YSAI.Rpc.data;
+using YSAI.Rpc.service;
 using YSAI.Unility;
 
 namespace YSAI.Rpc.unility
@@ -68,6 +70,7 @@ namespace YSAI.Rpc.unility
         /// <returns>状态</returns>
         public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
         {
+            result = null;
             try
             {
                 //标识
@@ -93,16 +96,19 @@ namespace YSAI.Rpc.unility
                 Response response = JsonConvert.DeserializeObject<Response>(res);
                 if (response == null)
                 {
-                    throw new Exception("超时未响应");
+                    if (basics.Main is RpcClient)
+                    {
+                        (basics.Main as RpcClient)?.Exception(new Exception("超时未响应"));
+                    }
+                    else if (basics.Main is RpcService)
+                    {
+                        (basics.Main as RpcClient)?.Exception(new Exception("超时未响应"));
+                    }
                 }
                 else if (response.status)
                 {
                     System.Type? returnType = basics.type?.GetMethod(binder.Name)?.ReturnType;
-                    if (returnType == typeof(void))
-                    {
-                        result = null;
-                    }
-                    else
+                    if (returnType != typeof(void))
                     {
                         result = JsonConvert.DeserializeObject(response.data.ToJson(), returnType);
                     }
@@ -110,13 +116,28 @@ namespace YSAI.Rpc.unility
                 }
                 else
                 {
-                    throw new Exception($"异常错误消息:{response.info}");
+                    if (basics.Main is RpcClient)
+                    {
+                        (basics.Main as RpcClient)?.Exception(new Exception($"异常错误消息:{response.info}"));
+                    }
+                    else if (basics.Main is RpcService)
+                    {
+                        (basics.Main as RpcClient)?.Exception(new Exception($"异常错误消息:{response.info}"));
+                    }
                 }
             }
             catch (Exception ex)
             {
-                throw ex;
+                if (basics.Main is RpcClient)
+                {
+                    (basics.Main as RpcClient)?.Exception(ex);
+                }
+                else if (basics.Main is RpcService)
+                {
+                    (basics.Main as RpcClient)?.Exception(ex);
+                }
             }
+            return false;
         }
     }
 }

+ 1 - 1
src/YSAI.Test.All/Program.cs

@@ -29,7 +29,7 @@ while (true)
 
 void SerialOperate_OnEvent(object? sender, EventResult e)
 {
-    byte[] array = (byte[])e.RData;
+    byte[] array = e.GetRData<byte[]>();
     Console.WriteLine(ByteTool.HexToStr(array).ToUpper());
     bytes = ByteTool.CombineBytes(bytes, 0, bytes.Length, array, 0, array.Length);
 }

+ 1 - 0
src/YSAI.VT/Program.cs

@@ -34,6 +34,7 @@ namespace YSAI.VT
                 //"YSAI.Netty",
                 //"YSAI.RabbitMQ",
                 //"YSAI.Rpc",
+                //"YSAI.Redis",
 #endif
             };