Esempio n. 1
0
        private AbstractEndpoint GetEndpoint(List <Attribute> attributes, object result)
        {
            var endpoint = result as AbstractEndpoint;

            if (endpoint != null)
            {
                var autoStartup = MessagingAttributeUtils.ResolveAttribute <string>(attributes, "AutoStartup");
                if (!string.IsNullOrEmpty(autoStartup))
                {
                    autoStartup = ApplicationContext?.ResolveEmbeddedValue(autoStartup);
                    if (!string.IsNullOrEmpty(autoStartup))
                    {
                        endpoint.IsAutoStartup = bool.Parse(autoStartup);
                    }
                }

                var phase = MessagingAttributeUtils.ResolveAttribute <string>(attributes, "Phase");
                if (!string.IsNullOrEmpty(phase))
                {
                    phase = ApplicationContext?.ResolveEmbeddedValue(phase);
                    if (!string.IsNullOrEmpty(phase))
                    {
                        endpoint.Phase = int.Parse(phase);
                    }
                }
            }

            return(endpoint);
        }
Esempio n. 2
0
        protected virtual AbstractEndpoint CreateEndpoint(IMessageHandler handler, MethodInfo method, List <Attribute> annotations)
        {
            AbstractEndpoint endpoint = null;
            var inputChannelName      = MessagingAttributeUtils.ResolveAttribute <string>(annotations, InputChannelProperty);

            if (!string.IsNullOrEmpty(inputChannelName))
            {
                IMessageChannel inputChannel;
                try
                {
                    inputChannel = ChannelResolver.ResolveDestination(inputChannelName);
                    if (inputChannel == null)
                    {
                        inputChannel = new DirectChannel(ApplicationContext, inputChannelName);
                        ApplicationContext.Register(inputChannelName, inputChannel);
                    }
                }
                catch (DestinationResolutionException)
                {
                    inputChannel = new DirectChannel(ApplicationContext, inputChannelName);
                    ApplicationContext.Register(inputChannelName, inputChannel);
                }

                endpoint = DoCreateEndpoint(handler, inputChannel, annotations);
            }

            return(endpoint);
        }
Esempio n. 3
0
        protected virtual void SetOutputChannelIfPresent(List <Attribute> annotations, AbstractReplyProducingMessageHandler handler)
        {
            var outputChannelName = MessagingAttributeUtils.ResolveAttribute <string>(annotations, "OutputChannel");

            if (!string.IsNullOrEmpty(outputChannelName))
            {
                handler.OutputChannelName = outputChannelName;
            }
        }
Esempio n. 4
0
        public virtual bool ShouldCreateEndpoint(MethodInfo method, List <Attribute> attributes)
        {
            var inputChannel   = MessagingAttributeUtils.ResolveAttribute <string>(attributes, InputChannelProperty);
            var createEndpoint = !string.IsNullOrEmpty(inputChannel);

            if (!createEndpoint && ServiceAnnotationAware())
            {
                var isService = method.GetCustomAttribute <ServiceAttribute>() != null;
                if (isService)
                {
                    throw new InvalidOperationException("A channel name in '" + InputChannelProperty + "' is required when " + AnnotationType + " is used on '[Service]' methods.");
                }
            }

            return(createEndpoint);
        }
Esempio n. 5
0
        protected override IMessageHandler CreateHandler(object service, MethodInfo method, List <Attribute> attributes)
        {
            AbstractReplyProducingMessageHandler serviceActivator;

            if (method.GetCustomAttribute <ServiceAttribute>() != null)
            {
                // Service Attribute usage
                var target = ResolveTargetServiceFromMethodWithServiceAnnotation(method);
                serviceActivator = ExtractTypeIfPossible <AbstractReplyProducingMessageHandler>(target);
                if (serviceActivator == null)
                {
                    if (target is IMessageHandler handler)
                    {
                        /*
                         * Return a reply-producing message handler so that we still get 'produced no reply' messages
                         * and the super class will inject the advice chain to advise the handler method if needed.
                         */
                        return(new ReplyProducingMessageHandlerWrapper(ApplicationContext, handler));
                    }
                    else
                    {
                        serviceActivator = new ServiceActivatingHandler(ApplicationContext, target, method);
                    }
                }
                else
                {
                    CheckMessageHandlerAttributes(ResolveTargetServiceName(method), attributes);
                    return((IMessageHandler)target);
                }
            }
            else
            {
                serviceActivator = new ServiceActivatingHandler(ApplicationContext, service, method);
            }

            var requiresReply = MessagingAttributeUtils.ResolveAttribute <string>(attributes, "RequiresReply");

            if (!string.IsNullOrEmpty(requiresReply))
            {
                serviceActivator.RequiresReply = bool.Parse(ApplicationContext.ResolveEmbeddedValue(requiresReply));
            }

            SetOutputChannelIfPresent(attributes, serviceActivator);
            return(serviceActivator);
        }