V5.5.0正式版

This commit is contained in:
若汝棋茗
2021-08-13 21:41:12 +08:00
parent 7576c60bc7
commit 59f562c38e
228 changed files with 26352 additions and 0 deletions

View 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
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
namespace RRQMSocket.RPC
{
/// <summary>
/// 调用状态
/// </summary>
public enum InvokeStatus : byte
{
/// <summary>
/// 就绪
/// </summary>
Ready,
/// <summary>
/// 未找到服务
/// </summary>
UnFound,
/// <summary>
/// 不可用
/// </summary>
UnEnable,
/// <summary>
/// 成功调用
/// </summary>
Success,
/// <summary>
/// 终止执行
/// </summary>
Abort,
/// <summary>
/// 调用内部异常
/// </summary>
InvocationException,
/// <summary>
/// 其他异常
/// </summary>
Exception
}
}

View File

@@ -0,0 +1,77 @@
//------------------------------------------------------------------------------
// 此代码版权除特别声明或在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.Reflection;
namespace RRQMSocket.RPC
{
/// <summary>
/// RPC函数实例
/// </summary>
public class MethodInstance
{
/// <summary>
/// 执行此RPC的实例
/// </summary>
public IServerProvider Provider { get; internal set; }
/// <summary>
/// RPC函数
/// </summary>
public MethodInfo Method { get; internal set; }
/// <summary>
/// RPC属性集合
/// </summary>
public RPCAttribute[] RPCAttributes { get; internal set; }
/// <summary>
/// 方法唯一令箭
/// </summary>
public int MethodToken { get; internal set; }
/// <summary>
/// 返回值类型无返回值时为Null
/// </summary>
public Type ReturnType { get; internal set; }
/// <summary>
/// 参数类型集合已处理out及ref无参数时为空集合
/// </summary>
public Type[] ParameterTypes { get; internal set; }
/// <summary>
/// 参数集合
/// </summary>
public ParameterInfo[] Parameters { get; internal set; }
/// <summary>
/// 参数名集合
/// </summary>
public string[] ParameterNames { get; internal set; }
/// <summary>
/// 是否异步执行
/// </summary>
public bool Async { get; internal set; }
/// <summary>
/// 是否有引用类型
/// </summary>
public bool IsByRef { get; internal set; }
/// <summary>
/// 是否可用
/// </summary>
public bool IsEnable { get; internal set; }
}
}

View File

@@ -0,0 +1,50 @@
//------------------------------------------------------------------------------
// 此代码版权除特别声明或在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
{
/// <summary>
/// 函数调用信使
/// </summary>
public class MethodInvoker
{
/// <summary>
/// 返回值
/// </summary>
public object ReturnParameter { get; set; }
/// <summary>
/// 参数值集合
/// </summary>
public object[] Parameters { get; set; }
/// <summary>
/// 获取调用状态
/// </summary>
public InvokeStatus Status { get; set; }
/// <summary>
/// 状态消息
/// </summary>
public string StatusMessage { get; set; }
/// <summary>
/// 可以传递其他类型的数据容器
/// </summary>
public object Flag { get; set; }
/// <summary>
/// 此函数执行者
/// </summary>
public object Caller { get; set; }
}
}

View File

