/// <summary>
        /// Adds the payload serializer.
        /// </summary>
        /// <typeparam name="P">The pipeline type.</typeparam>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="serializer">The serializer to add.</param>
        /// <returns>The pipeline.</returns>
        public static P AddPayloadSerializer <P>(this P pipeline, IServiceHandlerSerialization serializer)
            where P : IPipeline
        {
            pipeline.Service.ServiceHandlers.Serialization.Add(serializer);

            return(pipeline);
        }
Esempio n. 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="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 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
                                            , IServiceHandlerSerialization serializer = null
                                            , Action <ISender> action      = null
                                            , int?maxUdpMessagePayloadSize = UdpHelper.PacketMaxSize
                                            )
            where C : IPipelineChannelOutgoing <IPipeline>
        {
            serializerId = (
                serializerId?.Id
                ?? serializer?.Id
                ?? $"udp_out/{cpipe.Channel.Id}"
                ).ToLowerInvariant();

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

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

            cpipe.AttachSender(sender, action, true);

            return(cpipe);
        }
Esempio n. 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="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);
        }
        /// <summary>
        /// Tries to compress the outgoing holder.
        /// </summary>
        /// <param name="collection">The collection.</param>
        /// <param name="holder">The holder.</param>
        /// <returns>Returns true if the Content is serialized correctly to a binary blob.</returns>
        public static bool TrySerialize(this ServiceHandlerCollection <IServiceHandlerSerialization> collection, ServiceHandlerContext holder)
        {
            string id;

            if (!ServiceHandlerContainer.ExtractContentType(holder, out id))
            {
                return(false);
            }

            IServiceHandlerSerialization sr = null;

            if (!collection.TryGet(id, out sr))
            {
                return(false);
            }

            return(sr.TrySerialize(holder));
        }