コード例 #1
0
        /// <summary>
        /// This extension adds the inline command to the pipeline
        /// </summary>
        /// <typeparam name="P">The pipeline type.</typeparam>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="commandFunction">The command function.</param>
        /// <param name="header">The destination fragment</param>
        /// <param name="referenceId">The optional command reference id</param>
        /// <param name="startupPriority">The command startup priority.</param>
        /// <param name="channelIncoming">The incoming channel. This is optional if you pass channel information in the header.</param>
        /// <param name="autoCreateChannel">Set this to true if you want the incoming channel created if it does not exist. The default is true.</param>
        /// <returns>Returns the pipeline.</returns>
        public static P AddCommand <P>(this P pipeline
                                       , Func <CommandMethodRequestContext, Task> commandFunction
                                       , ServiceMessageHeaderFragment header
                                       , string referenceId  = null
                                       , int startupPriority = 100
                                       , IPipelineChannelIncoming <P> channelIncoming = null
                                       , bool autoCreateChannel = true
                                       )
            where P : IPipeline
        {
            ServiceMessageHeader location;

            if (header is ServiceMessageHeader)
            {
                location = (ServiceMessageHeader)header;
            }
            else
            {
                if (channelIncoming == null)
                {
                    throw new ChannelIncomingMissingException();
                }
                location = (channelIncoming.Channel.Id, header);
            }

            var command = new CommandMethodInline(location, commandFunction, referenceId);

            pipeline.AddCommand(command, startupPriority, null, channelIncoming);

            return(pipeline);
        }
コード例 #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 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>
        /// This extension adds the inline command to the pipeline
        /// </summary>
        /// <typeparam name="E">The pipeline type.</typeparam>
        /// <param name="cpipe">The pipeline.</param>
        /// <param name="commandFunction">The command function.</param>
        /// <param name="header">The header.</param>
        /// <param name="referenceId">The reference identifier.</param>
        /// <param name="startupPriority">The startup priority.</param>
        /// <returns>Returns the pipeline.</returns>
        public static E AttachCommand <E>(this E cpipe
                                          , Func <CommandMethodRequestContext, Task> commandFunction
                                          , ServiceMessageHeaderFragment header
                                          , string referenceId  = null
                                          , int startupPriority = 100
                                          )
            where E : IPipelineChannelIncoming <IPipeline>
        {
            cpipe.ToPipeline().AddCommand(commandFunction, header, referenceId, startupPriority, cpipe);

            return(cpipe);
        }
コード例 #6
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.");
 }
コード例 #7
0
 /// <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;
 }
コード例 #8
0
        /// <summary>
        /// This method matches two headers. It expands on equal and matches based on a partial key match.
        /// </summary>
        /// <param name="other">The other header to compare.</param>
        /// <returns>Returns true if it is a match.</returns>
        public bool IsMatch(ServiceMessageHeaderFragment other)
        {
            if (MessageType == null)
            {
                return(true);
            }

            if (!string.Equals(MessageType, other.MessageType, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            if (ActionType == null)
            {
                return(true);
            }

            return(string.Equals(ActionType, other.ActionType, StringComparison.InvariantCultureIgnoreCase));
        }
コード例 #9
0
 /// <summary>
 /// This method creates a service message and injects it in to the execution path and bypasses the listener infrastructure.
 /// </summary>
 /// <param name="header">The message header fragment to identify the recipient. The channel will be inserted by the command harness.</param>
 /// <param name="package">The object package to process.</param>
 /// <param name="ChannelPriority">The priority that the message should be processed. The default is 1. If this message is not a valid value, it will be matched to the nearest valid value.</param>
 /// <param name="options">The process options.</param>
 /// <param name="release">The release action which is called when the payload has been executed by the receiving commands.</param>
 /// <param name="responseHeader">This is the optional response header</param>
 /// <param name="ResponseChannelPriority">This is the response channel priority. This will be set if the response header is not null. The default priority is 1.</param>
 /// <param name="originatorServiceId">This optional parameter allows you to set the originator serviceId</param>
 public void Process(ServiceMessageHeaderFragment header
                     , object package                      = null
                     , int ChannelPriority                 = 1
                     , ProcessOptions options              = ProcessOptions.RouteExternal | ProcessOptions.RouteInternal
                     , Action <bool, Guid> release         = null
                     , ServiceMessageHeader responseHeader = null
                     , int ResponseChannelPriority         = 1
                     , string originatorServiceId          = null
                     )
 {
     Process((Policy.ChannelId, header)
             , package
             , ChannelPriority
             , options
             , release
             , responseHeader
             , ResponseChannelPriority
             , originatorServiceId
             );
 }