@@ -0,0 +1,81 @@
//------------------------------------------------------------------------------
// 此代码版权除特别声明或在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;
using RRQMSocket.RPC.RRQMRPC;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace RRQMSocket.RPC
{
/// <summary>
/// 函数映射图
/// </summary>
public class MethodMap
{
internal MethodMap()
{
this.methodMap = new ConcurrentDictionary<int, MethodInstance>();
}
private ConcurrentDictionary<int, MethodInstance> methodMap;
internal void Add(MethodInstance methodInstance)
{
this.methodMap.TryAdd(methodInstance.MethodToken, methodInstance);
}
/// <summary>
/// 通过methodToken获取函数实例
/// </summary>
/// <param name="methodToken"></param>
/// <param name="methodInstance"></param>
/// <returns></returns>
public bool TryGet(int methodToken, out MethodInstance methodInstance)
{
return this.methodMap.TryGetValue(methodToken, out methodInstance);
}
internal bool RemoveServer(Type type, out IServerProvider serverProvider, out MethodInstance[] methodInstances)
{
serverProvider = null;
bool success = false;
List<MethodInstance> keys = new List<MethodInstance>();
foreach (var methodInstance in this.methodMap.Values)
{
if (methodInstance.Provider.GetType().FullName == type.FullName)
{
success = true;
serverProvider = methodInstance.Provider;
keys.Add(methodInstance);
}
}
foreach (var item in keys)
{
this.methodMap.TryRemove(item.MethodToken, out _);
}
methodInstances = keys.ToArray();
return success;
}
/// <summary>
/// 获取所有服务函数实例
/// </summary>
/// <returns></returns>
public MethodInstance[] GetAllMethodInstances()
{
return this.methodMap.Values.ToArray();
}
}
}

View File

@@ -0,0 +1,79 @@
//------------------------------------------------------------------------------
// 此代码版权除特别声明或在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;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
namespace RRQMSocket.RPC
{
/// <summary>
/// RPCParser集合
/// </summary>
[DebuggerDisplay("Count")]
public class RPCParserCollection : IEnumerable<IRPCParser>
{
private ConcurrentDictionary<string, IRPCParser> parsers = new ConcurrentDictionary<string, IRPCParser>();
/// <summary>
/// 数量
/// </summary>
public int Count { get { return parsers.Count; } }
/// <summary>
/// 获取IRPCParser
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public IRPCParser this[string key] { get { return this.parsers[key]; } }
/// <summary>
/// 获取IRPCParser
/// </summary>
/// <param name="key"></param>
/// <param name="parser"></param>
/// <returns></returns>
public bool TryGetRPCParser(string key, out IRPCParser parser)
{
return this.parsers.TryGetValue(key, out parser);
}
internal void Add(string key, IRPCParser parser)
{
if (this.parsers.Values.Contains(parser))
{
throw new RRQMRPCException("重复添加解析器");
}
this.parsers.TryAdd(key, parser);
}
internal bool TryRemove(string key, out IRPCParser parser)
{
return this.parsers.TryRemove(key, out parser);
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.parsers.Values.GetEnumerator();
}
/// <summary>
/// 返回枚举对象
/// </summary>
/// <returns></returns>
IEnumerator<IRPCParser> IEnumerable<IRPCParser>.GetEnumerator()
{
return this.parsers.Values.GetEnumerator();
}
}
}

View File

@@ -0,0 +1,85 @@
//------------------------------------------------------------------------------
// 此代码版权除特别声明或在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;
using System.Collections.Generic;
namespace RRQMSocket.RPC
{
/// <summary>
/// 只读字典
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
public class ReadOnlyDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
{
private Dictionary<TKey, TValue> dic = new Dictionary<TKey, TValue>();
/// <summary>
/// 值集合
/// </summary>
public ICollection<TValue> Values { get { return this.dic.Values; } }
/// <summary>
/// 键集合
/// </summary>
public ICollection<TKey> Keys { get { return this.dic.Keys; } }
internal void Add(TKey key, TValue value)
{
dic.Add(key, value);
}
internal bool Remove(TKey key)
{
return dic.Remove(key);
}
internal void Clear()
{
dic.Clear();
}
/// <summary>
/// 键值对数目
/// </summary>
public int Count { get { return this.dic.Count; } }
/// <summary>
/// 尝试获取值
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool TryGetValue(TKey key, out TValue value)
{
return this.dic.TryGetValue(key, out value);
}
/// <summary>
/// 返回迭代器
/// </summary>
/// <returns></returns>
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return this.dic.GetEnumerator();
}
/// <summary>
/// 迭代器
/// </summary>
/// <returns></returns>
IEnumerator IEnumerable.GetEnumerator()
{
return this.dic.GetEnumerator();
}
}
}

View File

