Пример #1
0
        /// <summary>
        /// Attaches the UDP listener to the incoming channel.
        /// </summary>
        /// <typeparam name="C">The pipeline type.</typeparam>
        /// <param name="cpipe">The pipeline.</param>
        /// <param name="udp">The UDP endpoint configuration.</param>
        /// <param name="serializerId">Default serializer MIME Content-type id, i.e application/json.</param>
        /// <param name="compressionId">Default serializer MIME Content-encoding id, i.e. GZIP.</param>
        /// <param name="encryptionId">The encryption handler id.</param>
        /// <param name="requestAddress">This is the optional address fragment which specifies the incoming message destination. If this is not set then ("","") will be used. This does not include a channelId as this will be provided by the pipeline.</param>
        /// <param name="responseAddress">This is the optional return address destination to be set for the incoming messages.</param>
        /// <param name="requestAddressPriority">This is the default priority for the request message. The default is null. This will inherit from the channel priority.</param>
        /// <param name="responseAddressPriority">This is the priority for the response address. The default is 1.</param>
        /// <param name="serializer">This is an optional serializer that can be added with the specific mime type. Note:  the serializer mime type will be changed, so you should not share this serializer instance.</param>
        /// <param name="action">The optional action to be called when the listener is created.</param>
        /// <returns>Returns the pipeline.</returns>
        public static C AttachUdpListener <C>(this C cpipe
                                              , UdpConfig udp
                                              , SerializationHandlerId serializerId         = null
                                              , CompressionHandlerId compressionId          = null
                                              , EncryptionHandlerId encryptionId            = null
                                              , ServiceMessageHeaderFragment requestAddress = null
                                              , ServiceMessageHeader responseAddress        = null
                                              , int?requestAddressPriority              = null
                                              , int responseAddressPriority             = 1
                                              , IServiceHandlerSerialization serializer = null
                                              , Action <IListener> action = null
                                              )
            where C : IPipelineChannelIncoming <IPipeline>
        {
            serializerId = (serializerId?.Id ?? serializer?.Id ?? $"udp_in/{cpipe.Channel.Id}").ToLowerInvariant();

            var listener = new UdpCommunicationAgent(udp
                                                     , CommunicationAgentCapabilities.Listener
                                                     , serializerId, compressionId, encryptionId
                                                     , requestAddress, responseAddress, requestAddressPriority, responseAddressPriority
                                                     );

            if (serializer != null)
            {
                cpipe.Pipeline.AddPayloadSerializer(serializer);
            }

            cpipe.AttachListener(listener, action, true);

            return(cpipe);
        }
Пример #2
0
        /// <summary>
        /// Attaches the UDP sender to the outgoing channel.
        /// </summary>
        /// <typeparam name="C">The pipeline type.</typeparam>
        /// <param name="cpipe">The pipeline.</param>
        /// <param name="udp">The UDP endpoint configuration.</param>
        /// <param name="serializerId">Default serializer MIME Content-type id, i.e application/json.</param>
        /// <param name="compressionId">Default serializer MIME Content-encoding id, i.e. GZIP.</param>
        /// <param name="encryptionId">The encryption handler id.</param>
        /// <param name="serialize">The serialize action.</param>
        /// <param name="canSerialize">The optional serialize check function.</param>
        /// <param name="action">The optional action to be called when the sender is created.</param>
        /// <param name="maxUdpMessagePayloadSize">This is the max UDP message payload size. The default is 508 bytes. If you set this to null, the sender will not check the size before transmitting.</param>
        /// <returns>Returns the pipeline.</returns>
        public static C AttachUdpSender <C>(this C cpipe
                                            , UdpConfig udp
                                            , SerializationHandlerId serializerId             = null
                                            , CompressionHandlerId compressionId              = null
                                            , EncryptionHandlerId encryptionId                = null
                                            , Action <ServiceHandlerContext> serialize        = null
                                            , Func <ServiceHandlerContext, bool> canSerialize = null
                                            , Action <ISender> action      = null
                                            , int?maxUdpMessagePayloadSize = UdpHelper.PacketMaxSize
                                            )
            where C : IPipelineChannelOutgoing <IPipeline>
        {
            serializerId = (
                serializerId?.Id ?? $"udp_out/{cpipe.Channel.Id}"
                ).ToLowerInvariant();

            var sender = new UdpCommunicationAgent(udp
                                                   , CommunicationAgentCapabilities.Sender
                                                   , serializerId, compressionId, encryptionId
                                                   , maxUdpMessagePayloadSize: maxUdpMessagePayloadSize
                                                   );

            if (serialize != null)
            {
                cpipe.Pipeline.AddPayloadSerializer(serializerId
                                                    , serialize: serialize
                                                    , canSerialize: canSerialize);
            }

            cpipe.AttachSender(sender, action, true);

            return(cpipe);
        }
