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


C# ChannelAdapter.Send方法代码示例

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


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

示例1: Sending_a_message_to_an_nhibernate_backed_state_machine

        public void Sending_a_message_to_an_nhibernate_backed_state_machine()
        {
            TraceLogger.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>()
                        .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:sdhjl2000,项目名称:Magnum,代码行数:54,代码来源:NHibernateStateMachine_Specs.cs

示例2: 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

示例3: 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

示例4: 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;

			var input = new ChannelAdapter();
			using (input.Connect(x =>
				{
					x.AddConsumersFor<TestStateMachineInstance>()
						.BindUsing<TestStateMachineInstanceBinding, int>()
						.HandleOnCallingThread()
						.CreateNewInstanceBy(id => new TestStateMachineInstance(id))
						.PersistInMemoryUsing(_cache);
				}))
			{
				_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,
						Value = _newValue,
					});

				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,代码行数:44,代码来源:InMemoryStateMachine_Specs.cs

示例5: Should_add_a_consumer_to_an_empty_adapter_chain

		public void Should_add_a_consumer_to_an_empty_adapter_chain()
		{
			var adapter = new ChannelAdapter<TestMessage>(new ShuntChannel<TestMessage>());

			var future = new Future<TestMessage>();
			var consumer = new ConsumerChannel<TestMessage>(_fiber, future.Complete);

			using (ChannelConnection scope = adapter.Connect(x =>
			{
				x.AddChannel(consumer);
			}))
			{
				new TraceChannelVisitor().Visit(adapter);

				adapter.Send(new TestMessage());
			}

			future.IsCompleted.ShouldBeTrue();
		}
开发者ID:Nangal,项目名称:Stact,代码行数:19,代码来源:Aggregator_Specs.cs

示例6: Should_add_a_consumer_that_is_assignable_to_the_type

        public void Should_add_a_consumer_that_is_assignable_to_the_type()
        {
            var firstFuture = new Future<TestMessage>();
            var secondFuture = new Future<ITestMessage>();

            var first = new ConsumerChannel<TestMessage>(_fiber, firstFuture.Complete);
            var subs = new BroadcastChannel<TestMessage>(new[] {first});
            var adapter = new ChannelAdapter<TestMessage>(subs);

            var second = new ConsumerChannel<ITestMessage>(_fiber, secondFuture.Complete);

            using (var scope = adapter.Connect(x => x.AddChannel(second)))
            {
                new TraceChannelVisitor().Visit(adapter);

                adapter.Send(new TestMessage());
            }

            firstFuture.IsCompleted.ShouldBeTrue();
            secondFuture.IsCompleted.ShouldBeTrue();
        }
开发者ID:sdhjl2000,项目名称:Magnum,代码行数:21,代码来源:Aggregator_Specs.cs

示例7: Should_add_a_provider_based_consumer

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

			var futureA = new Future<TestMessage>();
			var futureB = new Future<TestMessage>();
			var futureC = new Future<TestMessage>();

			TestConsumer.Future = futureA;

			using (input.Connect(x =>
				{
					x.AddConsumerOf<TestMessage>()
						.UsingInstance().Of<TestConsumer>()
                        .HandleOnCallingThread()
						.ObtainedBy(() => new TestConsumer())
						.OnChannel(y => y.InputChannel);

					x.AddConsumerOf<TestMessage>()
						.UsingConsumer(futureB.Complete)
                        .HandleOnCallingThread();

					x.AddConsumerOf<TestMessage>()
						.UsingSelectiveConsumer(message => futureC.Complete)
                        .HandleOnCallingThread();
				}))
			{
				Trace.WriteLine("Complete network:");
				new TraceChannelVisitor().Visit(input);

				input.Send(new TestMessage());
			}

			Trace.WriteLine("Empty network:");
			new TraceChannelVisitor().Visit(input);

			futureA.IsCompleted.ShouldBeTrue();
			futureB.IsCompleted.ShouldBeTrue();
			futureC.IsCompleted.ShouldBeTrue();
		}
开发者ID:Nangal,项目名称:Stact,代码行数:40,代码来源:UntypedChannelSubscription_Specs.cs

示例8: Should_be_an_distinct_interval_consumer_on_the_channel

        public void Should_be_an_distinct_interval_consumer_on_the_channel()
        {
            var future = new Future<int>();

            var input = new ChannelAdapter();
            int expected = 5;

            using (input.Connect(x =>
                {
                    x.AddConsumerOf<TestMessage>()
                        .BufferFor(2.Seconds())
                        .Distinct(c => c.Value)
                        .UsingConsumer(message => future.Complete(message.Count))
                        .HandleOnCallingThread();
                }))
            {
                for (int i = 0; i < expected; i++)
                {
                    input.Send(new TestMessage
                        {
                            Value = i
                        });
                }

                future.WaitUntilCompleted(6.Seconds()).ShouldBeTrue();
                future.Value.ShouldEqual(expected);

                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                    {
                        typeof(ChannelAdapter),
                        typeof(BroadcastChannel),
                        typeof(TypedChannelAdapter<TestMessage>),
                        typeof(IntervalChannel<TestMessage>),
                        typeof(DistinctChannel<TestMessage, int>),
                        typeof(ConsumerChannel<IDictionary<int, TestMessage>>),
                    });
            }
        }
开发者ID:jgsteeler,项目名称:Magnum,代码行数:38,代码来源:ChannelSubscription_Specs.cs

