原文网址: 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. Java-小练习简单银行程序

    2练习1:创建一个简单的银行程序包   练习目标-Java 语言中面向对象的封装性及构造器的使用. 任务 在这个练习里,创建一个简单版本的(账户类)Account类.将这个源文件放入banking程序 ...

  2. 什么是P3O?

    P3O(Portfolio, Programme and Project Offices)项目组合.项目群和项目办公室资格认证. 是由英国商务部 OGC 于2008年10月28日发布的最新的最佳实践指 ...

  3. 移动端基于HTML模板和JSON数据的JavaScript交互

    写本文之前,我正在做一个基于Tab页的订单中心: 每点击一个TAB标签,会请求对应状态的订单列表.之前的项目,我会在js里使用 +  连接符连接多个html内容: var html = ''; htm ...

  4. Android 4.2版本以下使用WebView组件addJavascriptInterface方法存在JS漏洞

    JS注入漏洞存在的Android版本:Android < 4.2 综述:Android的SDK中提供了一个WebView组件,用于在应用中嵌入一个浏览器来进行网页浏览.WebView组件中的ad ...

  5. instanceof, typeof, & Object.prototype.toString

    /** * * @authors Your Name (you@example.org) * @date 2016-11-18 09:31:23 * @version $Id$ */instanceo ...

  6. javaweb+SSH实现简单的权限管理系统

    权限管理,平时里很多地方我们都可以看到,比如聊QQ时群里的群主.管理员以及成员之间的功能是不一样的--大家一定会遇到的一个问题,所以整理 一下自己写权限系统的一些经验给大家,只起参考作用,也望大家笑纳 ...

  7. ASP.NET MVC在线人数统计

    在Global.asax.cs文件中代码: protected void Application_Start() { Application[; AreaRegistration.RegisterAl ...

  8. 程序是如何执行的(一)a=a+1

    本文链接:http://www.orlion.ml/35/ 一.概述 1.计算机中有两个主要的核心部件:CPU和内存,其中CPU负责运算而内存负责存储程序和相关的变量,每一条程序语句和变量都在内存中有 ...

  9. jxl写入excel实现数据导出功能

    @RequestMapping(params = "method=export", method = RequestMethod.GET) public void exportCo ...

  10. codeforces B. Pasha and String(贪心)

    题意:给定一个长度为len的字符序列,然后是n个整数,对于每一个整数ai, 将字符序列区间为[ai,len-ai+1]进行反转.求出经过n次反转之后的序列! /* 思路1:将区间为偶数次的直接去掉!对 ...