Пример #3
0
        /// <summary>
        /// Attaches the UDP listener to the incoming channel.
        /// </summary>
        /// <typeparam name="C">The pipeline type.</typeparam>
        /// <param name="cpipe">The pipeline.</param>
        /// <param name="udp">The UDP endpoint configuration.</param>
        /// <param name="defaultDeserializerContentType">Default deserializer MIME Content-type, i.e application/json.</param>
        /// <param name="defaultDeserializerContentEncoding">Default deserializer MIME Content-encoding, i.e. GZIP.</param>
        /// <param name="requestAddress">This is the optional address fragment which specifies the incoming message destination. If this is not set then ("","") will be used. This does not include a channelId as this will be provided by the pipeline.</param>
        /// <param name="responseAddress">This is the optional return address destination to be set for the incoming messages.</param>
        /// <param name="requestAddressPriority">This is the default priority for the request message. The default is null. This will inherit from the channel priority.</param>
        /// <param name="responseAddressPriority">This is the priority for the response address. The default is 1.</param>
        /// <param name="deserialize">The deserialize action.</param>
        /// <param name="canDeserialize">The deserialize check function.</param>
        /// <param name="action">The optional action to be called when the listener is created.</param>
        /// <returns>Returns the pipeline.</returns>
        public static C AttachUdpListener <C>(this C cpipe
                                              , UdpConfig udp
                                              , string defaultDeserializerContentType       = null
                                              , string defaultDeserializerContentEncoding   = null
                                              , ServiceMessageHeaderFragment requestAddress = null
                                              , ServiceMessageHeader responseAddress        = null
                                              , int?requestAddressPriority  = null
                                              , int responseAddressPriority = 1
                                              , Action <ServiceHandlerContext> deserialize        = null
                                              , Func <ServiceHandlerContext, bool> canDeserialize = null
                                              , Action <IListener> action = null
                                              )
            where C : IPipelineChannelIncoming <IPipeline>
        {
            defaultDeserializerContentType = (defaultDeserializerContentType ?? $"udp_in/{cpipe.Channel.Id}").ToLowerInvariant();

            var listener = new UdpCommunicationAgent(udp
                                                     , CommunicationAgentCapabilities.Listener
                                                     , defaultDeserializerContentType, defaultDeserializerContentEncoding, null
                                                     , requestAddress, responseAddress, requestAddressPriority, responseAddressPriority
                                                     );

            if (deserialize != null)
            {
                cpipe.Pipeline.AddPayloadSerializer(
                    defaultDeserializerContentType
                    , deserialize: deserialize
                    , canDeserialize: canDeserialize);
            }

            cpipe.AttachListener(listener, action, true);

            return(cpipe);
        }
