当前位置: 首页>>代码示例>>C#>>正文


C# ChannelAdapter.Connect方法代码示例

本文整理汇总了C#中ChannelAdapter.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# ChannelAdapter.Connect方法的具体用法?C# ChannelAdapter.Connect怎么用?C# ChannelAdapter.Connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ChannelAdapter的用法示例。


在下文中一共展示了ChannelAdapter.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Sending_a_bid_request_should_get_a_response

		public void Sending_a_bid_request_should_get_a_response()
		{
			var response = new FutureChannel<Response<Status>>();

			UntypedChannel responseChannel = new ChannelAdapter();
			responseChannel.Connect(x => x.AddChannel(response));

			Auction.Request(new Ask(Id), responseChannel);

			response.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for response");

			response.Value.Body.AuctionId.ShouldEqual(Id);


			// ThreadUtil.Sleep(2.Seconds());
			// go ahead and buy something

			var purchased = new FutureChannel<Response<Purchased>>();

			responseChannel.Connect(x => x.AddChannel(purchased));

			Auction.Request(new Buy
				{
					Quantity = 15,
					Token = response.Value.Body.Token
				}, responseChannel);

			purchased.WaitUntilCompleted(2.Seconds()).ShouldBeTrue("Timeout waiting for purchase");

			purchased.Value.Body.Quantity.ShouldEqual(15);
			purchased.Value.Body.Price.ShouldEqual(response.Value.Body.CurrentBid);
		}
开发者ID:Nangal,项目名称:Stact,代码行数:32,代码来源:Ask_Specs.cs

示例2: PollingFileSystemEventProducer

        /// <summary>
        /// Creates a PollingFileSystemEventProducer
        /// </summary>		
        /// <param name="directory">The directory to watch</param>
        /// <param name="channel">The channel where events should be sent</param>
        /// <param name="scheduler">Event scheduler</param>
        /// <param name="fiber">Fiber to schedule on</param>
        /// <param name="checkInterval">The maximal time between events or polls on a given file</param>
        /// <param name="checkSubDirectory">Indicates if subdirectorys will be checked or ignored</param>
        public PollingFileSystemEventProducer(string directory, UntypedChannel channel, [NotNull] Scheduler scheduler, Fiber fiber, TimeSpan checkInterval, bool checkSubDirectory)
        {
            if (scheduler == null)
                throw new ArgumentNullException("scheduler");

            _directory = directory;
            _channel = channel;
            _fiber = fiber;
            _hashes = new Dictionary<string, Guid>();
            _scheduler = scheduler;
            _checkInterval = checkInterval;

            _scheduledAction = scheduler.Schedule(3.Seconds(), _fiber, HashFileSystem);

            var myChannel = new ChannelAdapter();

            _connection = myChannel.Connect(connectionConfigurator =>
            {
                connectionConfigurator.AddConsumerOf<FileSystemChanged>().UsingConsumer(HandleFileSystemChangedAndCreated);
                connectionConfigurator.AddConsumerOf<FileSystemCreated>().UsingConsumer(HandleFileSystemChangedAndCreated);
                connectionConfigurator.AddConsumerOf<FileSystemRenamed>().UsingConsumer(HandleFileSystemRenamed);
                connectionConfigurator.AddConsumerOf<FileSystemDeleted>().UsingConsumer(HandleFileSystemDeleted);
            });

            _fileSystemEventProducer = new FileSystemEventProducer(directory, myChannel, checkSubDirectory);
        }
开发者ID:akilhoffer,项目名称:Reactor,代码行数:35,代码来源:PollingFileSystemEventProducer.cs

示例3: A_file_is_created

        public void A_file_is_created()
        {
            _baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

            _filename = "test2.dat";
            _path = Path.Combine(_baseDirectory, _filename);

            System.IO.File.Delete(_path);

            _listener = new Future<FileCreated>();

            _channel = new ChannelAdapter();
            FiberFactory fiberFactory = () => new SynchronousFiber();
            _scheduler = new TimerScheduler(fiberFactory());
            _producer = new PollingFileSystemEventProducer(_baseDirectory, _channel, _scheduler, fiberFactory(),
                                                           20.Seconds());

            Thread.Sleep(5.Seconds());

            using (_channel.Connect(x => x.AddConsumerOf<FileCreated>().UsingConsumer(m => _listener.Complete(m))))
            {
                System.IO.File.Create(_path);

                _listener.WaitUntilCompleted(25.Seconds());
            }

            _producer.Dispose();
        }
开发者ID:sdhjl2000,项目名称:Magnum,代码行数:28,代码来源:PollingFileSystemWatcher_Specs.cs

示例4: A_request_is_sent_via_wcf

        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.ReceiveFromWcfChannel(_pipeUri, _pipeName);

                    x.AddConsumerOf<Request<TestMessage>>()
                        .UsingConsumer(request => request.Respond(request.Body));
                });
        }