示例9: Should_send_to_a_adapter_consumer_chain

        public void Should_send_to_a_adapter_consumer_chain()
        {
            Future<TestMessage> future = new Future<TestMessage>();

            var consumer = new ConsumerChannel<TestMessage>(_fiber, future.Complete);
            var adapter = new ChannelAdapter<TestMessage>(consumer);

            adapter.Send(new TestMessage());

            future.IsCompleted.ShouldBeTrue();
        }
开发者ID:sdhjl2000,项目名称:Magnum,代码行数:11,代码来源:Aggregator_Specs.cs

示例10: Should_remove_a_consumer_from_an_adapter_chain

        public void Should_remove_a_consumer_from_an_adapter_chain()
        {
            var adapter = new ChannelAdapter<TestMessage>(new ShuntChannel<TestMessage>());

            var future = new Future<TestMessage>();

            var consumer = new ConsumerChannel<TestMessage>(_fiber, future.Complete);
            using (var scope = adapter.Connect(x => x.AddChannel(consumer)))
            {
            }

            new TraceChannelVisitor().Visit(adapter);

            adapter.Send(new TestMessage());

            future.IsCompleted.ShouldBeFalse();
        }
开发者ID:sdhjl2000,项目名称:Magnum,代码行数:17,代码来源:Aggregator_Specs.cs

示例11: Should_manage_interleaved_changes_the_the_chain

        public void Should_manage_interleaved_changes_the_the_chain()
        {
            var firstFuture = new Future<TestMessage>();
            var secondFuture = new Future<TestMessage>();

            var adapter = new ChannelAdapter<TestMessage>(new ShuntChannel<TestMessage>());

            var first = new ConsumerChannel<TestMessage>(_fiber, firstFuture.Complete);
            var firstScope = adapter.Connect(x => x.AddChannel(first));

            var second = new ConsumerChannel<TestMessage>(_fiber, secondFuture.Complete);
            var secondScope = adapter.Connect(x => x.AddChannel(second));

            firstScope.Dispose();

            new TraceChannelVisitor().Visit(adapter);

            adapter.Send(new TestMessage());

            firstFuture.IsCompleted.ShouldBeFalse();
            secondFuture.IsCompleted.ShouldBeTrue();
        }
开发者ID:sdhjl2000,项目名称:Magnum,代码行数:22,代码来源:Aggregator_Specs.cs

示例12: Should_be_an_interval_consumer_on_the_channel

        public void Should_be_an_interval_consumer_on_the_channel()
        {
            var future = new Future<int>();

            var input = new ChannelAdapter();
            int expected = 5;
            using (input.Connect(x =>
                {
                    x.AddConsumerOf<TestMessage>()
                        .BufferFor(2.Seconds())
                        .UsingConsumer(message =>
                            {
                                future.Complete(message.Count);
                            })
                        .ExecuteOnProducerThread();
                }))
            {
                for (int i = 0; i < expected; i++)
                    input.Send(new TestMessage());

                future.WaitUntilCompleted(6.Seconds()).ShouldBeTrue();
                future.Value.ShouldEqual(expected);

                input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
                    {
                        typeof(ChannelAdapter),
                        typeof(BroadcastChannel),
                        typeof(TypedChannelAdapter<TestMessage>),
                        typeof(IntervalChannel<TestMessage>),
                        typeof(ConsumerChannel<ICollection<TestMessage>>),
                    });
            }
        }
开发者ID:hakeemsm,项目名称:Magnum,代码行数:33,代码来源:ChannelSubscription_Specs.cs

示例13: Should_register_my_consumer

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

			var futureA = new Future<TestMessage>();
			var consumerA = new ConsumerChannel<TestMessage>(new SynchronousFiber(), futureA.Complete);

			var futureB = new Future<TestMessage>();
			var consumerB = new ConsumerChannel<TestMessage>(new SynchronousFiber(), futureB.Complete);

			using (input.Connect(x =>
				{
					x.AddChannel(consumerA);
					x.AddChannel(consumerB);
				}))
			{
				new TraceChannelVisitor().Visit(input);

				input.Send(new TestMessage());
			}

			futureA.IsCompleted.ShouldBeTrue();
			futureB.IsCompleted.ShouldBeTrue();
		}
开发者ID:Nangal,项目名称:Stact,代码行数:24,代码来源:UntypedChannelSubscription_Specs.cs

示例14: Should_remove_my_consumer

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

			var futureA = new Future<TestMessage>();
			var consumerA = new ConsumerChannel<TestMessage>(new SynchronousFiber(), futureA.Complete);

			using (ChannelConnection connection = input.Connect(x => x.AddChannel(consumerA)))
			{
			}

			new TraceChannelVisitor().Visit(input);

			input.Send(new TestMessage());

			futureA.IsCompleted.ShouldBeFalse();
		}
开发者ID:Nangal,项目名称:Stact,代码行数:17,代码来源:UntypedChannelSubscription_Specs.cs

示例15: Should_work_through_a_channel_network

        public void Should_work_through_a_channel_network()
        {
            var received = new FutureChannel<Request<Simple>>();

            UntypedChannel channel = new ChannelAdapter();
            channel.Connect(x => x.AddChannel(received));

            var simpleImpl = new SimpleImpl();
            channel.Send(new RequestImpl<SimpleImpl>(null, simpleImpl));

            received.IsCompleted.ShouldBeTrue();
            received.Value.ShouldNotBeNull();
            received.Value.Body.ShouldEqual(simpleImpl);
        }
开发者ID:rickj33,项目名称:Stact,代码行数:14,代码来源:HeaderAdapter_Specs.cs


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