原文网址: 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. 哪些JavaScript IDE最好用?

    阅读本文之前,分享大家一张图片,看图会发现JavaScript开发需求最高,占比达到42.84%,因此掌握JavaScript语言好工作就不愁啦,工欲善其事必先利其器,那么选择IDE来开发是至关重要的 ...

  2. 【重要更新】Senparc.Weixin.Open v1.5.1

    本次更新调整了命名空间和文件位置,具体变化为(可以直接在源代码中替换): 旧命名空间(对应文件夹) 新命名空间(对应文件夹) Senparc.Weixin.Open.OAuth Senparc.Wei ...

  3. C-Lodop 非典型应用

    Lodop是什么? 有人说她是报表打印工具,因为那个add_print_table语句把报表统计的那点事弄了个明明白白: 有人说她是条码打印工具,因为用了她再也不用后台生成条码图片了,前端一行指令就动 ...

  4. CSS3与页面布局学习总结(四)——页面布局大全BFC、定位、浮动、7种垂直居中方法

    目录 一.BFC与IFC 1.1.BFC与IFC概要 1.2.如何产生BFC 1.3.BFC的作用与特点 二.定位 2.2.relative 2.3.absolute 2.4.fixed 2.5.z- ...

  5. fir.im Weekly - 给 Mac 应用开发者的教程

    写作是一件苦差事.无论写代码,还是写文章. 关于 Mac 应用开发,国内很少有完整的书籍或教程.最近@剑指人心写的 <Mac 应用开发基础教程>终于!完!稿!了! 这本书中对 Mac 平台 ...

  6. salesforce 零基础开发入门学习(五)异步进程介绍与数据批处理Batchable

    本篇知识参考:https://developer.salesforce.com/trailhead/force_com_dev_intermediate/asynchronous_apex/async ...

  7. ASP.NET MVC 拦截器IResultFilter

    在ASP.NET MVC中,有一个Result拦截器,实现ResultFilter需要继承一个类(System.Web.Mvc.FilterAttribute)和实现一个类(System.Web.Mv ...

  8. Python中的运算符

    说完常用的数据类型,再来说下运算符.运算符用于将各种类型的数据进行运算,让静态的数据跑起来. 编程语言中的运算大致分为以下几个大类: 算术运算, 用于加减乘除等数学运算 赋值运算,用于接收运算符或方法 ...

  9. python中常用的函数与库一

    1, collections.deque 在python里如果我们用列表作为队列使用也是可以的,只是当从队尾删除或者增加元素的时候是很快的,但是从队首删除或者增加元素则要慢得多,这是因为在队首进行操作 ...

  10. Package gp in the OpenCASCADE

    Package gp in the OpenCASCADE eryar@163.com China 一.简介 Introduction to Package gp gp是几何处理程序包(Geometr ...