mirror of
https://github.com/RRQM/TouchSocket.git
synced 2025-12-18 17:36:43 +08:00
替换RRQMSocket.RPC
This commit is contained in:
@@ -22,7 +22,7 @@ namespace RRQMSocket.RPC
|
||||
/// <summary>
|
||||
/// 执行此RPC的实例
|
||||
/// </summary>
|
||||
public ServerProvider Provider { get; internal set; }
|
||||
public IServerProvider Provider { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// RPC函数
|
||||
|
||||
@@ -15,7 +15,6 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace RRQMSocket.RPC
|
||||
{
|
||||
@@ -47,14 +46,14 @@ namespace RRQMSocket.RPC
|
||||
return this.methodMap.TryGetValue(methodToken, out methodInstance);
|
||||
}
|
||||
|
||||
internal bool RemoveServer(Type type,out ServerProvider serverProvider,out MethodInstance[] methodInstances)
|
||||
internal bool RemoveServer(Type type, out IServerProvider serverProvider, out MethodInstance[] methodInstances)
|
||||
{
|
||||
serverProvider = null;
|
||||
bool success=false;
|
||||
bool success = false;
|
||||
List<MethodInstance> keys = new List<MethodInstance>();
|
||||
foreach (var methodInstance in this.methodMap.Values)
|
||||
{
|
||||
if (methodInstance.Provider.GetType().FullName==type.FullName)
|
||||
if (methodInstance.Provider.GetType().FullName == type.FullName)
|
||||
{
|
||||
success = true;
|
||||
serverProvider = methodInstance.Provider;
|
||||
|
||||
@@ -9,12 +9,10 @@
|
||||
// 感谢您的下载和使用
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace RRQMSocket.RPC
|
||||
{
|
||||
@@ -57,11 +55,11 @@ namespace RRQMSocket.RPC
|
||||
}
|
||||
|
||||
this.parsers.TryAdd(key, parser);
|
||||
}
|
||||
|
||||
internal bool TryRemove(string key,out IRPCParser parser)
|
||||
}
|
||||
|
||||
internal bool TryRemove(string key, out IRPCParser parser)
|
||||
{
|
||||
return this.parsers.TryRemove(key,out parser);
|
||||
return this.parsers.TryRemove(key, out parser);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
|
||||
@@ -16,40 +16,17 @@ namespace RRQMSocket.RPC
|
||||
/// <summary>
|
||||
/// RPC范围类
|
||||
/// </summary>
|
||||
public abstract class ServerProvider
|
||||
public abstract class ServerProvider:IServerProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认复刻程序集
|
||||
/// </summary>
|
||||
public static Assembly DefaultAssembly { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 该服务所属的服务器
|
||||
/// </summary>
|
||||
public RPCService RPCService { get; internal set; }
|
||||
|
||||
internal void RPC(int index, IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
RPCEnter(parser, methodInvoker, methodInstance);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
RPCError(parser, methodInvoker, methodInstance);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
RPCLeave(parser, methodInvoker, methodInstance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public RPCService RPCService { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// RPC即将进入,
|
||||
@@ -58,7 +35,7 @@ namespace RRQMSocket.RPC
|
||||
/// <param name="parser"></param>
|
||||
/// <param name="methodInvoker"></param>
|
||||
/// <param name="methodInstance"></param>
|
||||
protected virtual void RPCEnter(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
|
||||
public virtual void RPCEnter(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -68,7 +45,7 @@ namespace RRQMSocket.RPC
|
||||
/// <param name="parser"></param>
|
||||
/// <param name="methodInvoker"></param>
|
||||
/// <param name="methodInstance"></param>
|
||||
protected virtual void RPCError(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
|
||||
public virtual void RPCError(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -78,7 +55,7 @@ namespace RRQMSocket.RPC
|
||||
/// <param name="parser"></param>
|
||||
/// <param name="methodInvoker"></param>
|
||||
/// <param name="methodInstance"></param>
|
||||
protected virtual void RPCLeave(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
|
||||
public virtual void RPCLeave(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace RRQMSocket.RPC
|
||||
{
|
||||
@@ -21,20 +20,20 @@ namespace RRQMSocket.RPC
|
||||
/// 服务集合
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Count}")]
|
||||
public class ServerProviderCollection : IEnumerable<ServerProvider>, IEnumerable
|
||||
public class ServerProviderCollection : IEnumerable<IServerProvider>, IEnumerable
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务数量
|
||||
/// </summary>
|
||||
public int Count { get { return this.servers.Count; } }
|
||||
|
||||
private List<ServerProvider> servers = new List<ServerProvider>();
|
||||
private List<IServerProvider> servers = new List<IServerProvider>();
|
||||
|
||||
internal void Add(ServerProvider serverProvider)
|
||||
internal void Add(IServerProvider serverProvider)
|
||||
{
|
||||
foreach (var server in this.servers)
|
||||
{
|
||||
if (serverProvider.GetType().FullName==server.GetType().FullName)
|
||||
if (serverProvider.GetType().FullName == server.GetType().FullName)
|
||||
{
|
||||
throw new RRQMRPCException("相同类型的服务已添加");
|
||||
}
|
||||
@@ -57,11 +56,12 @@ namespace RRQMSocket.RPC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回枚举
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IEnumerator<ServerProvider> IEnumerable<ServerProvider>.GetEnumerator()
|
||||
IEnumerator<IServerProvider> IEnumerable<IServerProvider>.GetEnumerator()
|
||||
{
|
||||
return this.servers.GetEnumerator();
|
||||
}
|
||||
|
||||
55
RRQMSocket.RPC/Global/Interface/IServerProvider.cs
Normal file
55
RRQMSocket.RPC/Global/Interface/IServerProvider.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
|
||||
// CSDN博客:https://blog.csdn.net/qq_40374647
|
||||
// 哔哩哔哩视频:https://space.bilibili.com/94253567
|
||||
// Gitee源代码仓库:https://gitee.com/RRQM_Home
|
||||
// Github源代码仓库:https://github.com/RRQM
|
||||
// 交流QQ群:234762506
|
||||
// 感谢您的下载和使用
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RRQMSocket.RPC
|
||||
{
|
||||
/// <summary>
|
||||
/// RRQM的RPC服务接口
|
||||
/// </summary>
|
||||
public interface IServerProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// 该服务所属的服务器
|
||||
/// </summary>
|
||||
RPCService RPCService { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// RPC即将进入,
|
||||
/// 若是想放弃本次执行,请抛出<see cref="RRQMAbandonRPCException"/>
|
||||
/// </summary>
|
||||
/// <param name="parser"></param>
|
||||
/// <param name="methodInvoker"></param>
|
||||
/// <param name="methodInstance"></param>
|
||||
void RPCEnter(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance);
|
||||
|
||||
/// <summary>
|
||||
/// 执行RPC发生错误
|
||||
/// </summary>
|
||||
/// <param name="parser"></param>
|
||||
/// <param name="methodInvoker"></param>
|
||||
/// <param name="methodInstance"></param>
|
||||
void RPCError(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance);
|
||||
|
||||
/// <summary>
|
||||
/// RPC方法执行完成
|
||||
/// </summary>
|
||||
/// <param name="parser"></param>
|
||||
/// <param name="methodInvoker"></param>
|
||||
/// <param name="methodInstance"></param>
|
||||
void RPCLeave(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance);
|
||||
}
|
||||
}
|
||||
@@ -38,14 +38,14 @@ namespace RRQMSocket.RPC
|
||||
/// </summary>
|
||||
/// <param name="provider"></param>
|
||||
/// <param name="methodInstances"></param>
|
||||
void OnRegisterServer(ServerProvider provider, MethodInstance[] methodInstances);
|
||||
void OnRegisterServer(IServerProvider provider, MethodInstance[] methodInstances);
|
||||
|
||||
/// <summary>
|
||||
/// 取消注册服务
|
||||
/// </summary>
|
||||
/// <param name="provider"></param>
|
||||
/// <param name="methodInstances"></param>
|
||||
void OnUnregisterServer(ServerProvider provider, MethodInstance[] methodInstances);
|
||||
void OnUnregisterServer(IServerProvider provider, MethodInstance[] methodInstances);
|
||||
|
||||
/// <summary>
|
||||
/// 结束调用
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using RRQMCore;
|
||||
using RRQMCore.Exceptions;
|
||||
using RRQMCore.Helper;
|
||||
using RRQMSocket.RPC.RRQMRPC;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -79,7 +78,7 @@ namespace RRQMSocket.RPC
|
||||
|
||||
if (applyServer)
|
||||
{
|
||||
Dictionary<ServerProvider, List<MethodInstance>> pairs = new Dictionary<ServerProvider, List<MethodInstance>>();
|
||||
Dictionary<IServerProvider, List<MethodInstance>> pairs = new Dictionary<IServerProvider, List<MethodInstance>>();
|
||||
|
||||
MethodInstance[] instances = this.MethodMap.GetAllMethodInstances();
|
||||
|
||||
@@ -133,9 +132,9 @@ namespace RRQMSocket.RPC
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns>返回T实例</returns>
|
||||
public ServerProvider RegisterServer<T>() where T : ServerProvider
|
||||
public IServerProvider RegisterServer<T>() where T : IServerProvider
|
||||
{
|
||||
ServerProvider serverProvider = (ServerProvider)Activator.CreateInstance(typeof(T));
|
||||
IServerProvider serverProvider = (IServerProvider)Activator.CreateInstance(typeof(T));
|
||||
this.RegisterServer(serverProvider);
|
||||
return serverProvider;
|
||||
}
|
||||
@@ -145,13 +144,13 @@ namespace RRQMSocket.RPC
|
||||
/// </summary>
|
||||
/// <param name="providerType"></param>
|
||||
/// <returns></returns>
|
||||
public ServerProvider RegisterServer(Type providerType)
|
||||
public IServerProvider RegisterServer(Type providerType)
|
||||
{
|
||||
if (!typeof(ServerProvider).IsAssignableFrom(providerType))
|
||||
if (!typeof(IServerProvider).IsAssignableFrom(providerType))
|
||||
{
|
||||
throw new RRQMRPCException("类型不相符");
|
||||
}
|
||||
ServerProvider serverProvider = (ServerProvider)Activator.CreateInstance(providerType);
|
||||
IServerProvider serverProvider = (IServerProvider)Activator.CreateInstance(providerType);
|
||||
this.RegisterServer(serverProvider);
|
||||
return serverProvider;
|
||||
}
|
||||
@@ -160,7 +159,7 @@ namespace RRQMSocket.RPC
|
||||
/// 注册服务
|
||||
/// </summary>
|
||||
/// <param name="serverProvider"></param>
|
||||
public void RegisterServer(ServerProvider serverProvider)
|
||||
public void RegisterServer(IServerProvider serverProvider)
|
||||
{
|
||||
serverProvider.RPCService = this;
|
||||
this.ServerProviders.Add(serverProvider);
|
||||
@@ -193,7 +192,7 @@ namespace RRQMSocket.RPC
|
||||
throw new RRQMException("没有找到该解析器");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置服务方法可用性
|
||||
/// </summary>
|
||||
@@ -222,13 +221,13 @@ namespace RRQMSocket.RPC
|
||||
{
|
||||
return this.RPCParsers.TryGetRPCParser(parserKey, out parser);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 移除注册服务
|
||||
/// </summary>
|
||||
/// <param name="provider"></param>
|
||||
/// <returns></returns>
|
||||
public int UnregisterServer(ServerProvider provider)
|
||||
public int UnregisterServer(IServerProvider provider)
|
||||
{
|
||||
return this.UnregisterServer(provider.GetType());
|
||||
}
|
||||
@@ -240,12 +239,12 @@ namespace RRQMSocket.RPC
|
||||
/// <returns></returns>
|
||||
public int UnregisterServer(Type providerType)
|
||||
{
|
||||
if (!typeof(ServerProvider).IsAssignableFrom(providerType))
|
||||
if (!typeof(IServerProvider).IsAssignableFrom(providerType))
|
||||
{
|
||||
throw new RRQMRPCException("类型不相符");
|
||||
}
|
||||
this.ServerProviders.Remove(providerType);
|
||||
if (this.MethodMap.RemoveServer(providerType, out ServerProvider serverProvider, out MethodInstance[] instances))
|
||||
if (this.MethodMap.RemoveServer(providerType, out IServerProvider serverProvider, out MethodInstance[] instances))
|
||||
{
|
||||
foreach (var parser in this.RPCParsers)
|
||||
{
|
||||
@@ -273,12 +272,12 @@ namespace RRQMSocket.RPC
|
||||
{
|
||||
try
|
||||
{
|
||||
methodInstance.Provider.RPC(1, parser, methodInvoker, methodInstance);
|
||||
methodInstance.Provider.RPCEnter(parser, methodInvoker, methodInstance);
|
||||
if (isAsync)
|
||||
{
|
||||
dynamic task = methodInstance.Method.Invoke(methodInstance.Provider, methodInvoker.Parameters);
|
||||
task.Wait();
|
||||
if (methodInstance.ReturnType!=null)
|
||||
if (methodInstance.ReturnType != null)
|
||||
{
|
||||
methodInvoker.ReturnParameter = task.Result;
|
||||
}
|
||||
@@ -287,7 +286,7 @@ namespace RRQMSocket.RPC
|
||||
{
|
||||
methodInvoker.ReturnParameter = methodInstance.Method.Invoke(methodInstance.Provider, methodInvoker.Parameters);
|
||||
}
|
||||
methodInstance.Provider.RPC(3, parser, methodInvoker, methodInstance);
|
||||
methodInstance.Provider.RPCLeave(parser, methodInvoker, methodInstance);
|
||||
methodInvoker.Status = InvokeStatus.Success;
|
||||
}
|
||||
catch (RRQMAbandonRPCException e)
|
||||
@@ -306,13 +305,13 @@ namespace RRQMSocket.RPC
|
||||
{
|
||||
methodInvoker.StatusMessage = "函数内部发生异常,信息:未知";
|
||||
}
|
||||
methodInstance.Provider.RPC(1, parser, methodInvoker, methodInstance);
|
||||
methodInstance.Provider.RPCError(parser, methodInvoker, methodInstance);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
methodInvoker.Status = InvokeStatus.Exception;
|
||||
methodInvoker.StatusMessage = e.Message;
|
||||
methodInstance.Provider.RPC(1, parser, methodInvoker, methodInstance);
|
||||
methodInstance.Provider.RPCError(parser, methodInvoker, methodInstance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
@@ -24,4 +20,4 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
public class RRQMRPCMemberAttribute : RPCAttribute
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,26 +10,25 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
/*
|
||||
若汝棋茗
|
||||
*/
|
||||
|
||||
internal class CodeMap
|
||||
/// <summary>
|
||||
/// 代码生成器
|
||||
/// </summary>
|
||||
public class CodeGenerator
|
||||
{
|
||||
internal CodeMap()
|
||||
internal CodeGenerator()
|
||||
{
|
||||
codeString = new StringBuilder();
|
||||
}
|
||||
|
||||
internal static string GetAssemblyInfo(string assemblyName, string version)
|
||||
{
|
||||
CodeMap codeMap = new CodeMap();
|
||||
CodeGenerator codeMap = new CodeGenerator();
|
||||
codeMap.AppendAssemblyInfo(assemblyName, version);
|
||||
return codeMap.codeString.ToString();
|
||||
}
|
||||
@@ -39,7 +38,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
internal MethodInfo[] Methods { get; set; }
|
||||
internal string ClassName { get; set; }
|
||||
internal static string Namespace { get; set; }
|
||||
internal static PropertyCodeMap PropertyCode { get; set; }
|
||||
internal static PropertyCodeGenerator PropertyCode { get; set; }
|
||||
|
||||
internal string GetCode()
|
||||
{
|
||||
@@ -64,6 +63,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
codeString.AppendLine(string.Format("public interface {0}", interfaceName));//类开始
|
||||
codeString.AppendLine("{");
|
||||
codeString.AppendLine("IRpcClient Client{get;}");
|
||||
AppendInterfaceMethods();
|
||||
codeString.AppendLine("}");//类结束
|
||||
}
|
||||
@@ -72,11 +72,11 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
codeString.AppendLine(string.Format("public class {0} :I{0}", className));//类开始
|
||||
codeString.AppendLine("{");
|
||||
codeString.AppendLine($"public {className}(IRPCClient client)");
|
||||
codeString.AppendLine($"public {className}(IRpcClient client)");
|
||||
codeString.AppendLine("{");
|
||||
codeString.AppendLine("this.Client=client;");
|
||||
codeString.AppendLine("}");
|
||||
AppendAttributes();
|
||||
AppendProperties();
|
||||
AppendMethods();
|
||||
codeString.AppendLine("}");//类结束
|
||||
}
|
||||
@@ -95,12 +95,12 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
codeString.AppendLine(string.Format("[assembly: AssemblyFileVersion(\"{0}\")]", version.ToString()));
|
||||
}
|
||||
|
||||
private void AppendAttributes()
|
||||
private void AppendProperties()
|
||||
{
|
||||
codeString.AppendLine("public IRPCClient Client{get;private set; }");
|
||||
codeString.AppendLine("public IRpcClient Client{get;private set; }");
|
||||
}
|
||||
|
||||
public string GetName(Type type)
|
||||
internal string GetName(Type type)
|
||||
{
|
||||
return PropertyCode.GetTypeFullName(type);
|
||||
}
|
||||
@@ -116,7 +116,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
bool isRef = false;
|
||||
string methodName = method.GetCustomAttribute<RRQMRPCAttribute>().MemberKey == null ? method.Name : method.GetCustomAttribute<RRQMRPCAttribute>().MemberKey;
|
||||
|
||||
if (method.ReturnType.FullName == "System.Void"|| method.ReturnType.FullName== "System.Threading.Tasks.Task")
|
||||
if (method.ReturnType.FullName == "System.Void" || method.ReturnType.FullName == "System.Threading.Tasks.Task")
|
||||
{
|
||||
isReturn = false;
|
||||
codeString.Append(string.Format("public void {0} ", methodName));
|
||||
@@ -285,6 +285,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
|
||||
codeString.AppendLine("}");
|
||||
|
||||
//以下生成异步
|
||||
if (!isOut && !isRef)//没有out或者ref
|
||||
{
|
||||
if (method.ReturnType.FullName == "System.Void" || method.ReturnType.FullName == "System.Threading.Tasks.Task")
|
||||
@@ -1,30 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
|
||||
// CSDN博客:https://blog.csdn.net/qq_40374647
|
||||
// 哔哩哔哩视频:https://space.bilibili.com/94253567
|
||||
// Gitee源代码仓库:https://gitee.com/RRQM_Home
|
||||
// Github源代码仓库:https://github.com/RRQM
|
||||
// 交流QQ群:234762506
|
||||
// 感谢您的下载和使用
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
/// <summary>
|
||||
/// RPC编译器
|
||||
/// </summary>
|
||||
public interface IRPCCompiler
|
||||
{
|
||||
/// <summary>
|
||||
/// 编译代码
|
||||
/// </summary>
|
||||
/// <param name="assemblyName"></param>
|
||||
/// <param name="codes"></param>
|
||||
/// <param name="refStrings"></param>
|
||||
/// <returns></returns>
|
||||
byte[] CompileCode(string assemblyName, string[] codes, List<string> refStrings);
|
||||
}
|
||||
}
|
||||
@@ -17,53 +17,61 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// </summary>
|
||||
public class InvokeOption
|
||||
{
|
||||
static InvokeOption()
|
||||
{
|
||||
onlySend = new InvokeOption();
|
||||
onlySend.WaitTime = 5;
|
||||
onlySend.FeedbackType = FeedbackType.OnlySend;
|
||||
|
||||
waitSend = new InvokeOption();
|
||||
waitSend.WaitTime = 5;
|
||||
waitSend.FeedbackType = FeedbackType.WaitSend;
|
||||
|
||||
waitInvoke = new InvokeOption();
|
||||
waitInvoke.WaitTime = 5;
|
||||
waitInvoke.FeedbackType = FeedbackType.WaitInvoke;
|
||||
}
|
||||
|
||||
private static InvokeOption onlySend;
|
||||
|
||||
/// <summary>
|
||||
/// 默认设置。
|
||||
/// WaitTime=5
|
||||
/// </summary>
|
||||
public static InvokeOption OnlySend { get { return onlySend; } }
|
||||
|
||||
private static InvokeOption waitSend;
|
||||
|
||||
/// <summary>
|
||||
/// 默认设置。
|
||||
/// WaitTime=5
|
||||
/// </summary>
|
||||
public static InvokeOption WaitSend { get { return waitSend; } }
|
||||
|
||||
private static InvokeOption waitInvoke;
|
||||
|
||||
private static InvokeOption waitSend;
|
||||
|
||||
private int timeout = 5000;
|
||||
|
||||
static InvokeOption()
|
||||
{
|
||||
onlySend = new InvokeOption();
|
||||
onlySend.FeedbackType = FeedbackType.OnlySend;
|
||||
|
||||
waitSend = new InvokeOption();
|
||||
waitSend.FeedbackType = FeedbackType.WaitSend;
|
||||
|
||||
waitInvoke = new InvokeOption();
|
||||
waitInvoke.FeedbackType = FeedbackType.WaitInvoke;
|
||||
}
|
||||
/// <summary>
|
||||
/// 默认设置。
|
||||
/// WaitTime=5
|
||||
/// Timeout=5000 ms
|
||||
/// </summary>
|
||||
public static InvokeOption OnlySend { get { return onlySend; } }
|
||||
/// <summary>
|
||||
/// 默认设置。
|
||||
/// Timeout=5000 ms
|
||||
/// </summary>
|
||||
public static InvokeOption WaitInvoke { get { return waitInvoke; } }
|
||||
|
||||
/// <summary>
|
||||
/// 调用等待时长
|
||||
/// 默认设置。
|
||||
/// Timeout=5000 ms
|
||||
/// </summary>
|
||||
public int WaitTime { get; set; }
|
||||
|
||||
public static InvokeOption WaitSend { get { return waitSend; } }
|
||||
/// <summary>
|
||||
/// 调用反馈
|
||||
/// </summary>
|
||||
public FeedbackType FeedbackType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 调用超时,
|
||||
/// min=1000,默认5000 ms
|
||||
/// </summary>
|
||||
public int Timeout
|
||||
{
|
||||
get { return timeout; }
|
||||
set
|
||||
{
|
||||
if (value < 1000)
|
||||
{
|
||||
value = 1000;
|
||||
}
|
||||
timeout = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
private Dictionary<string, MethodItem> methodKeyToMethodItem;
|
||||
internal Dictionary<Type, string> propertyDic;
|
||||
internal Dictionary<Type, string> genericTypeDic;
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的方法
|
||||
/// </summary>
|
||||
@@ -57,7 +58,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <param name="methodToken"></param>
|
||||
internal void RemoveMethodItem(int methodToken)
|
||||
{
|
||||
if (tokenToMethodItem.TryGetValue(methodToken,out MethodItem methodItem))
|
||||
if (tokenToMethodItem.TryGetValue(methodToken, out MethodItem methodItem))
|
||||
{
|
||||
tokenToMethodItem.Remove(methodToken);
|
||||
methodKeyToMethodItem.Remove(methodItem.Method);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// 代码辅助类
|
||||
/// </summary>
|
||||
public class PropertyCodeMap
|
||||
public class PropertyCodeGenerator
|
||||
{
|
||||
private static readonly string[] listType = { "List`1", "HashSet`1", "IList`1", "ISet`1", "ICollection`1", "IEnumerable`1" };
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public PropertyCodeMap(string nameSpace,MethodStore methodStore)
|
||||
public PropertyCodeGenerator(string nameSpace, MethodStore methodStore)
|
||||
{
|
||||
codeString = new StringBuilder();
|
||||
this.nameSpace = nameSpace;
|
||||
@@ -72,7 +72,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
|
||||
private StringBuilder codeString;
|
||||
private string nameSpace;
|
||||
private Dictionary<Type, string> propertyDic ;
|
||||
private Dictionary<Type, string> propertyDic;
|
||||
private Dictionary<Type, string> genericTypeDic;
|
||||
|
||||
internal void AddTypeString(Type type)
|
||||
@@ -177,7 +177,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
else if (type.IsClass)
|
||||
{
|
||||
if (type.Assembly == ServerProvider.DefaultAssembly||type.GetCustomAttribute<RRQMRPCMemberAttribute>()!=null)
|
||||
if (type.Assembly == ServerProvider.DefaultAssembly || type.GetCustomAttribute<RRQMRPCMemberAttribute>() != null)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
@@ -280,7 +280,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
Type[] ts = type.GetGenericArguments();
|
||||
if (ts.Length == 1)
|
||||
{
|
||||
return ts[0].Name;
|
||||
return ts[0].Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -297,7 +297,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
string typeName = type.FullName.Replace("&", string.Empty);
|
||||
type = Type.GetType(typeName);
|
||||
if (type == null&& ServerProvider.DefaultAssembly!=null)
|
||||
if (type == null && ServerProvider.DefaultAssembly != null)
|
||||
{
|
||||
type = ServerProvider.DefaultAssembly.GetType(typeName);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// RPC编译
|
||||
/// </summary>
|
||||
public static class RPCCompiler
|
||||
public static class RpcCompiler
|
||||
{
|
||||
private static List<string> RefStrings = new List<string>();
|
||||
|
||||
@@ -42,6 +42,15 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加编译引用
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
public static void AddRef(Type type)
|
||||
{
|
||||
AddRef(type.Assembly.FullName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除引用
|
||||
/// </summary>
|
||||
|
||||
@@ -11,16 +11,14 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using RRQMCore.ByteManager;
|
||||
using RRQMCore.Run;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
/// <summary>
|
||||
/// RPC传输类
|
||||
/// </summary>
|
||||
public class RPCContext : WaitResult
|
||||
public class RpcContext : WaitResult
|
||||
{
|
||||
internal int MethodToken;
|
||||
internal string ID;
|
||||
@@ -30,108 +28,45 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
|
||||
internal void Serialize(ByteBlock byteBlock)
|
||||
{
|
||||
byteBlock.Write(BitConverter.GetBytes(this.Sign));
|
||||
byteBlock.Write(this.Sign);
|
||||
byteBlock.Write(this.Status);
|
||||
byteBlock.Write(this.Feedback);
|
||||
byteBlock.Write(BitConverter.GetBytes(this.MethodToken));
|
||||
if (!string.IsNullOrEmpty(ID))
|
||||
{
|
||||
byte[] idBytes = Encoding.UTF8.GetBytes(this.ID);
|
||||
byteBlock.Write((byte)idBytes.Length);
|
||||
byteBlock.Write(idBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
byteBlock.Write(0);
|
||||
}
|
||||
if (this.Message != null)
|
||||
{
|
||||
byte[] mesBytes = Encoding.UTF8.GetBytes(this.Message);
|
||||
byteBlock.Write((byte)mesBytes.Length);
|
||||
byteBlock.Write(mesBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
byteBlock.Write(0);
|
||||
}
|
||||
byteBlock.Write(this.MethodToken);
|
||||
byteBlock.Write(this.ID);
|
||||
byteBlock.Write(this.Message);
|
||||
byteBlock.WriteBytesPackage(this.ReturnParameterBytes);
|
||||
|
||||
if (this.ReturnParameterBytes != null)
|
||||
{
|
||||
byteBlock.Write(BitConverter.GetBytes(this.ReturnParameterBytes.Length));
|
||||
byteBlock.Write(this.ReturnParameterBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
byteBlock.Write(BitConverter.GetBytes(0));
|
||||
}
|
||||
|
||||
if (this.ParametersBytes != null)
|
||||
if (this.ParametersBytes != null && this.ParametersBytes.Count > 0)
|
||||
{
|
||||
byteBlock.Write((byte)this.ParametersBytes.Count);
|
||||
foreach (byte[] item in this.ParametersBytes)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
byteBlock.Write(BitConverter.GetBytes(item.Length));
|
||||
byteBlock.Write(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
byteBlock.Write(BitConverter.GetBytes(0));
|
||||
}
|
||||
byteBlock.WriteBytesPackage(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
byteBlock.Write(0);
|
||||
byteBlock.Write((byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
internal static RPCContext Deserialize(byte[] buffer, int offset)
|
||||
internal static RpcContext Deserialize(ByteBlock byteBlock)
|
||||
{
|
||||
RPCContext context = new RPCContext();
|
||||
context.Sign = BitConverter.ToInt32(buffer, offset);
|
||||
offset += 4;
|
||||
context.Status = buffer[offset];
|
||||
offset += 1;
|
||||
context.Feedback = buffer[offset];
|
||||
offset += 1;
|
||||
context.MethodToken = BitConverter.ToInt32(buffer, offset);
|
||||
offset += 4;
|
||||
int lenID = buffer[offset];
|
||||
offset += 1;
|
||||
context.ID = Encoding.UTF8.GetString(buffer, offset, lenID);
|
||||
offset += lenID;
|
||||
int lenMes = buffer[offset];
|
||||
offset += 1;
|
||||
context.Message = Encoding.UTF8.GetString(buffer, offset, lenMes);
|
||||
offset += lenMes;
|
||||
int lenRet = BitConverter.ToInt32(buffer, offset);
|
||||
offset += 4;
|
||||
if (lenRet > 0)
|
||||
{
|
||||
context.ReturnParameterBytes = new byte[lenRet];
|
||||
Array.Copy(buffer, offset, context.ReturnParameterBytes, 0, lenRet);
|
||||
}
|
||||
offset += lenRet;
|
||||
RpcContext context = new RpcContext();
|
||||
context.Sign = byteBlock.ReadInt32();
|
||||
context.Status = byteBlock.ReadByte();
|
||||
context.Feedback = byteBlock.ReadByte();
|
||||
context.MethodToken = byteBlock.ReadInt32();
|
||||
context.ID = byteBlock.ReadString();
|
||||
context.Message = byteBlock.ReadString();
|
||||
context.ReturnParameterBytes = byteBlock.ReadBytesPackage();
|
||||
|
||||
context.ParametersBytes = new List<byte[]>();
|
||||
int countPar = buffer[offset];
|
||||
offset += 1;
|
||||
byte countPar = byteBlock.ReadByte();
|
||||
|
||||
for (int i = 0; i < countPar; i++)
|
||||
{
|
||||
int lenPar = BitConverter.ToInt32(buffer, offset);
|
||||
offset += 4;
|
||||
if (lenPar > 0)
|
||||
{
|
||||
byte[] datas = new byte[lenPar];
|
||||
Array.Copy(buffer, offset, datas, 0, lenPar);
|
||||
offset += lenPar;
|
||||
context.ParametersBytes.Add(datas);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.ParametersBytes.Add(null);
|
||||
}
|
||||
context.ParametersBytes.Add(byteBlock.ReadBytesPackage());
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// RPC代理文件程序
|
||||
/// </summary>
|
||||
public class RPCProxyInfo : WaitResult
|
||||
public class RpcProxyInfo : WaitResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 程序名
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
|
||||
// CSDN博客:https://blog.csdn.net/qq_40374647
|
||||
// 哔哩哔哩视频:https://space.bilibili.com/94253567
|
||||
// Gitee源代码仓库:https://gitee.com/RRQM_Home
|
||||
// Github源代码仓库:https://github.com/RRQM
|
||||
// 交流QQ群:234762506
|
||||
// 感谢您的下载和使用
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
/// <summary>
|
||||
/// 回调函数载体
|
||||
/// </summary>
|
||||
public class RpcCallBackContext
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -26,12 +26,12 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
string nameSpaceOld,
|
||||
ref MethodStore methodStore,
|
||||
Version version,
|
||||
ref RPCProxyInfo proxyInfo)
|
||||
ref RpcProxyInfo proxyInfo)
|
||||
{
|
||||
string nameSpace = string.IsNullOrEmpty(nameSpaceOld) ? "RRQMRPC" : $"RRQMRPC.{nameSpaceOld}";
|
||||
List<string> refs = new List<string>();
|
||||
|
||||
PropertyCodeMap propertyCode = new PropertyCodeMap(nameSpace, methodStore);
|
||||
PropertyCodeGenerator propertyCode = new PropertyCodeGenerator(nameSpace, methodStore);
|
||||
|
||||
foreach (MethodInstance methodInstance in methodInstances)
|
||||
{
|
||||
@@ -58,7 +58,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
#if NET45_OR_GREATER
|
||||
foreach (var item in refs)
|
||||
{
|
||||
RPCCompiler.AddRef(item);
|
||||
RpcCompiler.AddRef(item);
|
||||
}
|
||||
#endif
|
||||
List<MethodInfo> methods = new List<MethodInfo>();
|
||||
@@ -98,11 +98,10 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
}
|
||||
|
||||
CodeMap.Namespace = nameSpace;
|
||||
CodeMap.PropertyCode = propertyCode;
|
||||
CodeGenerator.Namespace = nameSpace;
|
||||
CodeGenerator.PropertyCode = propertyCode;
|
||||
|
||||
|
||||
CodeMap codeMap = new CodeMap();
|
||||
CodeGenerator codeMap = new CodeGenerator();
|
||||
codeMap.ClassName = className;
|
||||
codeMap.Methods = methods.ToArray();
|
||||
|
||||
@@ -140,7 +139,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
private static int ExistReturnNullParameters = 500000000;
|
||||
private static int ExistReturnExistParameters = 700000000;
|
||||
|
||||
internal static MethodInstance[] GetMethodInstances(ServerProvider serverProvider, bool isSetToken)
|
||||
internal static MethodInstance[] GetMethodInstances(IServerProvider serverProvider, bool isSetToken)
|
||||
{
|
||||
List<MethodInstance> instances = new List<MethodInstance>();
|
||||
|
||||
@@ -150,7 +149,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
if (method.IsGenericMethod)
|
||||
{
|
||||
throw new RRQMRPCException("RPC方法中不支持泛型参数");
|
||||
continue;
|
||||
}
|
||||
IEnumerable<RPCAttribute> attributes = method.GetCustomAttributes<RPCAttribute>(true);
|
||||
if (attributes.Count() > 0)
|
||||
@@ -184,7 +183,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
methodInstance.ParameterTypes = types.ToArray();
|
||||
|
||||
if (method.ReturnType == typeof(void)|| method.ReturnType==typeof(Task))
|
||||
if (method.ReturnType == typeof(void) || method.ReturnType == typeof(Task))
|
||||
{
|
||||
methodInstance.ReturnType = null;
|
||||
|
||||
@@ -199,7 +198,6 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
methodInstance.MethodToken = ++nullReturnExistParameters;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -233,7 +231,6 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
}
|
||||
instances.Add(methodInstance);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// TcpRPCClient配置
|
||||
/// </summary>
|
||||
public class TcpRPCClientConfig : ProtocolClientConfig
|
||||
public class TcpRpcClientConfig : ProtocolClientConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 代理文件令箭
|
||||
@@ -31,7 +31,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// 代理文件令箭, 所需类型<see cref="string"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty ProxyTokenProperty =
|
||||
DependencyProperty.Register("ProxyToken", typeof(string), typeof(TcpRPCClientConfig), null);
|
||||
DependencyProperty.Register("ProxyToken", typeof(string), typeof(TcpRpcClientConfig), null);
|
||||
|
||||
/// <summary>
|
||||
/// 序列化转换器
|
||||
@@ -46,6 +46,6 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// 序列化转换器, 所需类型<see cref="RRQMRPC.SerializeConverter"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty SerializeConverterProperty =
|
||||
DependencyProperty.Register("SerializeConverter", typeof(SerializeConverter), typeof(TcpRPCClientConfig), new BinarySerializeConverter());
|
||||
DependencyProperty.Register("SerializeConverter", typeof(SerializeConverter), typeof(TcpRpcClientConfig), new BinarySerializeConverter());
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// RRQMRPC解析器配置
|
||||
/// </summary>
|
||||
public class TcpRPCParserConfig : ProtocolServiceConfig
|
||||
public class TcpRpcParserConfig : ProtocolServiceConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 序列化转换器
|
||||
@@ -32,7 +32,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// 序列化转换器, 所需类型<see cref="RRQMRPC.SerializeConverter"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty SerializeConverterProperty =
|
||||
DependencyProperty.Register("SerializeConverter", typeof(SerializeConverter), typeof(TcpRPCParserConfig), new BinarySerializeConverter());
|
||||
DependencyProperty.Register("SerializeConverter", typeof(SerializeConverter), typeof(TcpRpcParserConfig), new BinarySerializeConverter());
|
||||
|
||||
/// <summary>
|
||||
/// 代理源文件命名空间
|
||||
@@ -47,7 +47,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// 代理源文件命名空间, 所需类型<see cref="string"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty NameSpaceProperty =
|
||||
DependencyProperty.Register("NameSpace", typeof(string), typeof(TcpRPCParserConfig), null);
|
||||
DependencyProperty.Register("NameSpace", typeof(string), typeof(TcpRpcParserConfig), null);
|
||||
|
||||
/// <summary>
|
||||
/// RPC代理版本
|
||||
@@ -62,8 +62,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// RPC代理版本, 所需类型<see cref="Version"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty RPCVersionProperty =
|
||||
DependencyProperty.Register("RPCVersion", typeof(Version), typeof(TcpRPCParserConfig), null);
|
||||
|
||||
DependencyProperty.Register("RPCVersion", typeof(Version), typeof(TcpRpcParserConfig), null);
|
||||
|
||||
/// <summary>
|
||||
/// 代理令箭,当客户端获取代理文件时需验证令箭
|
||||
@@ -78,6 +77,6 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// 代理令箭,当客户端获取代理文件时需验证令箭, 所需类型<see cref="string"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty ProxyTokenProperty =
|
||||
DependencyProperty.Register("ProxyToken", typeof(string), typeof(TcpRPCParserConfig), null);
|
||||
DependencyProperty.Register("ProxyToken", typeof(string), typeof(TcpRpcParserConfig), null);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// UdpRpc
|
||||
/// </summary>
|
||||
public class UdpRPCClientConfig : UdpSessionConfig
|
||||
public class UdpRpcClientConfig : UdpSessionConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 代理文件令箭
|
||||
@@ -31,7 +31,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// 代理文件令箭, 所需类型<see cref="string"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty ProxyTokenProperty =
|
||||
DependencyProperty.Register("ProxyToken", typeof(string), typeof(UdpRPCClientConfig), null);
|
||||
DependencyProperty.Register("ProxyToken", typeof(string), typeof(UdpRpcClientConfig), null);
|
||||
|
||||
/// <summary>
|
||||
/// 序列化转换器
|
||||
@@ -46,6 +46,6 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// 序列化转换器, 所需类型<see cref="RRQMRPC.SerializeConverter"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty SerializeConverterProperty =
|
||||
DependencyProperty.Register("SerializeConverter", typeof(SerializeConverter), typeof(UdpRPCClientConfig), new BinarySerializeConverter());
|
||||
DependencyProperty.Register("SerializeConverter", typeof(SerializeConverter), typeof(UdpRpcClientConfig), new BinarySerializeConverter());
|
||||
}
|
||||
}
|
||||
@@ -11,37 +11,37 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using RRQMCore.Dependency;
|
||||
using System;
|
||||
|
||||
|
||||
namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
/// <summary>
|
||||
/// UdpRPCParser
|
||||
/// </summary>
|
||||
public class UdpRPCParserConfig : UdpSessionConfig
|
||||
public class UdpRpcParserConfig : UdpSessionConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 代理源文件命名空间, 所需类型<see cref="string"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty NameSpaceProperty =
|
||||
DependencyProperty.Register("NameSpace", typeof(string), typeof(UdpRPCParserConfig), null);
|
||||
DependencyProperty.Register("NameSpace", typeof(string), typeof(UdpRpcParserConfig), null);
|
||||
|
||||
/// <summary>
|
||||
/// 代理令箭,当客户端获取代理文件时需验证令箭, 所需类型<see cref="string"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty ProxyTokenProperty =
|
||||
DependencyProperty.Register("ProxyToken", typeof(string), typeof(UdpRPCParserConfig), null);
|
||||
DependencyProperty.Register("ProxyToken", typeof(string), typeof(UdpRpcParserConfig), null);
|
||||
|
||||
/// <summary>
|
||||
/// RPC代理版本, 所需类型<see cref="Version"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty RPCVersionProperty =
|
||||
DependencyProperty.Register("RPCVersion", typeof(Version), typeof(UdpRPCParserConfig), null);
|
||||
DependencyProperty.Register("RPCVersion", typeof(Version), typeof(UdpRpcParserConfig), null);
|
||||
|
||||
/// <summary>
|
||||
/// 序列化转换器, 所需类型<see cref="RRQMRPC.SerializeConverter"/>
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty SerializeConverterProperty =
|
||||
DependencyProperty.Register("SerializeConverter", typeof(SerializeConverter), typeof(UdpRPCParserConfig), new BinarySerializeConverter());
|
||||
DependencyProperty.Register("SerializeConverter", typeof(SerializeConverter), typeof(UdpRpcParserConfig), new BinarySerializeConverter());
|
||||
|
||||
/// <summary>
|
||||
/// 代理源文件命名空间
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
|
||||
// CSDN博客:https://blog.csdn.net/qq_40374647
|
||||
// 哔哩哔哩视频:https://space.bilibili.com/94253567
|
||||
// Gitee源代码仓库:https://gitee.com/RRQM_Home
|
||||
// Github源代码仓库:https://github.com/RRQM
|
||||
// 交流QQ群:234762506
|
||||
// 感谢您的下载和使用
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using RRQMCore.Exceptions;
|
||||
|
||||
namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
/// <summary>
|
||||
/// 无可用RPC异常
|
||||
/// </summary>
|
||||
public class RRQMRPCNoFreeException : RRQMException
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public RRQMRPCNoFreeException() : base() { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public RRQMRPCNoFreeException(string message) : base(message) { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="inner"></param>
|
||||
public RRQMRPCNoFreeException(string message, System.Exception inner) : base(message, inner) { }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
/// <param name="context"></param>
|
||||
protected RRQMRPCNoFreeException(System.Runtime.Serialization.SerializationInfo info,
|
||||
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// 客户端RPC接口
|
||||
/// </summary>
|
||||
public interface IRPCClient : IDisposable
|
||||
public interface IRpcClient : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 函数式调用
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// 客户端RPC接口
|
||||
/// </summary>
|
||||
public interface IRRQMRPCClient : IRPCClient
|
||||
public interface IRRQMRpcClient : IRpcClient
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取ID
|
||||
@@ -27,7 +27,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// 日志记录器
|
||||
/// </summary>
|
||||
ILog Logger { get; set; }
|
||||
ILog Logger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取内存池实例
|
||||
@@ -45,7 +45,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <returns></returns>
|
||||
/// <exception cref="RRQMRPCException"></exception>
|
||||
/// <exception cref="RRQMTimeoutException"></exception>
|
||||
RPCProxyInfo GetProxyInfo();
|
||||
RpcProxyInfo GetProxyInfo();
|
||||
|
||||
/// <summary>
|
||||
/// 服务发现完成后
|
||||
@@ -57,6 +57,6 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// </summary>
|
||||
/// <param name="isTrigger">是否触发初始化事件</param>
|
||||
/// <returns>已发现的服务</returns>
|
||||
MethodItem[] DiscoveryService(bool isTrigger=true);
|
||||
MethodItem[] DiscoveryService(bool isTrigger = true);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// RRQMRPC接口
|
||||
/// </summary>
|
||||
public interface IRRQMRPCParser
|
||||
public interface IRRQMRpcParser
|
||||
{
|
||||
/// <summary>
|
||||
/// 内存池实例
|
||||
@@ -39,7 +39,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// 获取代理文件实例
|
||||
/// </summary>
|
||||
RPCProxyInfo ProxyInfo { get; }
|
||||
RpcProxyInfo ProxyInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 函数库
|
||||
@@ -67,14 +67,14 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <param name="proxyToken">代理令箭</param>
|
||||
/// <param name="caller">调用作用者,TCP模式下派生自<see cref="RPCSocketClient"/>,UDP模式下是<see cref="EndPoint"/></param>
|
||||
/// <returns></returns>
|
||||
RPCProxyInfo GetProxyInfo(string proxyToken, object caller);
|
||||
RpcProxyInfo GetProxyInfo(string proxyToken, object caller);
|
||||
|
||||
/// <summary>
|
||||
/// 执行函数
|
||||
/// </summary>
|
||||
/// <param name="context">函数内容</param>
|
||||
/// <param name="caller">调用作用者,TCP模式下派生自<see cref="RPCSocketClient"/>,UDP模式下是<see cref="EndPoint"/></param>
|
||||
void ExecuteContext(RPCContext context, object caller);
|
||||
void ExecuteContext(RpcContext context, object caller);
|
||||
|
||||
/// <summary>
|
||||
/// 获取注册函数
|
||||
@@ -85,12 +85,13 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
List<MethodItem> GetRegisteredMethodItems(string proxyToken, object caller);
|
||||
|
||||
#if NET45_OR_GREATER
|
||||
|
||||
/// <summary>
|
||||
/// 编译代理
|
||||
/// </summary>
|
||||
/// <param name="targetDic">存放目标文件夹</param>
|
||||
void CompilerProxy(string targetDic = "");
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权(除特别声明或在RRQMCore.XREF命名空间的代码)归作者本人若汝棋茗所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权
|
||||
// CSDN博客:https://blog.csdn.net/qq_40374647
|
||||
// 哔哩哔哩视频:https://space.bilibili.com/94253567
|
||||
// Gitee源代码仓库:https://gitee.com/RRQM_Home
|
||||
// Github源代码仓库:https://github.com/RRQM
|
||||
// 交流QQ群:234762506
|
||||
// 感谢您的下载和使用
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using RRQMCore.XREF.Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
/// <summary>
|
||||
/// Json序列化转化器
|
||||
/// </summary>
|
||||
public class JsonSerializeConverter : RRQMSocket.RPC.RRQMRPC.SerializeConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// 反序列化
|
||||
/// </summary>
|
||||
/// <param name="parameterBytes"></param>
|
||||
/// <param name="parameterType"></param>
|
||||
/// <returns></returns>
|
||||
public override object DeserializeParameter(byte[] parameterBytes, Type parameterType)
|
||||
{
|
||||
if (parameterBytes == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(parameterBytes), parameterType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 序列化
|
||||
/// </summary>
|
||||
/// <param name="parameter"></param>
|
||||
/// <returns></returns>
|
||||
public override byte[] SerializeParameter(object parameter)
|
||||
{
|
||||
if (parameter == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(parameter));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,22 +33,26 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
AddUsedProtocol(102, "获取注册服务");
|
||||
AddUsedProtocol(103, "ID调用客户端");
|
||||
AddUsedProtocol(104, "RPC回调");
|
||||
for (short i = 105; i < 110; i++)
|
||||
{
|
||||
AddUsedProtocol(i, "保留协议");
|
||||
}
|
||||
}
|
||||
|
||||
internal Func<RPCSocketClient, RPCContext, RPCContext> IDAction;
|
||||
internal Func<RPCSocketClient, RpcContext, RpcContext> IDAction;
|
||||
|
||||
internal RRQMReceivedProcotolEventHandler Received;
|
||||
|
||||
internal SerializeConverter serializeConverter;
|
||||
|
||||
internal RRQMWaitHandle<RPCContext> waitHandle;
|
||||
internal RRQMWaitHandle<RpcContext> waitHandle;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public RPCSocketClient()
|
||||
{
|
||||
waitHandle = new RRQMWaitHandle<RPCContext>();
|
||||
waitHandle = new RRQMWaitHandle<RpcContext>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -61,8 +65,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <returns></returns>
|
||||
public T CallBack<T>(int methodToken, InvokeOption invokeOption = null, params object[] parameters)
|
||||
{
|
||||
RPCContext context = new RPCContext();
|
||||
WaitData<RPCContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<RpcContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
|
||||
context.MethodToken = methodToken;
|
||||
|
||||
@@ -77,7 +81,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
List<byte[]> datas = new List<byte[]>();
|
||||
foreach (object parameter in parameters)
|
||||
{
|
||||
datas.Add(this.serializeConverter.SerializeParameter (parameter));
|
||||
datas.Add(this.serializeConverter.SerializeParameter(parameter));
|
||||
}
|
||||
context.ParametersBytes = datas;
|
||||
context.Serialize(byteBlock);
|
||||
@@ -102,9 +106,9 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
if (resultContext.Status == 0)
|
||||
{
|
||||
@@ -114,9 +118,9 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
if (resultContext.Status == 0)
|
||||
{
|
||||
@@ -157,8 +161,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <param name="parameters"></param>
|
||||
public void CallBack(int methodToken, InvokeOption invokeOption = null, params object[] parameters)
|
||||
{
|
||||
RPCContext context = new RPCContext();
|
||||
WaitData<RPCContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<RpcContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
|
||||
context.MethodToken = methodToken;
|
||||
|
||||
@@ -197,9 +201,9 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
if (resultContext.Status == 0)
|
||||
{
|
||||
@@ -209,9 +213,9 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
if (resultContext.Status == 0)
|
||||
{
|
||||
@@ -242,10 +246,10 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <param name="invokeContext"></param>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public byte[] CallBack(RPCContext invokeContext, int timeout)
|
||||
public byte[] CallBack(RpcContext invokeContext, int timeout)
|
||||
{
|
||||
RPCContext context = new RPCContext();
|
||||
WaitData<RPCContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<RpcContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = invokeContext.MethodToken;
|
||||
|
||||
ByteBlock byteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
@@ -278,7 +282,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
waitData.Wait(timeout * 1000);
|
||||
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
if (resultContext.Status == 0)
|
||||
{
|
||||
@@ -290,7 +294,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
waitData.Wait(timeout * 1000);
|
||||
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
if (resultContext.Status == 0)
|
||||
{
|
||||
@@ -344,7 +348,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
try
|
||||
{
|
||||
string proxyToken = Encoding.UTF8.GetString(buffer, 2, r - 2);
|
||||
byte[] data = SerializeConvert.RRQMBinarySerialize(((IRRQMRPCParser)this.Service).GetProxyInfo(proxyToken, this), true);
|
||||
byte[] data = SerializeConvert.RRQMBinarySerialize(((IRRQMRpcParser)this.Service).GetProxyInfo(proxyToken, this), true);
|
||||
this.InternalSend(100, data, 0, data.Length);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -357,12 +361,13 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
try
|
||||
{
|
||||
RPCContext content = RPCContext.Deserialize(buffer, 2);
|
||||
byteBlock.Pos = 2;
|
||||
RpcContext content = RpcContext.Deserialize(byteBlock);
|
||||
if (content.Feedback == 1)
|
||||
{
|
||||
List<byte[]> ps = content.ParametersBytes;
|
||||
|
||||
ByteBlock returnByteBlock = this.BytePool.GetByteBlock(this.bufferLength);
|
||||
ByteBlock returnByteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
try
|
||||
{
|
||||
content.ParametersBytes = null;
|
||||
@@ -376,7 +381,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
returnByteBlock.Dispose();
|
||||
}
|
||||
}
|
||||
((IRRQMRPCParser)this.Service).ExecuteContext(content, this);
|
||||
((IRRQMRpcParser)this.Service).ExecuteContext(content, this);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -389,7 +394,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
try
|
||||
{
|
||||
string proxyToken = Encoding.UTF8.GetString(buffer, 2, r - 2);
|
||||
byte[] data = SerializeConvert.RRQMBinarySerialize(((IRRQMRPCParser)this.Service).GetRegisteredMethodItems(proxyToken, this), true);
|
||||
byte[] data = SerializeConvert.RRQMBinarySerialize(((IRRQMRpcParser)this.Service).GetRegisteredMethodItems(proxyToken, this), true);
|
||||
this.InternalSend(102, data, 0, data.Length);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -404,7 +409,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
try
|
||||
{
|
||||
RPCContext content = RPCContext.Deserialize(buffer, 2);
|
||||
byteBlock.Pos = 2;
|
||||
RpcContext content = RpcContext.Deserialize(byteBlock);
|
||||
content = this.IDAction(this, content);
|
||||
|
||||
ByteBlock retuenByteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
@@ -429,7 +435,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
try
|
||||
{
|
||||
RPCContext content = RPCContext.Deserialize(buffer, 2);
|
||||
byteBlock.Pos = 2;
|
||||
RpcContext content = RpcContext.Deserialize(byteBlock);
|
||||
this.waitHandle.SetRun(content);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
// 感谢您的下载和使用
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
using RRQMCore;
|
||||
using RRQMCore.ByteManager;
|
||||
using RRQMCore.Log;
|
||||
using System;
|
||||
@@ -22,7 +21,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// TcpRPCParser泛型类型
|
||||
/// </summary>
|
||||
/// <typeparam name="TClient"></typeparam>
|
||||
public class TcpParser<TClient> : ProtocolService<TClient>, IRPCParser, IRRQMRPCParser where TClient : RPCSocketClient, new()
|
||||
public class TcpParser<TClient> : ProtocolService<TClient>, IRPCParser, IRRQMRpcParser where TClient : RPCSocketClient, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
@@ -30,7 +29,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
public TcpParser()
|
||||
{
|
||||
this.methodStore = new MethodStore();
|
||||
this.proxyInfo = new RPCProxyInfo();
|
||||
this.proxyInfo = new RpcProxyInfo();
|
||||
}
|
||||
|
||||
#pragma warning disable
|
||||
@@ -41,11 +40,11 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
|
||||
public Action<IRPCParser, MethodInvoker, MethodInstance> RRQMExecuteMethod { get; private set; }
|
||||
|
||||
public CellCode[] Codes { get => this.proxyInfo==null?null:this.proxyInfo.Codes.ToArray(); }
|
||||
public CellCode[] Codes { get => this.proxyInfo == null ? null : this.proxyInfo.Codes.ToArray(); }
|
||||
|
||||
public string NameSpace { get; private set; }
|
||||
|
||||
public RPCProxyInfo ProxyInfo { get => proxyInfo; }
|
||||
public RpcProxyInfo ProxyInfo { get => proxyInfo; }
|
||||
|
||||
public string ProxyToken { get; private set; }
|
||||
|
||||
@@ -54,13 +53,14 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
public SerializeConverter SerializeConverter { get; private set; }
|
||||
|
||||
private MethodStore methodStore;
|
||||
private RPCProxyInfo proxyInfo;
|
||||
|
||||
private RpcProxyInfo proxyInfo;
|
||||
|
||||
public MethodStore MethodStore { get => methodStore; }
|
||||
|
||||
public void OnEndInvoke(MethodInvoker methodInvoker, MethodInstance methodInstance)
|
||||
{
|
||||
RPCContext context = (RPCContext)methodInvoker.Flag;
|
||||
RpcContext context = (RpcContext)methodInvoker.Flag;
|
||||
if (context.Feedback != 2)
|
||||
{
|
||||
return;
|
||||
@@ -147,32 +147,31 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
}
|
||||
|
||||
public void OnRegisterServer(ServerProvider provider, MethodInstance[] methodInstances)
|
||||
public void OnRegisterServer(IServerProvider provider, MethodInstance[] methodInstances)
|
||||
{
|
||||
Tools.GetRPCMethod(methodInstances, this.NameSpace, ref this.methodStore, this.RPCVersion, ref this.proxyInfo);
|
||||
}
|
||||
|
||||
public void OnUnregisterServer(ServerProvider provider, MethodInstance[] methodInstances)
|
||||
public void OnUnregisterServer(IServerProvider provider, MethodInstance[] methodInstances)
|
||||
{
|
||||
foreach (var item in methodInstances)
|
||||
{
|
||||
this.methodStore.RemoveMethodItem(item.MethodToken);
|
||||
}
|
||||
|
||||
CellCode cellCode=null;
|
||||
CellCode cellCode = null;
|
||||
foreach (var item in this.proxyInfo.Codes)
|
||||
{
|
||||
if (item.Name==provider.GetType().Name)
|
||||
if (item.Name == provider.GetType().Name)
|
||||
{
|
||||
cellCode = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cellCode!=null)
|
||||
if (cellCode != null)
|
||||
{
|
||||
this.proxyInfo.Codes.Remove(cellCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SetExecuteMethod(Action<IRPCParser, MethodInvoker, MethodInstance> executeMethod)
|
||||
@@ -189,24 +188,27 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
this.RPCService = service;
|
||||
}
|
||||
|
||||
#if NET45_OR_GREATER
|
||||
|
||||
/// <summary>
|
||||
/// 编译代理
|
||||
/// </summary>
|
||||
/// <param name="targetDic">存放目标文件夹</param>
|
||||
public void CompilerProxy(string targetDic = "")
|
||||
{
|
||||
string assemblyInfo = CodeMap.GetAssemblyInfo(this.proxyInfo.AssemblyName, this.proxyInfo.Version);
|
||||
string assemblyInfo = CodeGenerator.GetAssemblyInfo(this.proxyInfo.AssemblyName, this.proxyInfo.Version);
|
||||
List<string> codesString = new List<string>();
|
||||
codesString.Add(assemblyInfo);
|
||||
foreach (var item in this.proxyInfo.Codes)
|
||||
{
|
||||
codesString.Add(item.Code);
|
||||
}
|
||||
RPCCompiler.CompileCode(Path.Combine(targetDic, this.proxyInfo.AssemblyName), codesString.ToArray());
|
||||
|
||||
RpcCompiler.CompileCode(Path.Combine(targetDic, this.proxyInfo.AssemblyName), codesString.ToArray());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
protected override void OnCreateSocketCliect(TClient socketClient, CreateOption createOption)
|
||||
{
|
||||
if (createOption.NewCreate)
|
||||
@@ -222,9 +224,9 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
this.Received?.Invoke(sender, procotol, byteBlock);
|
||||
}
|
||||
|
||||
public virtual RPCProxyInfo GetProxyInfo(string proxyToken, object caller)
|
||||
public virtual RpcProxyInfo GetProxyInfo(string proxyToken, object caller)
|
||||
{
|
||||
RPCProxyInfo proxyInfo = new RPCProxyInfo();
|
||||
RpcProxyInfo proxyInfo = new RpcProxyInfo();
|
||||
if (this.ProxyToken == proxyToken)
|
||||
{
|
||||
proxyInfo.AssemblyData = this.ProxyInfo.AssemblyData;
|
||||
@@ -242,7 +244,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
return proxyInfo;
|
||||
}
|
||||
|
||||
public virtual void ExecuteContext(RPCContext context, object caller)
|
||||
public virtual void ExecuteContext(RpcContext context, object caller)
|
||||
{
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.Caller = caller;
|
||||
@@ -283,10 +285,10 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
protected override void LoadConfig(ServiceConfig ServiceConfig)
|
||||
{
|
||||
base.LoadConfig(ServiceConfig);
|
||||
this.SerializeConverter = (SerializeConverter)ServiceConfig.GetValue(TcpRPCParserConfig.SerializeConverterProperty);
|
||||
this.ProxyToken = (string)ServiceConfig.GetValue(TcpRPCParserConfig.ProxyTokenProperty);
|
||||
this.NameSpace = (string)ServiceConfig.GetValue(TcpRPCParserConfig.NameSpaceProperty);
|
||||
this.RPCVersion = (Version)ServiceConfig.GetValue(TcpRPCParserConfig.RPCVersionProperty);
|
||||
this.SerializeConverter = (SerializeConverter)ServiceConfig.GetValue(TcpRpcParserConfig.SerializeConverterProperty);
|
||||
this.ProxyToken = (string)ServiceConfig.GetValue(TcpRpcParserConfig.ProxyTokenProperty);
|
||||
this.NameSpace = (string)ServiceConfig.GetValue(TcpRpcParserConfig.NameSpaceProperty);
|
||||
this.RPCVersion = (Version)ServiceConfig.GetValue(TcpRpcParserConfig.RPCVersionProperty);
|
||||
}
|
||||
|
||||
public virtual List<MethodItem> GetRegisteredMethodItems(string proxyToken, object caller)
|
||||
@@ -298,7 +300,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
return null;
|
||||
}
|
||||
|
||||
private RPCContext IDInvoke(RPCSocketClient socketClient, RPCContext context)
|
||||
private RpcContext IDInvoke(RPCSocketClient socketClient, RpcContext context)
|
||||
{
|
||||
if (this.TryGetSocketClient(context.ID, out TClient targetsocketClient))
|
||||
{
|
||||
@@ -367,5 +369,6 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
throw new RRQMRPCException("未找到该客户端");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,13 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// TcpRPCClient
|
||||
/// </summary>
|
||||
public class TcpRPCClient : ProtocolClient, IRRQMRPCClient
|
||||
public class TcpRpcClient : ProtocolClient, IRRQMRpcClient
|
||||
{
|
||||
private MethodMap methodMap;
|
||||
|
||||
private MethodStore methodStore;
|
||||
|
||||
private RPCProxyInfo proxyFile;
|
||||
private RpcProxyInfo proxyFile;
|
||||
|
||||
private ServerProviderCollection serverProviders;
|
||||
|
||||
@@ -40,19 +40,24 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
|
||||
private RRQMWaitHandle<WaitResult> waitHandle;
|
||||
|
||||
static TcpRPCClient()
|
||||
static TcpRpcClient()
|
||||
{
|
||||
AddUsedProtocol(100, "请求RPC代理文件");
|
||||
AddUsedProtocol(101, "RPC调用");
|
||||
AddUsedProtocol(102, "获取注册服务");
|
||||
AddUsedProtocol(103, "ID调用客户端");
|
||||
AddUsedProtocol(104, "RPC回调");
|
||||
|
||||
for (short i = 105; i < 110; i++)
|
||||
{
|
||||
AddUsedProtocol(i, "保留协议");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public TcpRPCClient()
|
||||
public TcpRpcClient()
|
||||
{
|
||||
this.methodMap = new MethodMap();
|
||||
this.serverProviders = new ServerProviderCollection();
|
||||
@@ -97,9 +102,9 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// </summary>
|
||||
/// <exception cref="RRQMRPCException"></exception>
|
||||
/// <exception cref="RRQMTimeoutException"></exception>
|
||||
public RPCProxyInfo GetProxyInfo()
|
||||
public RpcProxyInfo GetProxyInfo()
|
||||
{
|
||||
string proxyToken = (string)this.ClientConfig.GetValue(TcpRPCClientConfig.ProxyTokenProperty);
|
||||
string proxyToken = (string)this.ClientConfig.GetValue(TcpRpcClientConfig.ProxyTokenProperty);
|
||||
byte[] data = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(proxyToken) ? string.Empty : proxyToken);
|
||||
this.InternalSend(100, data, 0, data.Length);
|
||||
this.singleWaitData.Wait(1000 * 10);
|
||||
@@ -131,7 +136,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
try
|
||||
{
|
||||
this.methodStore = null;
|
||||
string proxyToken = (string)this.clientConfig.GetValue(TcpRPCClientConfig.ProxyTokenProperty);
|
||||
string proxyToken = (string)this.clientConfig.GetValue(TcpRpcClientConfig.ProxyTokenProperty);
|
||||
byte[] data = new byte[0];
|
||||
if (!string.IsNullOrEmpty(proxyToken))
|
||||
{
|
||||
@@ -176,7 +181,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMRPCNoRegisterException($"服务名为{method}的服务未找到注册信息");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<WaitResult> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodItem.MethodToken;
|
||||
ByteBlock byteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
@@ -195,7 +200,24 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
context.ParametersBytes = datas;
|
||||
context.Serialize(byteBlock);
|
||||
this.InternalSend(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
|
||||
switch (invokeOption.FeedbackType)
|
||||
{
|
||||
case FeedbackType.OnlySend:
|
||||
{
|
||||
this.InternalSendAsync(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
}
|
||||
break;
|
||||
case FeedbackType.WaitSend:
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
this.InternalSend(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -215,8 +237,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -230,8 +252,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -252,7 +274,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
else if (resultContext.Status == 5)
|
||||
{
|
||||
throw new RRQMRPCInvokeException("函数执行异常,详细信息:"+resultContext.Message);
|
||||
throw new RRQMRPCInvokeException("函数执行异常,详细信息:" + resultContext.Message);
|
||||
}
|
||||
else if (resultContext.Status == 6)
|
||||
{
|
||||
@@ -308,7 +330,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMRPCNoRegisterException($"服务名为{method}的服务未找到注册信息");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<WaitResult> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodItem.MethodToken;
|
||||
ByteBlock byteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
@@ -326,7 +348,22 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
context.ParametersBytes = datas;
|
||||
context.Serialize(byteBlock);
|
||||
this.InternalSend(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
switch (invokeOption.FeedbackType)
|
||||
{
|
||||
case FeedbackType.OnlySend:
|
||||
{
|
||||
this.InternalSendAsync(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
}
|
||||
break;
|
||||
case FeedbackType.WaitSend:
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
this.InternalSend(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -345,8 +382,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -357,8 +394,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -425,7 +462,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMRPCNoRegisterException($"服务名为{method}的服务未找到注册信息");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<WaitResult> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodItem.MethodToken;
|
||||
ByteBlock byteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
@@ -443,7 +480,22 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
context.ParametersBytes = datas;
|
||||
context.Serialize(byteBlock);
|
||||
this.InternalSend(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
switch (invokeOption.FeedbackType)
|
||||
{
|
||||
case FeedbackType.OnlySend:
|
||||
{
|
||||
this.InternalSendAsync(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
}
|
||||
break;
|
||||
case FeedbackType.WaitSend:
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
this.InternalSend(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -462,8 +514,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -474,8 +526,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -527,7 +579,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMRPCNoRegisterException($"服务名为{method}的服务未找到注册信息");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<WaitResult> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodItem.MethodToken;
|
||||
ByteBlock byteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
@@ -545,7 +597,22 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
context.ParametersBytes = datas;
|
||||
context.Serialize(byteBlock);
|
||||
this.InternalSend(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
switch (invokeOption.FeedbackType)
|
||||
{
|
||||
case FeedbackType.OnlySend:
|
||||
{
|
||||
this.InternalSendAsync(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
}
|
||||
break;
|
||||
case FeedbackType.WaitSend:
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
this.InternalSend(101, byteBlock.Buffer, 0, byteBlock.Len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -564,8 +631,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -579,8 +646,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -639,7 +706,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMRPCException("目标ID不能为null或empty");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<WaitResult> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodToken;
|
||||
context.ID = id;
|
||||
@@ -680,8 +747,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
case FeedbackType.WaitSend:
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -722,7 +789,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMRPCException("目标ID不能为null或empty");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<WaitResult> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodToken;
|
||||
context.ID = id;
|
||||
@@ -762,8 +829,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
case FeedbackType.WaitSend:
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = (RPCContext)waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = (RpcContext)waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -833,7 +900,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
if (method.IsGenericMethod)
|
||||
{
|
||||
throw new RRQMRPCException("RPC方法中不支持泛型参数");
|
||||
continue;
|
||||
}
|
||||
RRQMRPCCallBackMethodAttribute attribute = method.GetCustomAttribute<RRQMRPCCallBackMethodAttribute>();
|
||||
|
||||
@@ -897,7 +964,6 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 移除注册服务
|
||||
/// </summary>
|
||||
@@ -920,7 +986,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
throw new RRQMRPCException("类型不相符");
|
||||
}
|
||||
this.ServerProviders.Remove(providerType);
|
||||
if (this.MethodMap.RemoveServer(providerType, out ServerProvider serverProvider, out MethodInstance[] instances))
|
||||
if (this.MethodMap.RemoveServer(providerType, out IServerProvider serverProvider, out MethodInstance[] instances))
|
||||
{
|
||||
return instances.Length;
|
||||
}
|
||||
@@ -952,7 +1018,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
try
|
||||
{
|
||||
proxyFile = SerializeConvert.RRQMBinaryDeserialize<RPCProxyInfo>(buffer, 2);
|
||||
proxyFile = SerializeConvert.RRQMBinaryDeserialize<RpcProxyInfo>(buffer, 2);
|
||||
this.singleWaitData.Set();
|
||||
}
|
||||
catch
|
||||
@@ -967,7 +1033,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
try
|
||||
{
|
||||
RPCContext result = RPCContext.Deserialize(buffer, 2);
|
||||
byteBlock.Pos = 2;
|
||||
RpcContext result = RpcContext.Deserialize(byteBlock);
|
||||
this.waitHandle.SetRun(result.Sign, result);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -1001,7 +1068,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
try
|
||||
{
|
||||
RPCContext result = RPCContext.Deserialize(buffer, 2);
|
||||
byteBlock.Pos = 2;
|
||||
RpcContext result = RpcContext.Deserialize(byteBlock);
|
||||
this.waitHandle.SetRun(result.Sign, result);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -1014,7 +1082,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
RPCContext rpcContext = RPCContext.Deserialize(byteBlock.Buffer, 2);
|
||||
byteBlock.Pos = 2;
|
||||
RpcContext rpcContext = RpcContext.Deserialize(byteBlock);
|
||||
ByteBlock block = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
try
|
||||
{
|
||||
@@ -1050,7 +1119,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
base.LoadConfig(clientConfig);
|
||||
this.SetDataHandlingAdapter(new FixedHeaderDataHandlingAdapter());
|
||||
this.SerializeConverter = (SerializeConverter)clientConfig.GetValue(TcpRPCClientConfig.SerializeConverterProperty);
|
||||
this.SerializeConverter = (SerializeConverter)clientConfig.GetValue(TcpRpcClientConfig.SerializeConverterProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1069,7 +1138,14 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <param name="args"></param>
|
||||
protected virtual void OnServiceDiscovered(MesEventArgs args)
|
||||
{
|
||||
this.ServiceDiscovered?.Invoke(this, args);
|
||||
try
|
||||
{
|
||||
this.ServiceDiscovered?.Invoke(this, args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.Debug(LogType.Error, this, $"在事件{nameof(ServiceDiscovered)}中发生异常", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1082,7 +1158,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
OnHandleDefaultData(procotol, byteBlock);
|
||||
}
|
||||
|
||||
private RPCContext OnExecuteCallBack(RPCContext rpcContext)
|
||||
private RpcContext OnExecuteCallBack(RpcContext rpcContext)
|
||||
{
|
||||
if (this.methodMap != null)
|
||||
{
|
||||
@@ -15,7 +15,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// TCP RPC解释器
|
||||
/// </summary>
|
||||
public class TcpRPCParser : TcpParser<RPCSocketClient>
|
||||
public class TcpRpcParser : TcpParser<RPCSocketClient>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -24,12 +24,12 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// UDP协议客户端
|
||||
/// </summary>
|
||||
public class UdpRPCClient : UdpSession, IRRQMRPCClient
|
||||
public class UdpRpcClient : UdpSession, IRRQMRpcClient
|
||||
{
|
||||
private MethodStore methodStore;
|
||||
private RPCProxyInfo proxyFile;
|
||||
private RpcProxyInfo proxyFile;
|
||||
private WaitData<WaitResult> singleWaitData;
|
||||
private RRQMWaitHandle<RPCContext> waitHandle;
|
||||
private RRQMWaitHandle<RpcContext> waitHandle;
|
||||
private WaitResult waitResult;
|
||||
|
||||
/// <summary>
|
||||
@@ -40,9 +40,9 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public UdpRPCClient()
|
||||
public UdpRpcClient()
|
||||
{
|
||||
this.waitHandle = new RRQMWaitHandle<RPCContext>();
|
||||
this.waitHandle = new RRQMWaitHandle<RpcContext>();
|
||||
this.SerializeConverter = new BinarySerializeConverter();
|
||||
this.waitResult = new WaitResult();
|
||||
this.singleWaitData = new WaitData<WaitResult>();
|
||||
@@ -64,7 +64,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <returns></returns>
|
||||
/// <exception cref="RRQMRPCException"></exception>
|
||||
/// <exception cref="RRQMTimeoutException"></exception>
|
||||
public RPCProxyInfo GetProxyInfo()
|
||||
public RpcProxyInfo GetProxyInfo()
|
||||
{
|
||||
int count = 0;
|
||||
while (count < 3)
|
||||
@@ -72,7 +72,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
lock (this)
|
||||
{
|
||||
byte[] datas;
|
||||
string proxyToken = (string)this.ServiceConfig.GetValue(UdpRPCClientConfig.ProxyTokenProperty);
|
||||
string proxyToken = (string)this.ServiceConfig.GetValue(UdpRpcClientConfig.ProxyTokenProperty);
|
||||
if (proxyToken == null)
|
||||
{
|
||||
datas = new byte[0];
|
||||
@@ -115,7 +115,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
this.methodStore = null;
|
||||
|
||||
string proxyToken = (string)this.ServiceConfig.GetValue(UdpRPCClientConfig.ProxyTokenProperty);
|
||||
string proxyToken = (string)this.ServiceConfig.GetValue(UdpRpcClientConfig.ProxyTokenProperty);
|
||||
byte[] data = new byte[0];
|
||||
if (!string.IsNullOrEmpty(proxyToken))
|
||||
{
|
||||
@@ -161,8 +161,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMException($"服务名为{method}的服务未找到注册信息");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
WaitData<RPCContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<RpcContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodItem.MethodToken;
|
||||
ByteBlock byteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
if (invokeOption == null)
|
||||
@@ -200,8 +200,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -215,8 +215,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -292,8 +292,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMException($"服务名为{method}的服务未找到注册信息");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
WaitData<RPCContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<RpcContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodItem.MethodToken;
|
||||
ByteBlock byteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
if (invokeOption == null)
|
||||
@@ -329,8 +329,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -341,8 +341,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -408,8 +408,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMException($"服务名为{method}的服务未找到注册信息");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
WaitData<RPCContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<RpcContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodItem.MethodToken;
|
||||
ByteBlock byteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
if (invokeOption == null)
|
||||
@@ -445,8 +445,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -457,8 +457,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -509,8 +509,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
throw new RRQMException($"服务名为{method}的服务未找到注册信息");
|
||||
}
|
||||
RPCContext context = new RPCContext();
|
||||
WaitData<RPCContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
RpcContext context = new RpcContext();
|
||||
WaitData<RpcContext> waitData = this.waitHandle.GetWaitData(context);
|
||||
context.MethodToken = methodItem.MethodToken;
|
||||
ByteBlock byteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
if (invokeOption == null)
|
||||
@@ -546,8 +546,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitSend:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -561,8 +561,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
case FeedbackType.WaitInvoke:
|
||||
{
|
||||
waitData.Wait(invokeOption.WaitTime * 1000);
|
||||
RPCContext resultContext = waitData.WaitResult;
|
||||
waitData.Wait(invokeOption.Timeout);
|
||||
RpcContext resultContext = waitData.WaitResult;
|
||||
this.waitHandle.Destroy(waitData);
|
||||
|
||||
if (resultContext.Status == 0)
|
||||
@@ -604,6 +604,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 密封数据
|
||||
/// </summary>
|
||||
@@ -620,7 +621,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
try
|
||||
{
|
||||
proxyFile = SerializeConvert.RRQMBinaryDeserialize<RPCProxyInfo>(buffer, 2);
|
||||
proxyFile = SerializeConvert.RRQMBinaryDeserialize<RpcProxyInfo>(buffer, 2);
|
||||
this.singleWaitData.Set();
|
||||
}
|
||||
catch
|
||||
@@ -635,7 +636,8 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
try
|
||||
{
|
||||
RPCContext result = RPCContext.Deserialize(buffer, 2);
|
||||
byteBlock.Pos = 2;
|
||||
RpcContext result = RpcContext.Deserialize(byteBlock);
|
||||
this.waitHandle.SetRun(result.Sign, result);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -697,7 +699,14 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <param name="args"></param>
|
||||
protected virtual void OnServiceDiscovered(MesEventArgs args)
|
||||
{
|
||||
this.ServiceDiscovered?.Invoke(this, args);
|
||||
try
|
||||
{
|
||||
this.ServiceDiscovered?.Invoke(this, args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.Debug(LogType.Error, this, $"在事件{nameof(ServiceDiscovered)}中发生异常", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,15 +23,15 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
/// <summary>
|
||||
/// UDP RPC解释器
|
||||
/// </summary>
|
||||
public class UdpRPCParser : UdpSession, IRPCParser, IRRQMRPCParser
|
||||
public class UdpRpcParser : UdpSession, IRPCParser, IRRQMRpcParser
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public UdpRPCParser()
|
||||
public UdpRpcParser()
|
||||
{
|
||||
this.methodStore = new MethodStore();
|
||||
this.proxyInfo = new RPCProxyInfo();
|
||||
this.proxyInfo = new RpcProxyInfo();
|
||||
}
|
||||
|
||||
#pragma warning disable
|
||||
@@ -45,7 +45,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
|
||||
public string NameSpace { get; private set; }
|
||||
|
||||
public RPCProxyInfo ProxyInfo { get => proxyInfo; }
|
||||
public RpcProxyInfo ProxyInfo { get => proxyInfo; }
|
||||
|
||||
public string ProxyToken { get; private set; }
|
||||
|
||||
@@ -54,7 +54,9 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
public SerializeConverter SerializeConverter { get; private set; }
|
||||
|
||||
private MethodStore methodStore;
|
||||
private RPCProxyInfo proxyInfo;
|
||||
|
||||
private RpcProxyInfo proxyInfo;
|
||||
|
||||
public MethodStore MethodStore => this.methodStore;
|
||||
|
||||
public void SetExecuteMethod(Action<IRPCParser, MethodInvoker, MethodInstance> executeMethod)
|
||||
@@ -72,9 +74,9 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
this.RPCService = service;
|
||||
}
|
||||
|
||||
public virtual RPCProxyInfo GetProxyInfo(string proxyToken, object caller)
|
||||
public virtual RpcProxyInfo GetProxyInfo(string proxyToken, object caller)
|
||||
{
|
||||
RPCProxyInfo proxyInfo = new RPCProxyInfo();
|
||||
RpcProxyInfo proxyInfo = new RpcProxyInfo();
|
||||
if (this.ProxyToken == proxyToken)
|
||||
{
|
||||
proxyInfo.AssemblyData = this.ProxyInfo.AssemblyData;
|
||||
@@ -92,7 +94,7 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
return proxyInfo;
|
||||
}
|
||||
|
||||
public virtual void ExecuteContext(RPCContext context, object caller)
|
||||
public virtual void ExecuteContext(RpcContext context, object caller)
|
||||
{
|
||||
MethodInvoker methodInvoker = new MethodInvoker();
|
||||
methodInvoker.Caller = caller;
|
||||
@@ -133,10 +135,10 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
protected override void LoadConfig(ServiceConfig ServiceConfig)
|
||||
{
|
||||
base.LoadConfig(ServiceConfig);
|
||||
this.SerializeConverter = (SerializeConverter)ServiceConfig.GetValue(UdpRPCParserConfig.SerializeConverterProperty);
|
||||
this.ProxyToken = (string)ServiceConfig.GetValue(UdpRPCParserConfig.ProxyTokenProperty);
|
||||
this.NameSpace = (string)ServiceConfig.GetValue(UdpRPCParserConfig.NameSpaceProperty);
|
||||
this.RPCVersion = (Version)ServiceConfig.GetValue(UdpRPCParserConfig.RPCVersionProperty);
|
||||
this.SerializeConverter = (SerializeConverter)ServiceConfig.GetValue(UdpRpcParserConfig.SerializeConverterProperty);
|
||||
this.ProxyToken = (string)ServiceConfig.GetValue(UdpRpcParserConfig.ProxyTokenProperty);
|
||||
this.NameSpace = (string)ServiceConfig.GetValue(UdpRpcParserConfig.NameSpaceProperty);
|
||||
this.RPCVersion = (Version)ServiceConfig.GetValue(UdpRpcParserConfig.RPCVersionProperty);
|
||||
}
|
||||
|
||||
public virtual List<MethodItem> GetRegisteredMethodItems(string proxyToken, object caller)
|
||||
@@ -144,12 +146,12 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
return this.methodStore.GetAllMethodItem();
|
||||
}
|
||||
|
||||
public void OnRegisterServer(ServerProvider provider, MethodInstance[] methodInstances)
|
||||
public void OnRegisterServer(IServerProvider provider, MethodInstance[] methodInstances)
|
||||
{
|
||||
Tools.GetRPCMethod(methodInstances, this.NameSpace, ref this.methodStore, this.RPCVersion, ref this.proxyInfo);
|
||||
}
|
||||
|
||||
public void OnUnregisterServer(ServerProvider provider, MethodInstance[] methodInstances)
|
||||
public void OnUnregisterServer(IServerProvider provider, MethodInstance[] methodInstances)
|
||||
{
|
||||
foreach (var item in methodInstances)
|
||||
{
|
||||
@@ -169,12 +171,11 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
this.proxyInfo.Codes.Remove(cellCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnEndInvoke(MethodInvoker methodInvoker, MethodInstance methodInstance)
|
||||
{
|
||||
RPCContext context = (RPCContext)methodInvoker.Flag;
|
||||
RpcContext context = (RpcContext)methodInvoker.Flag;
|
||||
if (context.Feedback != 2)
|
||||
{
|
||||
return;
|
||||
@@ -314,12 +315,13 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
{
|
||||
try
|
||||
{
|
||||
RPCContext content = RPCContext.Deserialize(buffer, 2);
|
||||
byteBlock.Pos = 2;
|
||||
RpcContext content = RpcContext.Deserialize(byteBlock);
|
||||
if (content.Feedback == 1)
|
||||
{
|
||||
List<byte[]> ps = content.ParametersBytes;
|
||||
|
||||
ByteBlock returnByteBlock = this.BytePool.GetByteBlock(this.bufferLength);
|
||||
ByteBlock returnByteBlock = this.BytePool.GetByteBlock(this.BufferLength);
|
||||
try
|
||||
{
|
||||
content.ParametersBytes = null;
|
||||
@@ -358,25 +360,23 @@ namespace RRQMSocket.RPC.RRQMRPC
|
||||
}
|
||||
|
||||
#if NET45_OR_GREATER
|
||||
|
||||
/// <summary>
|
||||
/// 编译代理
|
||||
/// </summary>
|
||||
/// <param name="targetDic">存放目标文件夹</param>
|
||||
public void CompilerProxy(string targetDic = "")
|
||||
{
|
||||
string assemblyInfo = CodeMap.GetAssemblyInfo(this.proxyInfo.AssemblyName, this.proxyInfo.Version);
|
||||
string assemblyInfo = CodeGenerator.GetAssemblyInfo(this.proxyInfo.AssemblyName, this.proxyInfo.Version);
|
||||
List<string> codesString = new List<string>();
|
||||
codesString.Add(assemblyInfo);
|
||||
foreach (var item in this.proxyInfo.Codes)
|
||||
{
|
||||
codesString.Add(item.Code);
|
||||
}
|
||||
RPCCompiler.CompileCode(Path.Combine(targetDic, this.proxyInfo.AssemblyName), codesString.ToArray());
|
||||
|
||||
RpcCompiler.CompileCode(Path.Combine(targetDic, this.proxyInfo.AssemblyName), codesString.ToArray());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,9 @@ API:https://gitee.com/RRQM_OS/RRQM/wikis/pages</Description>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RRQMSocket\RRQMSocket.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="RRQMCore">
|
||||
|
||||
Reference in New Issue
Block a user