Esempio n. 1
0
        public static IPipe <ConsumeContext <TMessage> > BuildMessagePipe <TConsumer, TMessage, T>(
            IPipeSpecification <ConsumerConsumeContext <T> >[] pipeSpecifications, IFilter <ConsumeContext <TMessage> > messageFilter)
            where TMessage : class where T : class where TConsumer : class
        {
            return(Pipe.New <ConsumeContext <TMessage> >(x =>
            {
                var messagePipeBuilder = new MessagePipeBuilder <TConsumer, TMessage, T>();
                for (var i = 0; i < pipeSpecifications.Length; i++)
                {
                    pipeSpecifications[i].Apply(messagePipeBuilder);
                }

                var pipeBuilder = messagePipeBuilder as MessagePipeBuilder <TConsumer, TMessage, TConsumer>;
                if (pipeBuilder == null)
                {
                    throw new InvalidOperationException("Should not be null, ever");
                }

                foreach (IFilter <ConsumeContext <TMessage> > filter in pipeBuilder.Filters)
                {
                    x.UseFilter(filter);
                }

                x.UseFilter(messageFilter);
            }));
        }
        IPipe <ConsumeContext <TMessage> > BuildMessagePipe <T>(IPipeSpecification <ConsumerConsumeContext <T> >[] pipeSpecifications,
                                                                IConsumerFactory <TConsumer> consumerFactory, IPipe <ConsumerConsumeContext <TConsumer, TMessage> > consumerPipe)
            where T : class
        {
            return(Pipe.New <ConsumeContext <TMessage> >(x =>
            {
                var messagePipeBuilder = new MessagePipeBuilder <T>();
                for (int i = 0; i < pipeSpecifications.Length; i++)
                {
                    pipeSpecifications[i].Apply(messagePipeBuilder);
                }

                var pipeBuilder = messagePipeBuilder as MessagePipeBuilder <TConsumer>;
                if (pipeBuilder == null)
                {
                    throw new InvalidOperationException("Should not be null, ever");
                }

                foreach (var filter in pipeBuilder.Filters)
                {
                    x.UseFilter(filter);
                }

                x.UseFilter(new ConsumerMessageFilter <TConsumer, TMessage>(consumerFactory, consumerPipe));
            }));
        }
Esempio n. 3
0
        ConnectHandle IConsumerConnector.ConnectConsumer <T>(IConsumePipeConnector consumePipe, IConsumerFactory <T> consumerFactory,
                                                             IPipeSpecification <ConsumerConsumeContext <T> >[] pipeSpecifications)
        {
            var factory = consumerFactory as IConsumerFactory <TConsumer>;

            if (factory == null)
            {
                throw new ArgumentException("The consumer factory type does not match: " + TypeMetadataCache <T> .ShortName);
            }

            IPipe <ConsumerConsumeContext <TConsumer, TMessage> > consumerPipe = ConsumerPipeBuilder.BuildConsumerPipe(_consumeFilter, pipeSpecifications);

            IPipe <ConsumeContext <TMessage> > messagePipe = MessagePipeBuilder.BuildMessagePipe <TConsumer, TMessage, T>(pipeSpecifications, new ConsumerMessageFilter <TConsumer, TMessage>(factory, consumerPipe));

            return(consumePipe.ConnectConsumePipe(messagePipe));
        }
Esempio n. 4
0
        ConnectHandle IInstanceConnector.ConnectInstance <T>(IConsumePipeConnector consumePipe, T instance,
                                                             IPipeSpecification <ConsumerConsumeContext <T> >[] pipeSpecifications)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            var consumer = instance as TConsumer;

            if (consumer == null)
            {
                throw new ConsumerException(
                          $"The instance type {instance.GetType().GetTypeName()} does not match the consumer type: {TypeMetadataCache<TConsumer>.ShortName}");
            }

            IPipe <ConsumerConsumeContext <TConsumer, TMessage> > consumerPipe = ConsumerPipeBuilder.BuildConsumerPipe(_consumeFilter, pipeSpecifications);

            IPipe <ConsumeContext <TMessage> > messagePipe = MessagePipeBuilder.BuildMessagePipe <TConsumer, TMessage, T>(pipeSpecifications,
                                                                                                                          new InstanceMessageFilter <TConsumer, TMessage>(consumer, consumerPipe));

            return(consumePipe.ConnectConsumePipe(messagePipe));
        }