From a70c097c05e775935b5b336383bcd2489f4f6033 Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 27 Oct 2020 08:48:53 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/dotnetCampus.Ipc.Demo/Program.cs | 43 +---------------- .../dotnetCampus.Ipc.Demo.csproj | 1 + .../IpcObjectJsonSerializer.cs | 48 ++++++++++++++++++- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/demo/dotnetCampus.Ipc.Demo/Program.cs b/demo/dotnetCampus.Ipc.Demo/Program.cs index c6d20e39..ffd192e8 100644 --- a/demo/dotnetCampus.Ipc.Demo/Program.cs +++ b/demo/dotnetCampus.Ipc.Demo/Program.cs @@ -8,37 +8,6 @@ namespace dotnetCampus.Ipc.Demo { - - public class IpcProxy : DispatchProxy - { - protected override object Invoke(MethodInfo targetMethod, object[] args) - { - var actualReturnType = GetAndCheckActualReturnType(targetMethod.ReturnType); - - return default!; - } - - private Type GetAndCheckActualReturnType(Type returnType) - { - if (returnType == typeof(Task)) - { - return typeof(void); - } - else if (returnType.BaseType == typeof(Task)) - { - if (returnType.Name == "Task`1") - { - if (returnType.GenericTypeArguments.Length == 1) - { - return returnType.GenericTypeArguments[0]; - } - } - } - - throw new ArgumentException($"方法返回值只能是 Task 或 Task 泛形"); - } - } - public interface IF1 { Task F2(); @@ -48,13 +17,6 @@ public interface IF1 void Fx(); } - class IpcClientProvider - { - public T GetObject() - { - return DispatchProxy.Create>(); - } - } internal class Program { @@ -91,8 +53,7 @@ private static void Main(string[] args) //Task.Run(LibearlafeCilinoballnelnall), //Task.Run(LibearlafeCilinoballnelnall), //Task.Run(WhejeewukawBalbejelnewearfe), - Task.Run(WheehakawlucearHalwahewurlaiwhair), - Task.Run(BaiqealawbawKeqakeyawaw) + Task.Run(WheehakawlucearHalwahewurlaiwhair), Task.Run(BaiqealawbawKeqakeyawaw) }; Task.WaitAll(jalejekemNereyararli.ToArray()); @@ -121,7 +82,6 @@ private static void LerlocunaihukeajerJinenenay() var ipcProvider = new IpcProvider(); ipcProvider.PeerConnected += (sender, proxy) => { - }; var peer = await ipcProvider.ConnectToPeerAsync(IpcContext.DefaultPipeName); await peer.IpcMessageWriter.WriteMessageAsync("林德熙是逗比"); @@ -135,7 +95,6 @@ private static void LerlocunaihukeajerJinenenay() var ipcProvider = new IpcProvider(); ipcProvider.PeerConnected += (sender, proxy) => { - }; var peer = await ipcProvider.ConnectToPeerAsync(IpcContext.DefaultPipeName); Console.WriteLine($"连接上{peer.PeerName}"); diff --git a/demo/dotnetCampus.Ipc.Demo/dotnetCampus.Ipc.Demo.csproj b/demo/dotnetCampus.Ipc.Demo/dotnetCampus.Ipc.Demo.csproj index 9df42359..27c70f1d 100644 --- a/demo/dotnetCampus.Ipc.Demo/dotnetCampus.Ipc.Demo.csproj +++ b/demo/dotnetCampus.Ipc.Demo/dotnetCampus.Ipc.Demo.csproj @@ -8,6 +8,7 @@ + diff --git a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs index 6a0b5090..22445ea9 100644 --- a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs +++ b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs @@ -1,4 +1,7 @@ -using System.Text; +using System; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; using Newtonsoft.Json; namespace dotnetCampus.Ipc @@ -17,4 +20,47 @@ public T Deserialize(byte[] byteList) return JsonConvert.DeserializeObject(json); } } + + public class IpcClientProvider + { + public T GetObject() + { + var obj= DispatchProxy.Create>(); + var ipcProxy = obj as IpcProxy; + ipcProxy.IpcClientProvider = this; + return obj; + } + } + + public class IpcProxy : DispatchProxy + { + public IpcClientProvider IpcClientProvider { set; get; } = null!; + + protected override object Invoke(MethodInfo targetMethod, object[] args) + { + var actualReturnType = GetAndCheckActualReturnType(targetMethod.ReturnType); + + return default!; + } + + private Type GetAndCheckActualReturnType(Type returnType) + { + if (returnType == typeof(Task)) + { + return typeof(void); + } + else if (returnType.BaseType == typeof(Task)) + { + if (returnType.Name == "Task`1") + { + if (returnType.GenericTypeArguments.Length == 1) + { + return returnType.GenericTypeArguments[0]; + } + } + } + + throw new ArgumentException($"方法返回值只能是 Task 或 Task 泛形"); + } + } } From 8751af281060f6b19a56a937335149fdb8301bd7 Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 27 Oct 2020 08:50:02 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=B8=80=E4=B8=AA=E7=B1=BB=E6=94=BE?= =?UTF-8?q?=E5=9C=A8=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dotnetCampus.Ipc/IpcClientProvider.cs | 17 +++++++++++++++++ src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs | 11 ----------- 2 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 src/dotnetCampus.Ipc/IpcClientProvider.cs diff --git a/src/dotnetCampus.Ipc/IpcClientProvider.cs b/src/dotnetCampus.Ipc/IpcClientProvider.cs new file mode 100644 index 00000000..3a25f08b --- /dev/null +++ b/src/dotnetCampus.Ipc/IpcClientProvider.cs @@ -0,0 +1,17 @@ +using System.Diagnostics; +using System.Reflection; + +namespace dotnetCampus.Ipc +{ + public class IpcClientProvider + { + public T GetObject() + { + var obj= DispatchProxy.Create>(); + var ipcProxy = obj as IpcProxy; + Debug.Assert(ipcProxy!=null); + ipcProxy!.IpcClientProvider = this; + return obj; + } + } +} diff --git a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs index 22445ea9..c8bf368c 100644 --- a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs +++ b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs @@ -21,17 +21,6 @@ public T Deserialize(byte[] byteList) } } - public class IpcClientProvider - { - public T GetObject() - { - var obj= DispatchProxy.Create>(); - var ipcProxy = obj as IpcProxy; - ipcProxy.IpcClientProvider = this; - return obj; - } - } - public class IpcProxy : DispatchProxy { public IpcClientProvider IpcClientProvider { set; get; } = null!; From b079f45256663d67bba33ba8c4c7b4608fb83e1f Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 27 Oct 2020 08:58:52 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=BB=99=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=92=8C=E4=BB=8E=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=94=B6=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copy from: https://github.com/jacqueskang/IpcServiceFramework https://github.com/jacqueskang/IpcServiceFramework/issues/171 --- .../IpcObjectJsonSerializer.cs | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs index c8bf368c..a39459c5 100644 --- a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs +++ b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Reflection; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; @@ -21,6 +23,96 @@ public T Deserialize(byte[] byteList) } } + /// + /// 发送给服务器的请求数据 + /// + /// Copy From: https://github.com/jacqueskang/IpcServiceFramework.git + public class IpcRequest + { + public Type ObjectType { set; get; } + + public string MethodName { get; set; } + + public List ParameterList { set; get; } + + public List GenericArgumentList { set; get; } + + public Type ReturnType { set; get; } + } + + /// + /// 从服务器返回的信息 + /// + /// Copy From: https://github.com/jacqueskang/IpcServiceFramework.git + public class IpcResponse + { + public static IpcResponse Success(object data) + => new IpcResponse(IpcStatus.Ok, data, null, null); + + public static IpcResponse BadRequest() + => new IpcResponse(IpcStatus.BadRequest, null, null, null); + + public static IpcResponse BadRequest(string errorDetails) + => new IpcResponse(IpcStatus.BadRequest, null, errorDetails, null); + + public static IpcResponse BadRequest(string errorDetails, Exception innerException) + => new IpcResponse(IpcStatus.BadRequest, null, errorDetails, innerException); + + public static IpcResponse InternalServerError() + => new IpcResponse(IpcStatus.InternalServerError, null, null, null); + + public static IpcResponse InternalServerError(string errorDetails) + => new IpcResponse(IpcStatus.InternalServerError, null, errorDetails, null); + + public static IpcResponse InternalServerError(string errorDetails, Exception innerException) + => new IpcResponse(IpcStatus.InternalServerError, null, errorDetails, innerException); + + public IpcResponse( + IpcStatus status, + object data, + string errorMessage, + Exception innerException) + { + Status = status; + Data = data; + ErrorMessage = errorMessage; + InnerException = innerException; + } + + [DataMember] + public IpcStatus Status { get; } + + [DataMember] + public object Data { get; } + + [DataMember] + public string ErrorMessage { get; set; } + + [DataMember] + public Exception InnerException { get; } + + public bool Succeed() => Status == IpcStatus.Ok; + } + + /// + /// 从服务器返回的值 + /// + /// Copy From: https://github.com/jacqueskang/IpcServiceFramework.git + public enum IpcStatus : int + { + Unknown = 0, + Ok = 200, + BadRequest = 400, + InternalServerError = 500, + } + + public class IpcRequestParameter + { + public Type ParameterType { set; get; } + + public object Value { set; get; } + } + public class IpcProxy : DispatchProxy { public IpcClientProvider IpcClientProvider { set; get; } = null!; From f3300882d2c2835a8a617834d034d7cc37713d2b Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 27 Oct 2020 09:07:45 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E6=A0=87=E8=AF=86?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=AB=AF=E7=9A=84=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs index a39459c5..a8160ef6 100644 --- a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs +++ b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs @@ -31,6 +31,11 @@ public class IpcRequest { public Type ObjectType { set; get; } + /// + /// 用来标识服务器端的对象 + /// + public ulong ObjectId { set; get; } + public string MethodName { get; set; } public List ParameterList { set; get; } From ea8c351b1562d00173e37588c2e3784792310ab4 Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 27 Oct 2020 09:08:14 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=8D=95=E7=8B=AC=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E7=B1=BB=E6=94=BE=E5=9C=A8=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IpcObjectJsonSerializer.cs | 134 +----------------- src/dotnetCampus.Ipc/IpcProxy.cs | 38 +++++ src/dotnetCampus.Ipc/IpcRequest.cs | 27 ++++ src/dotnetCampus.Ipc/IpcRequestParameter.cs | 11 ++ src/dotnetCampus.Ipc/IpcResponse.cs | 59 ++++++++ src/dotnetCampus.Ipc/IpcStatus.cs | 14 ++ 6 files changed, 150 insertions(+), 133 deletions(-) create mode 100644 src/dotnetCampus.Ipc/IpcProxy.cs create mode 100644 src/dotnetCampus.Ipc/IpcRequest.cs create mode 100644 src/dotnetCampus.Ipc/IpcRequestParameter.cs create mode 100644 src/dotnetCampus.Ipc/IpcResponse.cs create mode 100644 src/dotnetCampus.Ipc/IpcStatus.cs diff --git a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs index a8160ef6..6a0b5090 100644 --- a/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs +++ b/src/dotnetCampus.Ipc/IpcObjectJsonSerializer.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; +using System.Text; using Newtonsoft.Json; namespace dotnetCampus.Ipc @@ -22,131 +17,4 @@ public T Deserialize(byte[] byteList) return JsonConvert.DeserializeObject(json); } } - - /// - /// 发送给服务器的请求数据 - /// - /// Copy From: https://github.com/jacqueskang/IpcServiceFramework.git - public class IpcRequest - { - public Type ObjectType { set; get; } - - /// - /// 用来标识服务器端的对象 - /// - public ulong ObjectId { set; get; } - - public string MethodName { get; set; } - - public List ParameterList { set; get; } - - public List GenericArgumentList { set; get; } - - public Type ReturnType { set; get; } - } - - /// - /// 从服务器返回的信息 - /// - /// Copy From: https://github.com/jacqueskang/IpcServiceFramework.git - public class IpcResponse - { - public static IpcResponse Success(object data) - => new IpcResponse(IpcStatus.Ok, data, null, null); - - public static IpcResponse BadRequest() - => new IpcResponse(IpcStatus.BadRequest, null, null, null); - - public static IpcResponse BadRequest(string errorDetails) - => new IpcResponse(IpcStatus.BadRequest, null, errorDetails, null); - - public static IpcResponse BadRequest(string errorDetails, Exception innerException) - => new IpcResponse(IpcStatus.BadRequest, null, errorDetails, innerException); - - public static IpcResponse InternalServerError() - => new IpcResponse(IpcStatus.InternalServerError, null, null, null); - - public static IpcResponse InternalServerError(string errorDetails) - => new IpcResponse(IpcStatus.InternalServerError, null, errorDetails, null); - - public static IpcResponse InternalServerError(string errorDetails, Exception innerException) - => new IpcResponse(IpcStatus.InternalServerError, null, errorDetails, innerException); - - public IpcResponse( - IpcStatus status, - object data, - string errorMessage, - Exception innerException) - { - Status = status; - Data = data; - ErrorMessage = errorMessage; - InnerException = innerException; - } - - [DataMember] - public IpcStatus Status { get; } - - [DataMember] - public object Data { get; } - - [DataMember] - public string ErrorMessage { get; set; } - - [DataMember] - public Exception InnerException { get; } - - public bool Succeed() => Status == IpcStatus.Ok; - } - - /// - /// 从服务器返回的值 - /// - /// Copy From: https://github.com/jacqueskang/IpcServiceFramework.git - public enum IpcStatus : int - { - Unknown = 0, - Ok = 200, - BadRequest = 400, - InternalServerError = 500, - } - - public class IpcRequestParameter - { - public Type ParameterType { set; get; } - - public object Value { set; get; } - } - - public class IpcProxy : DispatchProxy - { - public IpcClientProvider IpcClientProvider { set; get; } = null!; - - protected override object Invoke(MethodInfo targetMethod, object[] args) - { - var actualReturnType = GetAndCheckActualReturnType(targetMethod.ReturnType); - - return default!; - } - - private Type GetAndCheckActualReturnType(Type returnType) - { - if (returnType == typeof(Task)) - { - return typeof(void); - } - else if (returnType.BaseType == typeof(Task)) - { - if (returnType.Name == "Task`1") - { - if (returnType.GenericTypeArguments.Length == 1) - { - return returnType.GenericTypeArguments[0]; - } - } - } - - throw new ArgumentException($"方法返回值只能是 Task 或 Task 泛形"); - } - } } diff --git a/src/dotnetCampus.Ipc/IpcProxy.cs b/src/dotnetCampus.Ipc/IpcProxy.cs new file mode 100644 index 00000000..ee7755c3 --- /dev/null +++ b/src/dotnetCampus.Ipc/IpcProxy.cs @@ -0,0 +1,38 @@ +using System; +using System.Reflection; +using System.Threading.Tasks; + +namespace dotnetCampus.Ipc +{ + public class IpcProxy : DispatchProxy + { + public IpcClientProvider IpcClientProvider { set; get; } = null!; + + protected override object Invoke(MethodInfo targetMethod, object[] args) + { + var actualReturnType = GetAndCheckActualReturnType(targetMethod.ReturnType); + + return default!; + } + + private Type GetAndCheckActualReturnType(Type returnType) + { + if (returnType == typeof(Task)) + { + return typeof(void); + } + else if (returnType.BaseType == typeof(Task)) + { + if (returnType.Name == "Task`1") + { + if (returnType.GenericTypeArguments.Length == 1) + { + return returnType.GenericTypeArguments[0]; + } + } + } + + throw new ArgumentException($"方法返回值只能是 Task 或 Task 泛形"); + } + } +} \ No newline at end of file diff --git a/src/dotnetCampus.Ipc/IpcRequest.cs b/src/dotnetCampus.Ipc/IpcRequest.cs new file mode 100644 index 00000000..a20b80ff --- /dev/null +++ b/src/dotnetCampus.Ipc/IpcRequest.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +namespace dotnetCampus.Ipc +{ + /// + /// 发送给服务器的请求数据 + /// + /// Copy From: https://github.com/jacqueskang/IpcServiceFramework.git + public class IpcRequest + { + public Type ObjectType { set; get; } + + /// + /// 用来标识服务器端的对象 + /// + public ulong ObjectId { set; get; } + + public string MethodName { get; set; } + + public List ParameterList { set; get; } + + public List GenericArgumentList { set; get; } + + public Type ReturnType { set; get; } + } +} \ No newline at end of file diff --git a/src/dotnetCampus.Ipc/IpcRequestParameter.cs b/src/dotnetCampus.Ipc/IpcRequestParameter.cs new file mode 100644 index 00000000..d3322ca6 --- /dev/null +++ b/src/dotnetCampus.Ipc/IpcRequestParameter.cs @@ -0,0 +1,11 @@ +using System; + +namespace dotnetCampus.Ipc +{ + public class IpcRequestParameter + { + public Type ParameterType { set; get; } + + public object Value { set; get; } + } +} \ No newline at end of file diff --git a/src/dotnetCampus.Ipc/IpcResponse.cs b/src/dotnetCampus.Ipc/IpcResponse.cs new file mode 100644 index 00000000..5f64e6b4 --- /dev/null +++ b/src/dotnetCampus.Ipc/IpcResponse.cs @@ -0,0 +1,59 @@ +using System; +using System.Runtime.Serialization; + +namespace dotnetCampus.Ipc +{ + /// + /// 从服务器返回的信息 + /// + /// Copy From: https://github.com/jacqueskang/IpcServiceFramework.git + public class IpcResponse + { + public static IpcResponse Success(object data) + => new IpcResponse(IpcStatus.Ok, data, null, null); + + public static IpcResponse BadRequest() + => new IpcResponse(IpcStatus.BadRequest, null, null, null); + + public static IpcResponse BadRequest(string errorDetails) + => new IpcResponse(IpcStatus.BadRequest, null, errorDetails, null); + + public static IpcResponse BadRequest(string errorDetails, Exception innerException) + => new IpcResponse(IpcStatus.BadRequest, null, errorDetails, innerException); + + public static IpcResponse InternalServerError() + => new IpcResponse(IpcStatus.InternalServerError, null, null, null); + + public static IpcResponse InternalServerError(string errorDetails) + => new IpcResponse(IpcStatus.InternalServerError, null, errorDetails, null); + + public static IpcResponse InternalServerError(string errorDetails, Exception innerException) + => new IpcResponse(IpcStatus.InternalServerError, null, errorDetails, innerException); + + public IpcResponse( + IpcStatus status, + object data, + string errorMessage, + Exception innerException) + { + Status = status; + Data = data; + ErrorMessage = errorMessage; + InnerException = innerException; + } + + [DataMember] + public IpcStatus Status { get; } + + [DataMember] + public object Data { get; } + + [DataMember] + public string ErrorMessage { get; set; } + + [DataMember] + public Exception InnerException { get; } + + public bool Succeed() => Status == IpcStatus.Ok; + } +} \ No newline at end of file diff --git a/src/dotnetCampus.Ipc/IpcStatus.cs b/src/dotnetCampus.Ipc/IpcStatus.cs new file mode 100644 index 00000000..a27a98a2 --- /dev/null +++ b/src/dotnetCampus.Ipc/IpcStatus.cs @@ -0,0 +1,14 @@ +namespace dotnetCampus.Ipc +{ + /// + /// 从服务器返回的值 + /// + /// Copy From: https://github.com/jacqueskang/IpcServiceFramework.git + public enum IpcStatus : int + { + Unknown = 0, + Ok = 200, + BadRequest = 400, + InternalServerError = 500, + } +} \ No newline at end of file From 5f1de3a73fc6813f4889aea297e72e8682808fab Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 27 Oct 2020 09:10:09 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dotnetCampus.Ipc/IpcClientProvider.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dotnetCampus.Ipc/IpcClientProvider.cs b/src/dotnetCampus.Ipc/IpcClientProvider.cs index 3a25f08b..402a0380 100644 --- a/src/dotnetCampus.Ipc/IpcClientProvider.cs +++ b/src/dotnetCampus.Ipc/IpcClientProvider.cs @@ -3,6 +3,12 @@ namespace dotnetCampus.Ipc { + /// + /// 提供客户端使用的方法,可以拿到服务器端的对象 + /// + /// 在服务器端将会维护一个对象池,可以选的是一个对象可以作为单例或者作为每次访问返回新的对象 + /// 如果是每次访问都返回的新的对象,就需要将这个对象发生过去的时候加上对象的标识,之后客户端调用的时候,就可以 + /// 使用这个标识拿到对应的对象 public class IpcClientProvider { public T GetObject() From 9eadd0224a0ad9d6a6dbd24cd247189b3799b924 Mon Sep 17 00:00:00 2001 From: lindexi Date: Tue, 27 Oct 2020 09:14:17 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dotnetCampus.Ipc/IpcClientProvider.cs | 7 ++++++- src/dotnetCampus.Ipc/IpcProxy.cs | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/dotnetCampus.Ipc/IpcClientProvider.cs b/src/dotnetCampus.Ipc/IpcClientProvider.cs index 402a0380..228a0a9b 100644 --- a/src/dotnetCampus.Ipc/IpcClientProvider.cs +++ b/src/dotnetCampus.Ipc/IpcClientProvider.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.Reflection; namespace dotnetCampus.Ipc @@ -13,11 +14,15 @@ public class IpcClientProvider { public T GetObject() { +#if NETCOREAPP var obj= DispatchProxy.Create>(); var ipcProxy = obj as IpcProxy; Debug.Assert(ipcProxy!=null); ipcProxy!.IpcClientProvider = this; return obj; +#endif + // 还需要加上 NET45 使用的透明代理 + throw new NotImplementedException(); } } } diff --git a/src/dotnetCampus.Ipc/IpcProxy.cs b/src/dotnetCampus.Ipc/IpcProxy.cs index ee7755c3..31c9fd34 100644 --- a/src/dotnetCampus.Ipc/IpcProxy.cs +++ b/src/dotnetCampus.Ipc/IpcProxy.cs @@ -4,6 +4,13 @@ namespace dotnetCampus.Ipc { +#if !NETCOREAPP + public abstract class DispatchProxy + { + protected abstract object Invoke(MethodInfo targetMethod, object[] args); + } +#endif + public class IpcProxy : DispatchProxy { public IpcClientProvider IpcClientProvider { set; get; } = null!; @@ -35,4 +42,4 @@ private Type GetAndCheckActualReturnType(Type returnType) throw new ArgumentException($"方法返回值只能是 Task 或 Task 泛形"); } } -} \ No newline at end of file +}