Ejemplo n.º 1
0
        public void EstablishContext()
        {
            using (var startEvent = new ManualResetEvent(false))
            {
                _srv = new TestService();

                _channelAdaptor = new ChannelAdapter();
                _hostChannel = WellknownAddresses.GetHostHost(_channelAdaptor);

                _connection = _channelAdaptor.Connect(config => config.AddConsumerOf<ServiceStarted>().UsingConsumer(msg => startEvent.Set()));

                ServiceConfigurator<TestService> c = new ServiceConfigurator<TestService>();
                c.WhenStarted(s => s.Start());
                c.WhenStopped(s => s.Stop());
                c.WhenPaused(s => { _wasPaused = true; });
                c.WhenContinued(s => { _wasContinued = true; });
                c.HowToBuildService(name => _srv);

                _serviceController = c.Create();
                _serviceController.Start();

                startEvent.WaitOne(5.Seconds());

                _serviceController.State.ShouldEqual(ServiceState.Started);
            }
        }
Ejemplo n.º 2
0
		public void A_request_is_sent_via_wcf()
		{
			_pipeUri = new Uri("net.pipe://localhost/pipe");

			_response = new Future<Response<TestMessage>>();

			_client = new ChannelAdapter();
			_clientConnection = _client.Connect(x =>
				{
					x.SendToWcfChannel(_pipeUri, _pipeName)
						.HandleOnCallingThread();

					x.AddConsumerOf<Response<TestMessage>>()
						.UsingConsumer(_response.Complete);
				});

			_server = new ChannelAdapter();
			_serverConnection = _server.Connect(x =>
				{
					x.AddConsumerOf<Request<TestMessage>>()
						.UsingConsumer(request => request.Respond(request.Body));
				});

			_host = new WcfChannelHost(new PoolFiber(), _server, _pipeUri, _pipeName);
		}
Ejemplo n.º 3
0
        void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                if (_host != null)
                {
                    _host.Stop();
                    _host.Dispose();
                    _host = null;
                }

                if (_connections != null)
                {
                    _connections.Each(x =>
                    {
                        try
                        {
                            x.Dispose();
                        }
                        catch (Exception ex)
                        {
                            _log.Error("Closing connection caused an exception", ex);
                        }
                    });
                    _connections = null;
                }
            }

            _disposed = true;
        }
Ejemplo n.º 4
0
        public void Should_properly_arrive_at_the_destination()
        {
            var    serviceUri = new Uri("net.pipe://localhost/pipe");
            string pipeName   = "test";

            var future  = new Future <TestMessage>();
            var message = new TestMessage
            {
                Id   = Guid.NewGuid(),
                Name = "Alpha",
            };

            UntypedChannel adapter = new ChannelAdapter();

            using (var remote = new WcfChannelHost(new SynchronousFiber(), adapter, serviceUri, pipeName))
            {
                using (adapter.Connect(x =>
                {
                    x.AddConsumerOf <TestMessage>()
                    .UsingConsumer(m => future.Complete(m));
                }))
                {
                    var client = new WcfChannelProxy(new SynchronousFiber(), serviceUri, pipeName);

                    client.Send(message);

                    future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
                }
            }

            future.Value.ShouldNotBeNull();
            future.Value.ShouldEqual(message);
            future.Value.ShouldNotBeTheSameAs(message);
        }
Ejemplo n.º 5
0
        public void A_request_is_sent_via_wcf()
        {
            _pipeUri = new Uri("net.pipe://localhost/pipe");

            _response = new Future <Response <TestMessage> >();

            _client           = new ChannelAdapter();
            _clientConnection = _client.Connect(x =>
            {
                x.SendToWcfChannel(_pipeUri, _pipeName)
                .HandleOnCallingThread();

                x.AddConsumerOf <Response <TestMessage> >()
                .UsingConsumer(_response.Complete);
            });

            _server           = new ChannelAdapter();
            _serverConnection = _server.Connect(x =>
            {
                x.AddConsumerOf <Request <TestMessage> >()
                .UsingConsumer(request => request.Respond(request.Body));
            });

            _host = new WcfChannelHost(new PoolFiber(), _server, _pipeUri, _pipeName);
        }
