コード例 #1
0
        public void InitializeSample()
        {
            _mocks = new MockRepository();
            _requestChannel = _mocks.StrictMock<IMessageChannel>();

            _replyChannel = _mocks.StrictMock<IPollableChannel>();
            _messageMock = _mocks.StrictMock<IMessage>();

            _simpleMessagingGateway = new SimpleMessagingGateway();
            _simpleMessagingGateway.RequestChannel = _requestChannel;
            _simpleMessagingGateway.ReplyChannel = _replyChannel;
            _simpleMessagingGateway.ObjectFactory = TestUtils.CreateTestApplicationContext();
            //reset(_allmocks);
        }
コード例 #2
0
        private IMessagingGateway CreateGatewayForMethod(MethodInfo method)
        {
            SimpleMessagingGateway gateway = new SimpleMessagingGateway(new MethodParameterMessageMapper(method), new SimpleMessageMapper());
            if(TaskScheduler != null) {
                gateway.TaskScheduler = TaskScheduler;
            }
            GatewayAttribute gatewayAttribute = null;
            object[] attr = method.GetCustomAttributes(typeof(GatewayAttribute), false);
            if(attr.Length == 1)
                gatewayAttribute = attr[0] as GatewayAttribute;

            IMessageChannel requestChannel = _defaultRequestChannel;
            IMessageChannel replyChannel = _defaultReplyChannel;
            TimeSpan requestTimeout = _defaultRequestTimeout;
            TimeSpan replyTimeout = _defaultReplyTimeout;
            if(gatewayAttribute != null) {
                AssertUtils.State(ChannelResolver != null, "ChannelResolver is required");
                string requestChannelName = gatewayAttribute.RequestChannel;
                if(StringUtils.HasText(requestChannelName)) {
                    if(ChannelResolver == null)
                        throw new InvalidOperationException("ChannelResolvr must not be null");

                    requestChannel = ChannelResolver.ResolveChannelName(requestChannelName);

                    if(requestChannel == null)
                        throw new InvalidAsynchronousStateException("failed to resolve request channel '" + requestChannelName + "'");
                }

                string replyChannelName = gatewayAttribute.ReplyChannel;
                if(StringUtils.HasText(replyChannelName)) {
                    if(ChannelResolver == null)
                        throw new InvalidOperationException("ChannelResolvr must not be null");

                    replyChannel = ChannelResolver.ResolveChannelName(replyChannelName);

                    if(replyChannel == null)
                        throw new InvalidAsynchronousStateException("failed to resolve reply channel '" + replyChannelName + "'");
                }
                requestTimeout = gatewayAttribute.RequestTimeout;
                replyTimeout = gatewayAttribute.ReplyTimeout;
            }
            gateway.RequestChannel = requestChannel;
            gateway.ReplyChannel = replyChannel;
            gateway.RequestTimeout = requestTimeout;
            gateway.ReplyTimeout = replyTimeout;
            if(ObjectFactory != null) {
                gateway.ObjectFactory = ObjectFactory;
            }
            return gateway;
        }
コード例 #3
0
        private IMessagingGateway CreateGatewayForMethod(MethodInfo method)
        {
            SimpleMessagingGateway gateway = new SimpleMessagingGateway(new MethodParameterMessageMapper(method), new SimpleMessageMapper());

            if (TaskScheduler != null)
            {
                gateway.TaskScheduler = TaskScheduler;
            }
            GatewayAttribute gatewayAttribute = null;

            object[] attr = method.GetCustomAttributes(typeof(GatewayAttribute), false);
            if (attr.Length == 1)
            {
                gatewayAttribute = attr[0] as GatewayAttribute;
            }

            IMessageChannel requestChannel = _defaultRequestChannel;
            IMessageChannel replyChannel   = _defaultReplyChannel;
            TimeSpan        requestTimeout = _defaultRequestTimeout;
            TimeSpan        replyTimeout   = _defaultReplyTimeout;

            if (gatewayAttribute != null)
            {
                AssertUtils.State(ChannelResolver != null, "ChannelResolver is required");
                string requestChannelName = gatewayAttribute.RequestChannel;
                if (StringUtils.HasText(requestChannelName))
                {
                    if (ChannelResolver == null)
                    {
                        throw new InvalidOperationException("ChannelResolvr must not be null");
                    }

                    requestChannel = ChannelResolver.ResolveChannelName(requestChannelName);

                    if (requestChannel == null)
                    {
                        throw new InvalidAsynchronousStateException("failed to resolve request channel '" + requestChannelName + "'");
                    }
                }

                string replyChannelName = gatewayAttribute.ReplyChannel;
                if (StringUtils.HasText(replyChannelName))
                {
                    if (ChannelResolver == null)
                    {
                        throw new InvalidOperationException("ChannelResolvr must not be null");
                    }

                    replyChannel = ChannelResolver.ResolveChannelName(replyChannelName);

                    if (replyChannel == null)
                    {
                        throw new InvalidAsynchronousStateException("failed to resolve reply channel '" + replyChannelName + "'");
                    }
                }
                requestTimeout = gatewayAttribute.RequestTimeout;
                replyTimeout   = gatewayAttribute.ReplyTimeout;
            }
            gateway.RequestChannel = requestChannel;
            gateway.ReplyChannel   = replyChannel;
            gateway.RequestTimeout = requestTimeout;
            gateway.ReplyTimeout   = replyTimeout;
            if (ObjectFactory != null)
            {
                gateway.ObjectFactory = ObjectFactory;
            }
            return(gateway);
        }