介绍开源的.net通信框架NetworkComms框架 源码分析(六)SendReceiveOptions
原文网址: http://www.cnblogs.com/csdev
Networkcomms 是一款C# 语言编写的TCP/UDP通信框架 作者是英国人 以前是收费的 目前作者已经开源 许可是:Apache License v2
开源地址是:https://github.com/MarcFletcher/NetworkComms.Net
发送接收参数
networkcomms默认时,使用protobuf序列化器,使用别的序列化器的话,就需要设定SendReceiveOptions参数了.
如果要启用加密的话,也需要设定SendReceiveOptions参数
using System;
using System.Collections.Generic;
using System.Text;
using NetworkCommsDotNet.DPSBase;
using NetworkCommsDotNet.Tools;
using System.Threading;
namespace NetworkCommsDotNet
{
/// <summary>
/// Contains options and flags for sending and receiving data such as serialisation method, data processors, encryption etc.
/// Several static constructors are provided to help create SendReceiveOptions in the most common formats.
/// 收发参数类
/// 包含 用于发送和接收数据时相关的参数设定 包括 序列化方法 数据处理器 加密方法等
/// 系统提供了几个静态构造器来帮助创建SendReceiveOptions
/// </summary>
public class SendReceiveOptions
{
/// <summary>
/// If true any packets sent with this <see cref="SendReceiveOptions"/> will be forced to trigger a receive confirmation.
/// 如果设定为True,对方服务器在接收消息后,会发一个确认消息回来
/// </summary>
public bool ReceiveConfirmationRequired
{
get { return Options.ContainsKey("ReceiveConfirmationRequired"); }
set {
if (value) Options["ReceiveConfirmationRequired"] = "";
else Options.Remove("ReceiveConfirmationRequired");
}
}
/// <summary>
/// If true any packets sent with this <see cref="SendReceiveOptions"/> will include the packet creation time in the header.
/// 如果设定为True,相关数据包的包头中会包含数据包的创建时间
/// </summary>
public bool IncludePacketConstructionTime
{
get { return Options.ContainsKey("IncludePacketConstructionTime"); }
set
{
if (value) Options["IncludePacketConstructionTime"] = "";
else Options.Remove("IncludePacketConstructionTime");
}
}
/// <summary>
/// If true any packets sent with this <see cref="SendReceiveOptions"/> will be nested which can be used to obscure the actual
/// packet type.
/// 嵌套的数据类型
/// 如果设置为True,数据包在发送时将会进行嵌套以便于掩盖实际的数据包类型
/// </summary>
public bool UseNestedPacket
{
get { return Options.ContainsKey("UseNestedPacketType"); }
set
{
if (value) Options["UseNestedPacketType"] = "";
else Options.Remove("UseNestedPacketType");
}
}
/// <summary>
/// Incoming packets are handled using a flexible QueueItemPriority (Default - QueueItemPriority.Normal). Reserved internal
/// packet types and packets marked with QueueItemPriority.Highest are not enqueued but handled in real time by the thread
/// handling the incoming data. You are free to specify the queue item priority for packet handlers using this
/// SendReceiveOptions by setting this value as desired. CAUTION: Only use QueueItemPriority.Highest sparingly.
/// 使用灵活的 “队列项目优先级” 以便处理数据 默认优先级为 QueueItemPriority.Normal
/// 保留的内部数据类型(比如心跳检测,消息确认等)使用的优先级别较高 为QueueItemPriority.Highest 即最高优先级 不进入队列等待 而是有当前
/// 线程直接处理 您可以通过设置此项属性随意的制定数据包的“队列项目优先级”
/// 警告 应该有节制的使用QueueItemPriority.Highest 即最高优先级
/// </summary>
public QueueItemPriority ReceiveHandlePriority
{
get
{
if (Options.ContainsKey("ReceiveHandlePriority"))
return (QueueItemPriority)Enum.Parse(typeof(QueueItemPriority), Options["ReceiveHandlePriority"]);
else
return QueueItemPriority.Normal;
}
set
{
Options["ReceiveHandlePriority"] = Enum.GetName(typeof(QueueItemPriority), value);
}
}
private DataSerializer _dataSerializer;
private List<DataProcessor> _dataProcessors;
/// <summary>
/// Gets the <see cref="DPSBase.DataSerializer"/> that should be used when sending information
/// 获取数据序列化器 比如 protobuf.net
/// </summary>
public DataSerializer DataSerializer
{
get { return _dataSerializer; }
protected set
{
if (value == null)
_dataSerializer = DPSManager.GetDataSerializer<NullSerializer>();
else
_dataSerializer = value;
}
}
/// <summary>
/// Gets the <see cref="DPSBase.DataProcessor"/>s that should be used when sending information. <see cref="DPSBase.DataProcessor"/>s are applied in index order
/// 获取数据处理器 比如 加密 压缩
/// </summary>
public List<DataProcessor> DataProcessors
{
get { return _dataProcessors; }
protected set
{
if (value == null)
{
_dataProcessors = new List<DataProcessor>();
return;
}
)
throw new ArgumentException("Only 7 data Processors are supported");
//validate the list to make sure all the data processors are the same
//验证处理器列表 以防止处理器重复
List<DataProcessor> distinctProcessors = new List<DataProcessor>();
foreach (var processor in value)
{
if(distinctProcessors.Contains(processor))
throw new ArgumentException("Same data processor cannot be applied twice");
distinctProcessors.Add(processor);
}
_dataProcessors = value;
}
}
private Dictionary<string, string> options;
/// <summary>
/// Gets the options that should be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s on object serialization and deserialization
/// 这些参数值给 数据序列化器和 数据处理器 在序列化的过程中使用
/// </summary>
public Dictionary<string, string> Options
{
get { return options; }
}
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class with a specified <see cref="DPSBase.DataSerializer"/>, set of <see cref="DPSBase.DataProcessor"/>s and and other options
/// 初始化一个新的实例 并制定相应的序列化器 数据处理器 和其他参数
/// </summary>
/// <param name="serializer">数据序列化器 The <see cref="DPSBase.DataSerializer"/> to use</param>
/// <param name="dataProcessors">数据处理器 The set of <see cref="DPSBase.DataProcessor"/>s to use. The order in the list determines the order the <see cref="DPSBase.DataProcessor"/>s will be applied</param>
/// <param name="options">其他参数 Allows additional options to be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s</param>
public SendReceiveOptions(DataSerializer serializer, List<DataProcessor> dataProcessors, Dictionary<string, string> options)
{
if (serializer == null)
throw new ArgumentNullException("serializer", "The serializer argument when creating a sendReceiveOptions object should never be null.");
this.DataSerializer = serializer;
this.DataProcessors = dataProcessors;
if (options != null)
this.options = options;
else
this.options = new Dictionary<string, string>();
}
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class providing only options for the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s. This constructor should only be used when adding packet handlers for incoming connections
///初始化一个新的实例
///此构造函数只在为进入的连接添加数据包处理器时使用
/// </summary>
/// <param name="options">参数选项 这些参数将被传给给序列化器和处理器使用 Allows additional options to be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s</param>
public SendReceiveOptions(Dictionary<string, string> options)
{
DataSerializer = null; //This will set the NullSerialiser as a default 把序列化器设置为空
DataProcessors = null; //This will set an empty options dictionary 把处理器设置为空
if (options != null)
this.options = options;
else
this.options = new Dictionary<string, string>();
}
/// <summary>
/// Initializes an empty instance of the <see cref="SendReceiveOptions"/> class.
/// 初始化一个空的实例
/// </summary>
public SendReceiveOptions()
{
DataSerializer = null; //This will set the NullSerialiser as a default
DataProcessors = null; //This will set an empty options dictionary
this.options = new Dictionary<string, string>();
}
/// <summary>
/// Determines whether the supplied <see cref="SendReceiveOptions"/> is compatible, from a serialization point of view, with this instance
/// 比较参数中的SendReceiveOptions对象是否与当前对象一致
/// </summary>
/// <param name="options">要比较的对象 The <see cref="SendReceiveOptions"/> to compare against</param>
/// <returns>如果一致 返回True True if the options are compatible, false otherwise</returns>
/// <remarks>如果2个对象使用相同的序列化器和处理器 则为一致 否则为不一致 Two <see cref="SendReceiveOptions"/> instances will be compatible if they use the same <see cref="DPSBase.DataSerializer"/> and the same set of <see cref="DPSBase.DataProcessor"/>s</remarks>
public bool OptionsCompatible(SendReceiveOptions options)
{
if (options == null) throw new ArgumentNullException("options", "Provided SendReceiveOptions cannot be null.");
bool equal = options.DataSerializer == DataSerializer;
; i < options.DataProcessors.Count; i++)
equal &= options.DataProcessors[i] == DataProcessors[i];
return equal;
}
/// <summary>
/// Create a deep clone of this <see cref="SendReceiveOptions"/> object.
/// 创建对象的深拷贝
/// </summary>
/// <returns>The cloned object</returns>
public object Clone()
{
return new SendReceiveOptions(DataSerializer, new List<DataProcessor>(DataProcessors), new Dictionary<string,string>(Options));
}
}
/// <inheritdoc />
/// <typeparam name="T_DS">T_DS 类型为序列化器 The type of <see cref="DPSBase.DataSerializer"/> to use</typeparam>
public class SendReceiveOptions<T_DS> : SendReceiveOptions
where T_DS : DataSerializer
{
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> is passed as a generic parameter and no <see cref="DPSBase.DataProcessor"/>s are used. To provide additional options see other overrides.
/// 初始化一个新的SendReceiveOption类实例 序列化器作为泛型参数使用
/// </summary>
public SendReceiveOptions()
: base(null)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = null; //Note that this will cause data processors to be set to an empty list 设置数据处理器为空 即不对数据进行加密压缩等处理
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> is passed as a generic parameter and no <see cref="DPSBase.DataProcessor"/>s are used.
/// Further options can be passed to the <see cref="DPSBase.DataSerializer"/> as an argument which may be null
/// 初始化一个新的SendReceiveOption类实例 序列化器作为泛型参数传递
/// 相关的选项(可以为空)可以作为参数传递给序列化器和处理器
/// </summary>
/// <param name="options">Additional options to be passed to the <see cref="DPSBase.DataSerializer"/></param>
public SendReceiveOptions(Dictionary<string, string> options)
: base(options)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = null; //Note that this will cause data processors to be set to an empty list 设置数据处理器为空 即不对数据进行加密压缩等处理
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
}
/// <inheritdoc />
/// <typeparam name="T_DS">The type of <see cref="DPSBase.DataSerializer"/> to use</typeparam>
/// <typeparam name="T_DP1">The type of <see cref="DPSBase.DataProcessor"/> to use</typeparam>
public class SendReceiveOptions<T_DS, T_DP1> : SendReceiveOptions
where T_DS : DataSerializer
where T_DP1 : DataProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> and a single <see cref="DPSBase.DataProcessor"/> while will be used are passed as generic parameters. To provide additional options see other overrides.
///初始化一个新的SendReceiveOptions实例 数据序列化器和一个数据处理器作为泛型参数传递
/// </summary>
public SendReceiveOptions()
: base(null)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = new List<DataProcessor>() { DPSManager.GetDataProcessor<T_DP1>() };
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> and a single <see cref="DPSBase.DataProcessor"/> while will be used are passed as generic parameters
/// Further options can be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/> as an argument which may be null
/// 初始化一个新的SendReceiveOptions实例 数据序列化器和一个数据处理器作为泛型参数传递
/// 相关的选项(可以为空)可以作为参数传递给序列化器和处理器
/// </summary>
/// <param name="options">Additional options to be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/></param>
public SendReceiveOptions(Dictionary<string, string> options)
: base(options)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = new List<DataProcessor>() { DPSManager.GetDataProcessor<T_DP1>() };
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
}
/// <inheritdoc />
/// <typeparam name="T_DS">The type of <see cref="DPSBase.DataSerializer"/> to use</typeparam>
/// <typeparam name="T_DP1">The type of the first <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP2">The type of the second <see cref="DPSBase.DataProcessor"/> to use</typeparam>
public class SendReceiveOptions<T_DS, T_DP1, T_DP2> : SendReceiveOptions
where T_DS : DataSerializer
where T_DP1 : DataProcessor
where T_DP2 : DataProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> and 2 <see cref="DPSBase.DataProcessor"/>s while will be used are passed as generic parameters
/// Further options can be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s as an argument which may be null
/// 初始化一个新的SendReceiveOptions实例 数据序列化器和二个数据处理器作为泛型参数传递
/// 相关的选项(可以为空)可以作为参数传递给序列化器和处理器
/// </summary>
/// <param name="options">Additional options to be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s</param>
public SendReceiveOptions(Dictionary<string, string> options)
: base(options)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = new List<DataProcessor>() {
DPSManager.GetDataProcessor<T_DP1>(),
DPSManager.GetDataProcessor<T_DP2>() };
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
}
/// <inheritdoc />
/// <typeparam name="T_DS">The type of <see cref="DPSBase.DataSerializer"/> to use</typeparam>
/// <typeparam name="T_DP1">The type of the first <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP2">The type of the second <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP3">The type of the third <see cref="DPSBase.DataProcessor"/> to use</typeparam>
public class SendReceiveOptions<T_DS, T_DP1, T_DP2, T_DP3> : SendReceiveOptions
where T_DS : DataSerializer
where T_DP1 : DataProcessor
where T_DP2 : DataProcessor
where T_DP3 : DataProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> and 3 <see cref="DPSBase.DataProcessor"/>s while will be used are passed as generic parameters
/// Further options can be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s as an argument which may be null
/// 初始化一个新的SendReceiveOptions实例 数据序列化器和三个数据处理器作为泛型参数传递
/// 相关的选项(可以为空)可以作为参数传递给序列化器和处理器
/// </summary>
/// <param name="options">Additional options to be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s</param>
public SendReceiveOptions(Dictionary<string, string> options)
: base(options)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = new List<DataProcessor>() {
DPSManager.GetDataProcessor<T_DP1>(),
DPSManager.GetDataProcessor<T_DP2>(),
DPSManager.GetDataProcessor<T_DP3>() };
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
}
/// <inheritdoc />
/// <typeparam name="T_DS">The type of <see cref="DPSBase.DataSerializer"/> to use</typeparam>
/// <typeparam name="T_DP1">The type of the first <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP2">The type of the second <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP3">The type of the third <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP4">The type of the fourth <see cref="DPSBase.DataProcessor"/> to use</typeparam>
public class SendReceiveOptions<T_DS, T_DP1, T_DP2, T_DP3, T_DP4> : SendReceiveOptions
where T_DS : DataSerializer
where T_DP1 : DataProcessor
where T_DP2 : DataProcessor
where T_DP3 : DataProcessor
where T_DP4 : DataProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> and 4 <see cref="DPSBase.DataProcessor"/>s while will be used are passed as generic parameters
/// Further options can be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s as an argument which may be null
/// 初始化一个新的SendReceiveOptions实例 数据序列化器和四个数据处理器作为泛型参数传递
/// 相关的选项(可以为空)可以作为参数传递给序列化器和处理器
/// </summary>
/// <param name="options">Additional options to be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s</param>
public SendReceiveOptions(Dictionary<string, string> options)
: base(options)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = new List<DataProcessor>() {
DPSManager.GetDataProcessor<T_DP1>(),
DPSManager.GetDataProcessor<T_DP2>(),
DPSManager.GetDataProcessor<T_DP3>(),
DPSManager.GetDataProcessor<T_DP4>() };
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
}
/// <inheritdoc />
/// <typeparam name="T_DS">The type of <see cref="DPSBase.DataSerializer"/> to use</typeparam>
/// <typeparam name="T_DP1">The type of the first <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP2">The type of the second <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP3">The type of the third <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP4">The type of the fourth <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP5">The type of the fifth <see cref="DPSBase.DataProcessor"/> to use</typeparam>
public class SendReceiveOptions<T_DS, T_DP1, T_DP2, T_DP3, T_DP4, T_DP5> : SendReceiveOptions
where T_DS : DataSerializer
where T_DP1 : DataProcessor
where T_DP2 : DataProcessor
where T_DP3 : DataProcessor
where T_DP4 : DataProcessor
where T_DP5 : DataProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> and 5 <see cref="DPSBase.DataProcessor"/>s while will be used are passed as generic parameters
/// Further options can be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s as an argument which may be null
/// 初始化一个新的SendReceiveOptions实例 数据序列化器和五个数据处理器作为泛型参数传递
/// 相关的选项(可以为空)可以作为参数传递给序列化器和处理器
/// </summary>
/// <param name="options">Additional options to be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s</param>
public SendReceiveOptions(Dictionary<string, string> options)
: base(options)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = new List<DataProcessor>() {
DPSManager.GetDataProcessor<T_DP1>(),
DPSManager.GetDataProcessor<T_DP2>(),
DPSManager.GetDataProcessor<T_DP3>(),
DPSManager.GetDataProcessor<T_DP4>(),
DPSManager.GetDataProcessor<T_DP5>() };
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
}
/// <inheritdoc />
/// <typeparam name="T_DS">The type of <see cref="DPSBase.DataSerializer"/> to use</typeparam>
/// <typeparam name="T_DP1">The type of the first <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP2">The type of the second <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP3">The type of the third <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP4">The type of the fourth <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP5">The type of the fifth <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP6">The type of the sixth <see cref="DPSBase.DataProcessor"/> to use</typeparam>
public class SendReceiveOptions<T_DS, T_DP1, T_DP2, T_DP3, T_DP4, T_DP5, T_DP6> : SendReceiveOptions
where T_DS : DataSerializer
where T_DP1 : DataProcessor
where T_DP2 : DataProcessor
where T_DP3 : DataProcessor
where T_DP4 : DataProcessor
where T_DP5 : DataProcessor
where T_DP6 : DataProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> and 6 <see cref="DPSBase.DataProcessor"/>s while will be used are passed as generic parameters
/// Further options can be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s as an argument which may be null
/// 初始化一个新的SendReceiveOptions实例 数据序列化器和六个数据处理器作为泛型参数传递
/// 相关的选项(可以为空)可以作为参数传递给序列化器和处理器
/// </summary>
/// <param name="options">Additional options to be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s</param>
public SendReceiveOptions(Dictionary<string, string> options)
: base(options)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = new List<DataProcessor>() {
DPSManager.GetDataProcessor<T_DP1>(),
DPSManager.GetDataProcessor<T_DP2>(),
DPSManager.GetDataProcessor<T_DP3>(),
DPSManager.GetDataProcessor<T_DP4>(),
DPSManager.GetDataProcessor<T_DP5>(),
DPSManager.GetDataProcessor<T_DP6>() };
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
}
/// <inheritdoc />
/// <typeparam name="T_DS">The type of <see cref="DPSBase.DataSerializer"/> to use</typeparam>
/// <typeparam name="T_DP1">The type of the first <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP2">The type of the second <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP3">The type of the third <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP4">The type of the fourth <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP5">The type of the fifth <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP6">The type of the sixth <see cref="DPSBase.DataProcessor"/> to use</typeparam>
/// <typeparam name="T_DP7">The type of the seventh <see cref="DPSBase.DataProcessor"/> to use</typeparam>
public class SendReceiveOptions<T_DS, T_DP1, T_DP2, T_DP3, T_DP4, T_DP5, T_DP6, T_DP7> : SendReceiveOptions
where T_DS : DataSerializer
where T_DP1 : DataProcessor
where T_DP2 : DataProcessor
where T_DP3 : DataProcessor
where T_DP4 : DataProcessor
where T_DP5 : DataProcessor
where T_DP6 : DataProcessor
where T_DP7 : DataProcessor
{
/// <summary>
/// Initializes a new instance of the <see cref="SendReceiveOptions"/> class. The <see cref="DPSBase.DataSerializer"/> and 7 <see cref="DPSBase.DataProcessor"/>s while will be used are passed as generic parameters
/// Further options can be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s as an argument which may be null
/// 初始化一个新的SendReceiveOptions实例 数据序列化器和七个数据处理器作为泛型参数传递
/// 相关的选项(可以为空)可以作为参数传递给序列化器和处理器
/// </summary>
/// <param name="options">Additional options to be passed to the <see cref="DPSBase.DataSerializer"/> and <see cref="DPSBase.DataProcessor"/>s</param>
public SendReceiveOptions(Dictionary<string, string> options)
: base(options)
{
DataSerializer = DPSManager.GetDataSerializer<T_DS>();
DataProcessors = new List<DataProcessor>() {
DPSManager.GetDataProcessor<T_DP1>(),
DPSManager.GetDataProcessor<T_DP2>(),
DPSManager.GetDataProcessor<T_DP3>(),
DPSManager.GetDataProcessor<T_DP4>(),
DPSManager.GetDataProcessor<T_DP5>(),
DPSManager.GetDataProcessor<T_DP6>(),
DPSManager.GetDataProcessor<T_DP7>()};
if (DataSerializer == null)
throw new InvalidOperationException("Attempted to use null DataSerializer. If this exception is thrown DPSManager.GetDataSerializer<DS>() has failed.");
}
}
}
介绍开源的.net通信框架NetworkComms框架 源码分析(六)SendReceiveOptions的更多相关文章
- DotNetty网络通信框架学习之源码分析
DotNetty网络通信框架学习之源码分析 有关DotNetty框架,网上的详细资料不是很多,有不多的几个博友做了简单的介绍,也没有做深入的探究,我也根据源码中提供的demo做一下记录,方便后期查阅. ...
- 深入理解分布式调度框架TBSchedule及源码分析
简介 由于最近工作比较忙,前前后后花了两个月的时间把TBSchedule的源码翻了个底朝天.关于TBSchedule的使用,网上也有很多参考资料,这里不做过多的阐述.本文着重介绍TBSchedule的 ...
- 设计模式(十五)——命令模式(Spring框架的JdbcTemplate源码分析)
1 智能生活项目需求 看一个具体的需求 1) 我们买了一套智能家电,有照明灯.风扇.冰箱.洗衣机,我们只要在手机上安装 app 就可以控制对这些家电工作. 2) 这些智能家电来自不同的厂家,我们不想针 ...
- 设计模式(二十一)——解释器模式(Spring 框架中SpelExpressionParser源码分析)
1 四则运算问题 通过解释器模式来实现四则运算,如计算 a+b-c 的值,具体要求 1) 先输入表达式的形式,比如 a+b+c-d+e, 要求表达式的字母不能重复 2) 在分别输入 a ,b, c, ...
- $Django cbv源码分析 djangorestframework框架之APIView源码分析
1 CBV的源码分析 #视图 class login (View): pass #路由 url(r'^books/$', views.login.as_view()) #阅读源码: #左侧工程栏--- ...
- motan源码分析六:客户端与服务器的通信层分析
本章将分析motan的序列化和底层通信相关部分的代码. 1.在上一章中,有一个getrefers的操作,来获取所有服务器的引用,每个服务器的引用都是由DefaultRpcReferer来创建的 pub ...
- ④NuPlayer播放框架之Renderer源码分析
[时间:2016-11] [状态:Open] [关键词:android,nuplayer,开源播放器,播放框架,渲染器,render] 0 导读 之前我们分析了NuPlayer的实现代码,本文将重点聚 ...
- ⑤NuPlayer播放框架之GenericSource源码分析
[时间:2017-01] [状态:Open] [关键词:android,nuplayer,开源播放器,播放框架,GenericSource] 0 导读 GenericSource是NuPlayer:: ...
- ③NuPlayer播放框架之类NuPlayer源码分析
[时间:2016-10] [状态:Open] [关键词:android,nuplayer,开源播放器,播放框架] 0 引言 差不多一个月了,继续分析AOSP的播放框架的源码.这次我们需要深入分析的是N ...
- Laravel开发:Laravel框架门面Facade源码分析
前言 这篇文章我们开始讲 laravel 框架中的门面 Facade,什么是门面呢?官方文档: Facades(读音:/fəˈsäd/ )为应用程序的服务容器中可用的类提供了一个「静态」接口.Lara ...
随机推荐
- 我所理解的OOP——UML六种关系
最近由于经常给公司的小伙伴儿们讲一些OOP的基本东西,每次草纸都被我弄的很尴尬,画来画去自己都乱了,有时候也会尝试使用UML表示类之间的关系,但UML从毕业后就再也没接触过了,经常会被小伙伴儿们指出继 ...
- webservice3
什么是bottom up 什么是top down 通过浏览器访问如 http://localhost:8080/HelloWS/services/HelloWSsss?wsdl 获取的 wsdl, ...
- 桃小蛋 简单粗暴BFC总结—附代码图和效果图
说明:问题图与解决图的区别:黄色箭头那行代码的有和无. BFC 定义 BFC(Block formatting context)直译为"块级格式化上下文".它是一个独立的渲染区域, ...
- 每天一个linux命令(54):ping命令
Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”.不能打开网页时会说“你先ping网关地址192.168.1.1试试”. ...
- Node.js与Sails~自定义响应体responses
回到目录 在Node.js里,你可以控制请求和响应,自己可以定义自己的响应方式,如对文本如何响应,对json如何响应,对图像流如何响应等等,而这些在Sails架构里,变得更加容易和清晰了,它位于项目的 ...
- MVVM架构~knockoutjs系列之正则表达式使规则更灵活
返回目录 几乎每种验证架构都会有正则表达式的加盟,一般地,一种验证架构首先会提供一些标准的,常用的验证规则,它们通常是数字验证,电话验证,email验证,长度验证,范围验证,日期验证等,而如果使你的验 ...
- MVVM架构~knockoutjs系列之为validation.js扩展minLength和maxLength
返回目录 为什么要对minLength和maxLength这两个方法进行扩展呢,是因为这样一个需求,在用户注册时,可以由用户自己决定他们输入的字符,中文,英文,数字均可,这样做了之后,使用户的体验更好 ...
- github无法访问?试试修改hosts
github国内无法访问时,可以试试如下修改hosts,亲测有效: 204.232.175.78 http://documentcloud.github.com 207.97.227.239 http ...
- fir.im Weekly - 如何打造真正的工程师文化
好的工程师,无法忍受低效且无趣的工作.优秀的技术团队应该自上而下的地推进技术平台化建设.DevOps.自动化构建.测试和部署流程,积极采用合适的第三方工具或创造工具,进行周期性的前沿技术分享等等. 先 ...
- Oracle日期函数和循环总结
一,日期相关的函数 Select to_char(sysdate,'Q') from dual;--指定日期的季度 Select to_char(sysdate,'MM') from dual;--月 ...