开发者ID:rickj33,项目名称:Stact,代码行数:25,代码来源:RequestWcf_Specs.cs

示例5: Should_property_adapt_itself_to_a_channel_network

        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");
                }
            }
        }
开发者ID:sdhjl2000,项目名称:Magnum,代码行数:35,代码来源:DubSeeEff_Specs.cs

示例6: EstablishContext

        public void EstablishContext()
        {
            using (var startEvent = new ManualResetEvent(false))
            {
                _srv = new TestService();

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

                using (_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(WellknownAddresses.GetServiceCoordinatorProxy());
                    _serviceController.Start();

                    startEvent.WaitOne(5.Seconds());

                    _serviceController.State.ShouldEqual(ServiceState.Started);
                }
            }
        }
开发者ID:ramonsmits,项目名称:Topshelf,代码行数:28,代码来源:ServiceController_Specs.cs

示例7: Should_properly_arrive_at_the_destination

		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);
		}
开发者ID:Nangal,项目名称:Stact,代码行数:33,代码来源:RemoteChannel_Specs.cs

示例8: Sending_a_message_to_an_nhibernate_instance_channel

		public void Sending_a_message_to_an_nhibernate_instance_channel()
		{
			_newValue = new Random().Next(1, 500000)/100m;

			using (ISession session = SessionFactory.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				session.CreateQuery("Delete TestInstance").ExecuteUpdate();

				session.Save(new TestInstance(27));

				transaction.Commit();
			}

			var input = new ChannelAdapter();
			using (input.Connect(x =>
				{
					x.AddConsumerOf<UpdateValue>()
						.UsingInstance()
						.Of<TestInstance>()
						.HandleOnCallingThread()
						.DistributedBy(msg => msg.Id)
						.PersistUsingNHibernate()
						.UsingSessionProvider(m => SessionFactory.OpenSession())
						.OnChannel(m => m.UpdateValueChannel)
						.CreateNewInstanceBy(m => new TestInstance(m.Id));
				}))
			{
				//
				input.Send(new UpdateValue(27, _newValue));
			}
		}
开发者ID:Nangal,项目名称:Stact,代码行数:32,代码来源:NHibernateInstanceChannel_Specs.cs

示例9: Sending_a_message_to_an_nhibernate_backed_state_machine

        public void Sending_a_message_to_an_nhibernate_backed_state_machine()
        {
            TraceLogProvider.Configure(LogLevel.Debug);

            _newValue = new Random().Next(1, 500000)/100m;

            using (ISession session = SessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.CreateQuery("Delete TestStateMachineInstance").ExecuteUpdate();

                transaction.Commit();
            }

            var input = new ChannelAdapter();
            using (input.Connect(x =>
                {
                    x.AddConsumersFor<TestStateMachineInstance>()
                        .BindUsing<TestStateMachineInstanceBinding, int>()
                        .ExecuteOnProducerThread()
                        .CreateNewInstanceUsing(id => new TestStateMachineInstance(id))
                        .PersistUsingNHibernate()
                        .UseSessionProvider(() => SessionFactory.OpenSession());
                }))
            {
                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                    {
                        typeof(ChannelAdapter),
                        typeof(BroadcastChannel),
                        typeof(TypedChannelAdapter<CreateOrder>),
                        typeof(InstanceChannel<CreateOrder>),
                        typeof(TypedChannelAdapter<UpdateOrder>),
                        typeof(InstanceChannel<UpdateOrder>),
                        typeof(TypedChannelAdapter<CompleteOrder>),
                        typeof(InstanceChannel<CompleteOrder>),
                    });

                var future = new Future<int>();
                TestStateMachineInstance.CompletedLatch = new CountdownLatch(1, future.Complete);
                //
                input.Send(new CreateOrder
                    {
                        Id = 27
                    });

                input.Send(new UpdateOrder
                    {
                        Id = 27,
                        Value = _newValue,
                    });

                input.Send(new CompleteOrder
                    {
                        Id = 27,
                    });

                future.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();
            }
        }
开发者ID:hakeemsm,项目名称:Magnum,代码行数:59,代码来源:NHibernateStateMachine_Specs.cs

示例10: Should_properly_wrap_the_channel_as_synchronized

		public void Should_properly_wrap_the_channel_as_synchronized()
		{
			Assert.IsNull(SynchronizationContext.Current);

			var fiber = new PoolFiber();

			var input = new ChannelAdapter();

			var context = new TestSynchronizationContext();

			var future = new Future<TestMessage>();

			SynchronizationContext.SetSynchronizationContext(context);

			Assert.IsNotNull(SynchronizationContext.Current);

			using (input.Connect(x =>
				{
					x.AddConsumerOf<TestMessage>()
						.OnCurrentSynchronizationContext()
						.UsingConsumer(message =>
							{
								Trace.WriteLine("Received on Thread: " + Thread.CurrentThread.ManagedThreadId);

								Assert.IsNotNull(SynchronizationContext.Current);
								Assert.AreEqual(context, SynchronizationContext.Current);

								future.Complete(message);
							});
				}))
			{
				Trace.WriteLine("Subscribed on Thread: " + Thread.CurrentThread.ManagedThreadId);

				SynchronizationContext.SetSynchronizationContext(null);

				input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
					{
						typeof(ChannelAdapter),
						typeof(BroadcastChannel),
						typeof(TypedChannelAdapter<TestMessage>),
						typeof(SynchronizedChannel<TestMessage>),
						typeof(ConsumerChannel<TestMessage>),
					});

				fiber.Add(() =>
					{
						Trace.WriteLine("Thread: " + Thread.CurrentThread.ManagedThreadId);
						Assert.IsNull(SynchronizationContext.Current);

						input.Send(new TestMessage());
					});

				Assert.IsNull(SynchronizationContext.Current);

				future.WaitUntilCompleted(2.Seconds()).ShouldBeTrue();
			}
		}
开发者ID:Nangal,项目名称:Stact,代码行数:57,代码来源:SynchronizationContext_Specs.cs

示例11: Should_allow_the_selective_consumer_channel_type

		public void Should_allow_the_selective_consumer_channel_type()
		{
			var input = new ChannelAdapter();

			using (input.Connect(x =>
				{
					x.AddConsumerOf<TestMessage>()
						.UsingSelectiveConsumer(message => m => { });
				}))
			{
			}
		}
开发者ID:Nangal,项目名称:Stact,代码行数:12,代码来源:Connect_Specs.cs

示例12: Sending_a_message_to_an_nhibernate_backed_state_machine

		public void Sending_a_message_to_an_nhibernate_backed_state_machine()
		{
			_newValue = new Random().Next(1, 500000)/100m;

			using (ISession session = SessionFactory.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				session.CreateQuery("Delete TestStateMachineInstance").ExecuteUpdate();

				transaction.Commit();
			}

			var input = new ChannelAdapter();
			using (input.Connect(x =>
				{
					x.AddConsumersFor<TestStateMachineInstance>()
						.BindUsing<TestStateMachineInstanceBinding, int>()
						.HandleOnCallingThread()
						.CreateNewInstanceBy(id => new TestStateMachineInstance(id))
						.PersistUsingNHibernate()
						.UseSessionProvider(() => SessionFactory.OpenSession());
				}))
			{
				_networkTypes = input.Flatten().Select(c => c.GetType());

				var future = new Future<int>();
				TestStateMachineInstance.CompletedLatch = new CountdownLatch(1, future.Complete);
				//
				input.Send(new UpdateOrder
					{
						Id = 47
					});

				input.Send(new CreateOrder
					{
						Id = 27
					});

				input.Send(new UpdateOrder
					{
						Id = 27,
						Value = _newValue,
					});

				input.Send(new CompleteOrder
					{
						Id = 27,
					});

				future.WaitUntilCompleted(5.Seconds()).ShouldBeTrue();
			}
		}
开发者ID:Nangal,项目名称:Stact,代码行数:52,代码来源:NHibernateStateMachine_Specs.cs

示例13: A_message_is_sent_to_an_instance

		public void A_message_is_sent_to_an_instance()
		{
			_auctionId = CombGuid.Generate();

			_input = new ChannelAdapter();
			_connection = _input.Connect(x =>
			{
				x.AddConsumerOf<Bid>()
					.UsingInstance().Of<Auction>()
					.ObtainedBy(m => new Auction(m.AuctionId))
					.OnChannel(auction => auction.BidChannel);
			});
		}
开发者ID:Nangal,项目名称:Stact,代码行数:13,代码来源:Auction_Specs.cs

示例14: Should_allow_an_interval_channel_to_be_created

		public void Should_allow_an_interval_channel_to_be_created()
		{
			var input = new ChannelAdapter();

			using (input.Connect(x =>
				{
					x.AddConsumerOf<TestMessage>()
						.BufferFor(15.Seconds())
						.UsingConsumer(messages => { });
				}))
			{
			}
		}
开发者ID:Nangal,项目名称:Stact,代码行数:13,代码来源:Connect_Specs.cs

示例15: Should_allow_the_consumer_channel_type

		public void Should_allow_the_consumer_channel_type()
		{
			var input = new ChannelAdapter();

			using (input.Connect(x =>
				{
					x.AddConsumerOf<TestMessage>()
						.OnCurrentSynchronizationContext()
						.UsingConsumer(message => { })
						.HandleOnPoolFiber();
				}))
			{
			}
		}
开发者ID:Nangal,项目名称:Stact,代码行数:14,代码来源:Connect_Specs.cs


注:本文中的ChannelAdapter.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。