Ejemplo n.º 6
0
        public void Should_property_adapt_itself_to_a_channel_network()
        {
            TraceLogger.Configure(LogLevel.Debug);
            ILogger log = Logger.GetLogger<Sending_a_message_through_a_wcf_channel>();
            log.Debug("Starting");

            var serviceUri = new Uri("net.pipe://localhost/Pipe");
            string pipeName = "Test";
            Channel<TestMessage> adapter = new ChannelAdapter<TestMessage>();
            using (var host = new WcfChannelHost<TestMessage>(adapter, serviceUri, pipeName))
            {
                log.Debug("Host started");

                var future = new Future<TestMessage>();

                using (adapter.Connect(x =>
                    {
                        x.AddConsumer(m =>
                            {
                                log.Debug(l => l.Write("Received: {0}", m.Value));
                                future.Complete(m);
                            });
                    }))
                {
                    var client = new WcfChannelProxy<TestMessage>(new SynchronousFiber(), serviceUri, pipeName);
                    log.Debug("Client started");

                    client.Send(new TestMessage("Hello!"));

                    future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();

                    log.Debug("Complete");
                }
            }
        }
Ejemplo n.º 7
0
        public HostChannel(UntypedChannel output, Uri address, string pipeName)
        {
            _output   = output;
            _address  = address;
            _pipeName = pipeName;

            _host = new WcfChannelHost(new SynchronousFiber(), output, address, pipeName);
        }
Ejemplo n.º 8
0
        public void Configure(ChannelConfiguratorConnection connection)
        {
            Fiber fiber = GetConfiguredFiber(connection);

            var host = new WcfChannelHost(fiber, connection.Channel, _endpointUri, _pipeName);

            connection.AddDisposable(host);
        }
Ejemplo n.º 9
0
        public void After()
        {
            _host.Dispose();
            _host = null;

            _inputConnection.Dispose();
            _inputConnection = null;
            _input           = null;

            _outputConnection.Dispose();
            _outputConnection = null;
            _output           = null;
        }
Ejemplo n.º 10
0
        public void After()
        {
            _host.Dispose();
            _host = null;

            _clientConnection.Dispose();
            _clientConnection = null;
            _client           = null;

            _serverConnection.Dispose();
            _serverConnection = null;
            _server           = null;
        }
Ejemplo n.º 11
0
        public ServiceCoordinator(Action<IServiceCoordinator> beforeStartingServices,
            Action<IServiceCoordinator> beforeStart, Action<IServiceCoordinator> afterStop)
        {
            _beforeStartingServices = beforeStartingServices;
            _beforeStart = beforeStart;
            _afterStop = afterStop;
            _serviceConfigurators = new List<Func<IServiceController>>();
            _myChannel = new ChannelAdapter();
            _hostChannel = WellknownAddresses.GetHostHost(_myChannel);

            _myChannel.Connect(s =>
                {
                    s.AddConsumerOf<ShelfFault>().UsingConsumer(HandleServiceFault);
                    s.AddConsumerOf<ServiceStarted>().UsingConsumer(msg => ServiceStartedAction.Invoke(msg));
                });
        }
Ejemplo n.º 12
0
        public void Should_properly_arrive_at_the_destination()
        {
            TraceLogger.Configure(LogLevel.Debug);
            _log = Logger.GetLogger <Sending_a_message_to_a_remote_channel_via_wcf>();
            _log.Debug("Starting");

            var    serviceUri = new Uri("net.pipe://localhost/pipe");
            string pipeName   = "test";

            var future  = new Future <TestMessage>();
            var message = new TestMessage
            {
                Id   = Guid.NewGuid(),
                Name = "Alpha",
            };

            UntypedChannel adapter = new ChannelAdapter();

            using (var remote = new WcfChannelHost(new SynchronousFiber(), adapter, serviceUri, pipeName))
            {
                _log.Debug("Remote channel adapter created");
                using (adapter.Connect(x =>
                {
                    x.AddConsumerOf <TestMessage>()
                    .UsingConsumer(m => future.Complete(m));
                }))
                {
                    var client = new WcfChannelProxy(new SynchronousFiber(), serviceUri, pipeName);
                    _log.Debug("Client created");

                    client.Send(message);

                    future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
                }
            }

            future.Value.ShouldNotBeNull();
            future.Value.ShouldEqual(message);
            future.Value.ShouldNotBeTheSameAs(message);
        }