Пример #4
0
        /// <summary>
        /// Attaches the UDP listener to the incoming channel.
        /// </summary>
        /// <typeparam name="C">The pipeline type.</typeparam>
        /// <param name="cpipe">The pipeline.</param>
        /// <param name="udp">The UDP endpoint configuration.</param>
        /// <param name="defaultDeserializerContentType">Default deserializer MIME Content-type, i.e application/json.</param>
        /// <param name="defaultDeserializerContentEncoding">Default deserializer MIME Content-encoding, i.e. GZIP.</param>
        /// <param name="requestAddress">This is the optional address fragment which specifies the incoming message destination. If this is not set then ("","") will be used. This does not include a channelId as this will be provided by the pipeline.</param>
        /// <param name="responseAddress">This is the optional return address destination to be set for the incoming messages.</param>
        /// <param name="requestAddressPriority">This is the default priority for the request message. The default is null. This will inherit from the channel priority.</param>
        /// <param name="responseAddressPriority">This is the priority for the response address. The default is 1.</param>
        /// <param name="serializer">This is an optional serializer that can be added with the specific mime type. Note:  the serializer mime type will be changed, so you should not share this serializer instance.</param>
        /// <param name="action">The optional action to be called when the listener is created.</param>
        /// <returns>Returns the pipeline.</returns>
        public static C AttachUdpListener <C>(this C cpipe
                                              , UdpConfig udp
                                              , string defaultDeserializerContentType       = null
                                              , string defaultDeserializerContentEncoding   = null
                                              , ServiceMessageHeaderFragment requestAddress = null
                                              , ServiceMessageHeader responseAddress        = null
                                              , int?requestAddressPriority         = null
                                              , int responseAddressPriority        = 1
                                              , IPayloadSerializer serializer      = null
                                              , Action <UdpChannelListener> action = null
                                              )
            where C : IPipelineChannelIncoming <IPipeline>
        {
            defaultDeserializerContentType = (
                defaultDeserializerContentType
                ?? serializer?.ContentType
                ?? $"udp_in/{cpipe.Channel.Id}"
                ).ToLowerInvariant();

            var listener = new UdpChannelListener(udp
                                                  , defaultDeserializerContentType, defaultDeserializerContentEncoding
                                                  , requestAddress, responseAddress, requestAddressPriority, responseAddressPriority
                                                  );

            if (serializer != null)
            {
                cpipe.Pipeline.AddPayloadSerializer(serializer, defaultDeserializerContentType);
            }

            cpipe.AttachListener(listener, action, true);

            return(cpipe);
        }
