原文网址: 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的更多相关文章

  1. DotNetty网络通信框架学习之源码分析

    DotNetty网络通信框架学习之源码分析 有关DotNetty框架,网上的详细资料不是很多,有不多的几个博友做了简单的介绍,也没有做深入的探究,我也根据源码中提供的demo做一下记录,方便后期查阅. ...

  2. 深入理解分布式调度框架TBSchedule及源码分析

    简介 由于最近工作比较忙,前前后后花了两个月的时间把TBSchedule的源码翻了个底朝天.关于TBSchedule的使用,网上也有很多参考资料,这里不做过多的阐述.本文着重介绍TBSchedule的 ...

  3. 设计模式(十五)——命令模式(Spring框架的JdbcTemplate源码分析)

    1 智能生活项目需求 看一个具体的需求 1) 我们买了一套智能家电,有照明灯.风扇.冰箱.洗衣机,我们只要在手机上安装 app 就可以控制对这些家电工作. 2) 这些智能家电来自不同的厂家,我们不想针 ...

  4. 设计模式(二十一)——解释器模式(Spring 框架中SpelExpressionParser源码分析)

    1 四则运算问题 通过解释器模式来实现四则运算,如计算 a+b-c 的值,具体要求 1) 先输入表达式的形式,比如 a+b+c-d+e,  要求表达式的字母不能重复 2) 在分别输入 a ,b, c, ...

  5. $Django cbv源码分析 djangorestframework框架之APIView源码分析

    1 CBV的源码分析 #视图 class login (View): pass #路由 url(r'^books/$', views.login.as_view()) #阅读源码: #左侧工程栏--- ...

  6. motan源码分析六:客户端与服务器的通信层分析

    本章将分析motan的序列化和底层通信相关部分的代码. 1.在上一章中,有一个getrefers的操作,来获取所有服务器的引用,每个服务器的引用都是由DefaultRpcReferer来创建的 pub ...

  7. ④NuPlayer播放框架之Renderer源码分析

    [时间:2016-11] [状态:Open] [关键词:android,nuplayer,开源播放器,播放框架,渲染器,render] 0 导读 之前我们分析了NuPlayer的实现代码,本文将重点聚 ...

  8. ⑤NuPlayer播放框架之GenericSource源码分析

    [时间:2017-01] [状态:Open] [关键词:android,nuplayer,开源播放器,播放框架,GenericSource] 0 导读 GenericSource是NuPlayer:: ...

  9. ③NuPlayer播放框架之类NuPlayer源码分析

    [时间:2016-10] [状态:Open] [关键词:android,nuplayer,开源播放器,播放框架] 0 引言 差不多一个月了,继续分析AOSP的播放框架的源码.这次我们需要深入分析的是N ...

  10. Laravel开发:Laravel框架门面Facade源码分析

    前言 这篇文章我们开始讲 laravel 框架中的门面 Facade,什么是门面呢?官方文档: Facades(读音:/fəˈsäd/ )为应用程序的服务容器中可用的类提供了一个「静态」接口.Lara ...

随机推荐

  1. python 模块加载

    python 模块加载 本文主要介绍python模块加载的过程. module的组成 所有的module都是由对象和对象之间的关系组成. type和object python中所有的东西都是对象,分为 ...

  2. Atitit 理解Monad attilax总结

    Atitit 理解Monad attilax总结 但函数式编程最大的一个问题是,函数是一个数学抽象,在现实世界中不存在,1 那既然这样就够用了,还要 Monad 干嘛?Monad 的作用在这里就体现出 ...

  3. Atitit atiuse软件系列

    Atitit atiuse软件系列 1.1.  Atian inputmethod 输入法 方言与多语言多文字支持 (au)1 1.2. File searcher 文件搜索器,支持压缩文件与正则表达 ...

  4. Python的闭包

    Python的闭包 闭包概念都是一样的,实现机制一样,看看下面的代码是不是和javascript很像 def generate_counter(): cnt = [0] def count_one() ...

  5. Java连接MongoDB进行增删改查

    1.导入必须的包: 详情看项目:http://pan.baidu.com/s/1cvDAOY 2.通过Myeclipse创建WEB项目 3. 3.bean:创建实体类 package com.bean ...

  6. 一次SSIS Package的调试经历

    SSIS Package的调试有时是一个非常艰难的过程,由于SSIS 编译器给出的错误信息,可能并不完善,需要程序员根据错误信息抽丝拨茧,寻找错误的根源,进而解决问题. 第一部分:SSIS提供的调试工 ...

  7. How Spring Boot Autoconfiguration Magic Works--转

    原文地址:https://dzone.com/articles/how-springboot-autoconfiguration-magic-works In my previous post &qu ...

  8. Testing - 测试基础 - 分类

    对软件内部结构的深入程度 黑盒测试:又叫功能测试.数据驱动测试或基于需求规格说明书的功能测试. 白盒测试:又称结构测试.逻辑驱动测试或基于程序代码内部构成的测试. 灰盒测试:包含性能测试.自动化测试. ...

  9. 优秀工具推荐:超实用的 CSS 库,样板和框架

    当启动一个新的项目,使用 CSS 框架或样板,可以帮助您节省大量的时间.在这篇文章中,我编译整理了我最喜欢的 CSS 样板,框架和库,帮助你在建立网站或应用程序时更加高效. 您可能感兴趣的相关文章 精 ...

  10. 实现ASP.NET无刷新下载并提示下载完成

    先上代码,后面再进行说明. 以下是前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehi ...