コード例 #1
0
        /// <summary>
        /// This pipeline command creates a Persistence Message Initiator.
        /// </summary>
        /// <typeparam name="C">The incoming channel type.</typeparam>
        /// <typeparam name="K">The key type.</typeparam>
        /// <typeparam name="E">The entity type.</typeparam>
        /// <param name="cpipe">The incoming channel.</param>
        /// <param name="responseChannel">The channel to send the response message on. If this channel does not exist, and exception will be thrown.</param>
        /// <param name="command">The output command.</param>
        /// <param name="cacheManager">The cache manager to attach to the persistence agent</param>
        /// <param name="startupPriority"></param>
        /// <param name="defaultRequestTimespan">The default time out time. If not set, this defaults to 30s as set in the command initiator policy.</param>
        /// <param name="verifyChannel">This boolean value by default is true. It ensure the channel names passed exists. Set this to false if you do not want this check to happen.</param>
        /// <returns>The passthrough for the channel.</returns>
        public static C AttachPersistenceClient <C, K, E>(this C cpipe
                                                          , string responseChannel
                                                          , out PersistenceClient <K, E> command
                                                          , int startupPriority = 90
                                                          , ICacheManager <K, E> cacheManager = null
                                                          , TimeSpan?defaultRequestTimespan   = null
                                                          , bool verifyChannel = true
                                                          )
            where C : IPipelineChannelOutgoing <IPipeline>
            where K : IEquatable <K>
        {
            command = new PersistenceClient <K, E>(cacheManager, defaultRequestTimespan);

            if (responseChannel == null)
            {
                throw new ArgumentNullException("responseChannel", $"{nameof(AttachPersistenceClient)}: responseChannel cannot be null.");
            }

            //Check that the response channel exists
            if (verifyChannel && !cpipe.ToMicroservice().Communication.HasChannel(responseChannel, ChannelDirection.Incoming))
            {
                throw new ChannelDoesNotExistException(responseChannel, ChannelDirection.Incoming, cpipe.ToMicroservice().Id.Name);
            }

            //If the response channel is not set, dynamically create a response channel.
            command.ResponseChannelId = responseChannel;

            command.ChannelId      = cpipe.Channel.Id;
            command.RoutingDefault = ProcessOptions.RouteExternal;

            cpipe.Pipeline.AddCommand(command, startupPriority);

            return(cpipe);
        }
コード例 #2
0
        /// <summary>
        /// This pipeline command creates a Persistence Message Initiator.
        /// </summary>
        /// <typeparam name="C">The incoming channel type.</typeparam>
        /// <typeparam name="K">The key type.</typeparam>
        /// <typeparam name="E">The entity type.</typeparam>
        /// <param name="cpipe">The incoming channel.</param>
        /// <param name="command">The output command.</param>
        /// <param name="responseChannel">The channel to send the response message on. If this is not set, a default response channel will be created.</param>
        /// <param name="startupPriority"></param>
        /// <param name="cacheManager">The cache manager to attach to the persistence agent</param>
        /// <param name="defaultRequestTimespan">The default time out time. If not set, this defaults to 30s as set in the command initiator policy.</param>
        /// <param name="routing">The route map will attempt to first route the message internally and then try an external channel.</param>
        /// <returns>The pass through for the channel.</returns>
        public static C AttachPersistenceClient <C, K, E>(this C cpipe
                                                          , out PersistenceClient <K, E> command
                                                          , string responseChannel            = null
                                                          , int startupPriority               = 90
                                                          , ICacheManager <K, E> cacheManager = null
                                                          , TimeSpan?defaultRequestTimespan   = null
                                                          , ProcessOptions routing            = ProcessOptions.RouteExternal | ProcessOptions.RouteInternal
                                                          )
            where C : IPipelineChannelIncoming <IPipeline>
            where K : IEquatable <K>
        {
            command = new PersistenceClient <K, E>(cacheManager, defaultRequestTimespan);

            bool channelInternalOnly = responseChannel == null;

            if (channelInternalOnly)
            {
                responseChannel = $"PersistenceClient{command.ComponentId.ToString("N").ToUpperInvariant()}";
            }

            if (!cpipe.ToMicroservice().Communication.HasChannel(responseChannel, ChannelDirection.Incoming))
            {
                var outPipe = cpipe.ToPipeline().AddChannelIncoming(responseChannel, isAutocreated: true, internalOnly: channelInternalOnly, description: $"Persistence Client Response: {typeof(E).Name}");
                command.ResponseChannelId = outPipe.Channel.Id;
            }
            else
            {
                //If the response channel is not set, dynamically create a response channel.
                command.ResponseChannelId = responseChannel;
            }

            //Check that the response channel exists
            if (!cpipe.ToMicroservice().Communication.HasChannel(command.ResponseChannelId, ChannelDirection.Incoming))
            {
                throw new ChannelDoesNotExistException(command.ResponseChannelId, ChannelDirection.Incoming, cpipe.ToMicroservice().Id.Name);
            }

            command.ChannelId      = cpipe.Channel.Id;
            command.RoutingDefault = routing;

            cpipe.Pipeline.AddCommand(command, startupPriority);

            return(cpipe);
        }
コード例 #3
0
        /// <summary>
        /// This method attaches the persistence initiator and registers it with Unity for registration
        /// with the controllers.
        /// </summary>
        /// <typeparam name="C">The Unity Web pipe type.</typeparam>
        /// <typeparam name="K">The key type.</typeparam>
        /// <typeparam name="E">The entity type.</typeparam>
        /// <param name="cpipe">The pipe.</param>
        /// <param name="command">The command created.</param>
        /// <param name="outgoingChannel">The channel to make requests.</param>
        /// <param name="startupPriority">The startup priority</param>
        /// <param name="cacheManager">The optional cache manager.</param>
        /// <param name="defaultRequestTimespan">The default timeout.</param>
        /// <returns>Returns the pipe.</returns>
        public static C AttachPersistenceMessageInitiatorUnity <C, K, E>(this C cpipe
                                                                         , out PersistenceClient <K, E> command
                                                                         , string outgoingChannel
                                                                         , int startupPriority = 90
                                                                         , ICacheManager <K, E> cacheManager = null
                                                                         , TimeSpan?defaultRequestTimespan   = null
                                                                         )
            where C : IPipelineChannelOutgoing <IPipelineWebApiUnity>
            where K : IEquatable <K>
        {
            var ms = cpipe.ToMicroservice();

            command = new PersistenceClient <K, E>(cacheManager, defaultRequestTimespan)
            {
                ResponseChannelId = cpipe.Channel.Id
                , ChannelId       = outgoingChannel
            };

            cpipe.Pipeline.AddCommand(command, startupPriority);

            cpipe.Pipeline.Unity.RegisterInstance(typeof(IRepositoryAsync <K, E>), command);

            return(cpipe);
        }