@@ -0,0 +1,92 @@
//------------------------------------------------------------------------------
// 此代码版权除特别声明或在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;
using System.Collections.Generic;
namespace RRQMSocket.RPC
{
/// <summary>
/// 只读
/// </summary>
/// <typeparam name="T"></typeparam>
public class ReadOnlyList<T> : IEnumerable<T>
{
private List<T> list = new List<T>();
internal void Add(T block)
{
list.Add(block);
}
internal void AddRange(IEnumerable<T> collection)
{
list.AddRange(collection);
}
internal void Remove(T block)
{
list.Remove(block);
}
internal void RemoveAt(int index)
{
list.RemoveAt(index);
}
internal void RemoveAll(Predicate<T> match)
{
list.RemoveAll(match);
}
internal void RemoveRange(int index, int range)
{
list.RemoveRange(index, range);
}
internal void Clear()
{
list.Clear();
}
internal void Insert(int index, T item)
{
list.Insert(index, item);
}
internal void InsertRange(int index, IEnumerable<T> collection)
{
list.InsertRange(index, collection);
}
/// <summary>
/// 返回迭代器
/// </summary>
/// <returns></returns>
public IEnumerator<T> GetEnumerator()
{
return this.list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.list.GetEnumerator();
}
/// <summary>
/// 获取对象
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public T this[int index] { get { return list[index]; } }
}
}

View File

@@ -0,0 +1,62 @@
//------------------------------------------------------------------------------
// 此代码版权除特别声明或在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.Reflection;
namespace RRQMSocket.RPC
{
/// <summary>
/// RPC范围类
/// </summary>
public abstract class ServerProvider:IServerProvider
{
/// <summary>
/// 默认复刻程序集
/// </summary>
public static Assembly DefaultAssembly { get; set; }
/// <summary>
/// 该服务所属的服务器
/// </summary>
public RPCService RPCService { get; set; }
/// <summary>
/// RPC即将进入,
/// 若是想放弃本次执行,请抛出<see cref="RRQMAbandonRPCException"/>
/// </summary>
/// <param name="parser"></param>
/// <param name="methodInvoker"></param>
/// <param name="methodInstance"></param>
public virtual void RPCEnter(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
{
}
/// <summary>
/// 执行RPC发生错误
/// </summary>
/// <param name="parser"></param>
/// <param name="methodInvoker"></param>
/// <param name="methodInstance"></param>
public virtual void RPCError(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
{
}
/// <summary>
/// RPC方法执行完成
/// </summary>
/// <param name="parser"></param>
/// <param name="methodInvoker"></param>
/// <param name="methodInstance"></param>
public virtual void RPCLeave(IRPCParser parser, MethodInvoker methodInvoker, MethodInstance methodInstance)
{
}
}
}

View File

@@ -0,0 +1,74 @@
//------------------------------------------------------------------------------
// 此代码版权除特别声明或在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;
using System.Collections.Generic;
using System.Diagnostics;
namespace RRQMSocket.RPC
{
/// <summary>
/// 服务集合
/// </summary>
[DebuggerDisplay("{Count}")]
public class ServerProviderCollection : IEnumerable<IServerProvider>, IEnumerable
{
/// <summary>
/// 服务数量
/// </summary>
public int Count { get { return this.servers.Count; } }
private List<IServerProvider> servers = new List<IServerProvider>();
internal void Add(IServerProvider serverProvider)
{
foreach (var server in this.servers)
{
if (serverProvider.GetType().FullName == server.GetType().FullName)
{
throw new RRQMRPCException("相同类型的服务已添加");
}
}
if (ServerProvider.DefaultAssembly == null)
{
ServerProvider.DefaultAssembly = serverProvider.GetType().Assembly;
}
servers.Add(serverProvider);
}
internal void Remove(Type serverType)
{
foreach (var server in this.servers)
{
if (serverType.FullName == server.GetType().FullName)
{
this.servers.Remove(server);
return;
}
}
}
/// <summary>
/// 返回枚举
/// </summary>
/// <returns></returns>
IEnumerator<IServerProvider> IEnumerable<IServerProvider>.GetEnumerator()
{
return this.servers.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.servers.GetEnumerator();
}
}
}