Пример #5
0
        /// <summary>
        /// Attaches the UDP sender to the outgoing channel.
        /// </summary>
        /// <typeparam name="C">The pipeline type.</typeparam>
        /// <param name="cpipe">The pipeline.</param>
        /// <param name="udp">The UDP endpoint configuration.</param>
        /// <param name="defaultSerializerContentType">Default serializer MIME Content-type, i.e application/json.</param>
        /// <param name="defaultSerializerContentTypeEncoding">Default serializer MIME Content-encoding, i.e. GZIP.</param>
        /// <param name="serialize">The serialize action.</param>
        /// <param name="canSerialize">The optional serialize check function.</param>
        /// <param name="action">The optional action to be called when the sender is created.</param>
        /// <param name="maxUdpMessagePayloadSize">This is the max UDP message payload size. The default is 508 bytes. If you set this to null, the sender will not check the size before transmitting.</param>
        /// <returns>Returns the pipeline.</returns>
        public static C AttachUdpSender <C>(this C cpipe
                                            , UdpConfig udp
                                            , string defaultSerializerContentType           = null
                                            , string defaultSerializerContentTypeEncoding   = null
                                            , Action <SerializationHolder> serialize        = null
                                            , Func <SerializationHolder, bool> canSerialize = null
                                            , Action <UdpChannelSender> action = null
                                            , int?maxUdpMessagePayloadSize     = UdpHelper.PacketMaxSize
                                            )
            where C : IPipelineChannelOutgoing <IPipeline>
        {
            defaultSerializerContentType = (
                defaultSerializerContentType
                ?? $"udp_out/{cpipe.Channel.Id}"
                ).ToLowerInvariant();

            var sender = new UdpChannelSender(udp, defaultSerializerContentType, defaultSerializerContentTypeEncoding, maxUdpMessagePayloadSize);

            if (serialize != null)
            {
                cpipe.Pipeline.AddPayloadSerializer(defaultSerializerContentType
                                                    , serialize: serialize
                                                    , canSerialize: canSerialize);
            }

            cpipe.AttachSender(sender, action, true);

            return(cpipe);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UdpHelper"/> class.
        /// </summary>
        public UdpHelper(UdpConfig udp, UdpHelperMode mode)
        {
            Config = udp;
            Mode   = mode;

            mConnectionsListener = new Dictionary <IPEndPoint, State>();
            mConnectionsSender   = new Dictionary <IPEndPoint, State>();

            mIncomingPending = new ConcurrentQueue <Message>();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UdpChannelSender"/> class.
 /// </summary>
 /// <param name="udp">The UDP endpoint configuration.</param>
 /// <param name="contentType">The MIME Content Type which is used to identify the serializer.</param>
 /// <param name="contentEncoding">The optional content encoding for the binary blob.</param>
 /// <param name="maxUdpMessagePayloadSize">This is the max UDP message payload size. The default is 508 bytes. If you set this to null, the sender will not check the size before transmitting.</param>
 public UdpChannelSender(UdpConfig udp
                         , string contentType
                         , string contentEncoding       = null
                         , int?maxUdpMessagePayloadSize = UdpHelper.PacketMaxSize
                         )
 {
     Config          = udp;
     ContentType     = contentType;
     ContentEncoding = contentEncoding;
     UdpMessageMaximumPayloadSize = maxUdpMessagePayloadSize;
 }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UdpChannelSender"/> class.
 /// </summary>
 /// <param name="udp">The UDP endpoint configuration.</param>
 /// <param name="contentType">The MIME Content Type which is used to specify the serialization handler.</param>
 /// <param name="contentEncoding">The optional content encoding handler for the binary blob.</param>
 /// <param name="encryption">The optional payload encryption handler.</param>
 /// <param name="maxUdpMessagePayloadSize">This is the max UDP message payload size. The default is 508 bytes. If you set this to null, the sender will not check the size before transmitting.</param>
 public UdpChannelSender(UdpConfig udp
                         , SerializationHandlerId contentType
                         , CompressionHandlerId contentEncoding = null
                         , EncryptionHandlerId encryption       = null
                         , int?maxUdpMessagePayloadSize         = UdpHelper.PacketMaxSize
                         )
 {
     Config          = udp;
     ContentType     = contentType ?? throw new ArgumentNullException("contentType");
     ContentEncoding = contentEncoding;
     Encryption      = encryption;
     UdpMessageMaximumPayloadSize = maxUdpMessagePayloadSize;
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UdpCommunicationAgent"/> class.
 /// </summary>
 /// <param name="config">The UDP endpoint configuration.</param>
 /// <param name="serializerId">The optional serializer identifier.</param>
 /// <param name="compressionId">The optional compression identifier.</param>
 /// <param name="encryptionId">The optional encryption identifier.</param>
 /// <param name="requestAddress">The optional request address.</param>
 /// <param name="responseAddress">The optional response address.</param>
 /// <param name="requestAddressPriority">The optional request address priority.</param>
 /// <param name="responseAddressPriority">The optional response address priority.</param>
 /// <param name="capabilities">The agent capabilities. The default is bidirectional.</param>
 /// <param name="maxUdpMessagePayloadSize">Maximum size of the UDP message payload.</param>
 public UdpCommunicationAgent(UdpConfig config
                              , CommunicationAgentCapabilities capabilities = CommunicationAgentCapabilities.Bidirectional
                              , SerializationHandlerId serializerId         = null
                              , CompressionHandlerId compressionId          = null
                              , EncryptionHandlerId encryptionId            = null
                              , ServiceMessageHeaderFragment requestAddress = null
                              , ServiceMessageHeader responseAddress        = null
                              , int?requestAddressPriority   = null
                              , int responseAddressPriority  = 1
                              , int?maxUdpMessagePayloadSize = UdpHelper.PacketMaxSize
                              ) : base(capabilities, serializerId, compressionId, encryptionId)
 {
     mConfig = config ?? throw new ArgumentNullException("config", "Udp configuration cannot be null.");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="UdpChannelListener"/> class.
 /// </summary>
 /// <param name="udp">The UDP endpoint configuration.</param>
 /// <param name="contentType">The MIME Content Type which is used to identify the deserializer.</param>
 /// <param name="contentEncoding">The optional content encoding.</param>
 /// <param name="requestAddress">This is the optional address fragment which specifies the incoming message destination. If this is not set then ("","") will be used. This does not include a channelId as this will be provided by the pipeline.</param>
 /// <param name="responseAddress">This is the optional return address destination to be set for the incoming messages.</param>
 /// <param name="requestAddressPriority">This is the default priority for the request message. The default is 1.</param>
 /// <param name="responseAddressPriority">This is the priority for the response address. The default is 1.</param>
 public UdpChannelListener(UdpConfig udp
                           , string contentType, string contentEncoding  = null
                           , ServiceMessageHeaderFragment requestAddress = null
                           , ServiceMessageHeader responseAddress        = null
                           , int?requestAddressPriority  = null
                           , int responseAddressPriority = 1
                           )
 {
     Config                  = udp;
     ContentType             = contentType;
     ContentEncoding         = contentEncoding;
     RequestAddress          = requestAddress ?? ("", "");
     RequestAddressPriority  = requestAddressPriority;
     ResponseAddress         = responseAddress;
     ResponseAddressPriority = responseAddressPriority;
 }