Ejemplo n.º 13
0
        public void Should_properly_arrive_at_the_destination()
        {
            TraceLogProvider.Configure(LogLevel.Debug);
            _log = Logger.GetLogger<Sending_a_message_to_a_remote_channel_via_wcf>();
            _log.Debug("Starting");

            var serviceUri = new Uri("net.pipe://localhost/pipe");
            string pipeName = "test";

            var future = new Future<TestMessage>();
            var message = new TestMessage
                {
                    Id = Guid.NewGuid(),
                    Name = "Alpha",
                };

            UntypedChannel adapter = new ChannelAdapter();
            using (var remote = new WcfChannelHost(new SynchronousFiber(), adapter, serviceUri, pipeName))
            {
                _log.Debug("Remote channel adapter created");
                using (adapter.Connect(x =>
                    {
                        x.AddConsumerOf<TestMessage>()
                            .UsingConsumer(m => future.Complete(m));
                    }))
                {
                    var client = new WcfChannelProxy(new SynchronousFiber(), serviceUri, pipeName);
                    _log.Debug("Client created");

                    client.Send(message);

                    future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
                }
            }

            future.Value.ShouldNotBeNull();
            future.Value.ShouldEqual(message);
            future.Value.ShouldNotBeTheSameAs(message);
        }
Ejemplo n.º 14
0
        public void Connecting_two_services_through_a_wcf_proxy_and_host()
        {
            _pipeUri = new Uri("net.pipe://localhost/pipe");

            _consumer = new Future <TestMessage>();

            _input           = new ChannelAdapter();
            _inputConnection = _input.Connect(x =>
            {
                x.AddConsumerOf <TestMessage>()
                .UsingConsumer(_consumer.Complete);
            });

            _host = new WcfChannelHost(new PoolFiber(), _input, _pipeUri, _pipeName);

            _output           = new ChannelAdapter();
            _outputConnection = _output.Connect(x =>
            {
                x.SendToWcfChannel(_pipeUri, _pipeName)
                .HandleOnCallingThread();
            });
        }
Ejemplo n.º 15
0
        public HostChannel([NotNull] UntypedChannel output,
                           [NotNull] Uri address,
                           [NotNull] string pipeName)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }
            if (pipeName == null)
            {
                throw new ArgumentNullException("pipeName");
            }

            _output   = output;
            _address  = address;
            _pipeName = pipeName;

            _host = new WcfChannelHost(new SynchronousFiber(), output, address, pipeName);
        }
Ejemplo n.º 16
0
        public void Should_property_adapt_itself_to_a_channel_network()
        {
            TraceLogger.Configure(LogLevel.Debug);
            ILogger log = Logger.GetLogger <Sending_a_message_through_a_wcf_channel>();

            log.Debug("Starting");

            var    serviceUri             = new Uri("net.pipe://localhost/Pipe");
            string pipeName               = "Test";
            Channel <TestMessage> adapter = new ChannelAdapter <TestMessage>();

            using (var host = new WcfChannelHost <TestMessage>(adapter, serviceUri, pipeName))
            {
                log.Debug("Host started");

                var future = new Future <TestMessage>();

                using (adapter.Connect(x =>
                {
                    x.AddConsumer(m =>
                    {
                        log.Debug(l => l.Write("Received: {0}", m.Value));
                        future.Complete(m);
                    });
                }))
                {
                    var client = new WcfChannelProxy <TestMessage>(new SynchronousFiber(), serviceUri, pipeName);
                    log.Debug("Client started");

                    client.Send(new TestMessage("Hello!"));

                    future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();

                    log.Debug("Complete");
                }
            }
        }
Ejemplo n.º 17
0
        public void Should_property_adapt_itself_to_a_channel_network()
        {
            var    serviceUri             = new Uri("net.pipe://localhost/Pipe");
            string pipeName               = "Test";
            Channel <TestMessage> adapter = new ChannelAdapter <TestMessage>();

            using (var host = new WcfChannelHost <TestMessage>(adapter, serviceUri, pipeName))
            {
                var future = new Future <TestMessage>();

                using (adapter.Connect(x =>
                {
                    x.AddConsumer(future.Complete)
                    .HandleOnCallingThread();
                }))
                {
                    var client = new WcfChannelProxy <TestMessage>(new SynchronousFiber(), serviceUri, pipeName);

                    client.Send(new TestMessage("Hello!"));

                    future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
                }
            }
        }
Ejemplo n.º 18
0
		public void After()
		{
			_host.Dispose();
			_host = null;

			_clientConnection.Dispose();
			_clientConnection = null;
			_client = null;

			_serverConnection.Dispose();
			_serverConnection = null;
			_server = null;
		}