示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommunicationAgentBase"/> class.
 /// </summary>
 /// <param name="capabilities">The agent capabilities. The default is bidirectional.</param>
 /// <param name="serializerId">The optional preferred serializer identifier.</param>
 /// <param name="compressionId">The optional preferred compression identifier.</param>
 /// <param name="encryptionId">The optional preferred encryption identifier.</param>
 protected CommunicationAgentBase(
     CommunicationAgentCapabilities capabilities = CommunicationAgentCapabilities.Bidirectional
     , SerializationHandlerId serializerId       = null
     , CompressionHandlerId compressionId        = null
     , EncryptionHandlerId encryptionId          = null) : base(capabilities, serializerId, compressionId, encryptionId)
 {
 }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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;
 }
 /// <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.");
 }