本文整理汇总了C#中ChannelAdapter.Flatten方法的典型用法代码示例。如果您正苦于以下问题:C# ChannelAdapter.Flatten方法的具体用法?C# ChannelAdapter.Flatten怎么用?C# ChannelAdapter.Flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChannelAdapter
的用法示例。
在下文中一共展示了ChannelAdapter.Flatten方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: Should_add_an_untyped_channel_to_an_untyped_channel_adapter
public void Should_add_an_untyped_channel_to_an_untyped_channel_adapter()
{
var next = new ChannelAdapter();
var input = new ChannelAdapter();
using (input.Connect(x => { x.AddUntypedChannel(next); }))
{
input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
{
typeof(ChannelAdapter),
typeof(BroadcastChannel),
typeof(ChannelAdapter),
typeof(ShuntChannel),
});
}
}
示例5: 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();
}
}
示例6: Should_be_able_to_configure_a_wcf_host_via_the_connect_dsl
public void Should_be_able_to_configure_a_wcf_host_via_the_connect_dsl()
{
var future = new Future<TestMessage>();
var input = new ChannelAdapter();
using (input.Connect(x =>
{
// x.ReceiveFromNamedPipe(new Uri("net.pipe://localhost/pipe"), "test");
x.AddConsumerOf<TestMessage>()
.UsingConsumer(future.Complete);
}))
{
input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
{
typeof(ChannelAdapter),
typeof(BroadcastChannel),
typeof(TypedChannelAdapter<TestMessage>),
typeof(ConsumerChannel<TestMessage>),
});
}
}
示例7: 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>>),
});
}
}
示例8: Should_support_single_channels
public void Should_support_single_channels()
{
var input = new ChannelAdapter();
using (input.Connect(x =>
{
x.AddConsumerOf<UpdateValue>()
.UsingInstance()
.Of<TestInstance>()
.DistributedBy(m => m.Id)
.PersistUsingNHibernate()
.UsingSessionProvider(m => (ISession)null)
.OnChannel(m => m.UpdateValueChannel)
.CreateNewInstanceBy(m => new TestInstance(m.Id));
}))
{
input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
{
typeof(ChannelAdapter),
typeof(BroadcastChannel),
typeof(TypedChannelAdapter<UpdateValue>),
typeof(InstanceChannel<UpdateValue>),
});
}
}
示例9: Should_be_an_empty_channel_adapter_with_no_consumers
public void Should_be_an_empty_channel_adapter_with_no_consumers()
{
var input = new ChannelAdapter();
using (input.Connect(x => { }))
{
input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
{
typeof(ChannelAdapter),
typeof(ShuntChannel)
});
}
}
示例10: Should_subscribe_the_last_message_consumer
public void Should_subscribe_the_last_message_consumer()
{
var input = new ChannelAdapter();
using (input.Connect(x =>
{
x.AddConsumerOf<TestMessage>()
.BufferFor(2.Seconds())
.HandleOnCallingThread()
.Last()
.HandleOnCallingThread()
.UsingConsumer(message =>
{
})
.HandleOnCallingThread();
}))
{
input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
{
typeof(ChannelAdapter),
typeof(BroadcastChannel),
typeof(TypedChannelAdapter<TestMessage>),
typeof(IntervalChannel<TestMessage>),
typeof(LastChannel<TestMessage>),
typeof(ConsumerChannel<TestMessage>),
});
}
}
示例11: Should_include_the_filter_channel
public void Should_include_the_filter_channel()
{
var input = new ChannelAdapter();
using (input.Connect(x =>
{
x.AddConsumerOf<TestMessage>()
.Where(message => message.Value == 47)
.UsingConsumer(message => { });
}))
{
input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
{
typeof(ChannelAdapter),
typeof(BroadcastChannel),
typeof(TypedChannelAdapter<TestMessage>),
typeof(FilterChannel<TestMessage>),
typeof(ConsumerChannel<TestMessage>)
});
}
}
示例12: Should_be_two_consumers_on_the_channel
public void Should_be_two_consumers_on_the_channel()
{
SelectiveConsumer<TestMessage> selectiveConsumer = x => y => { };
var input = new ChannelAdapter();
using (input.Connect(x =>
{
x.AddConsumerOf<TestMessage>()
.UsingConsumer(message => { });
x.AddConsumerOf<TestMessage>()
.UsingSelectiveConsumer(selectiveConsumer);
}))
{
input.Flatten().Select(c => c.GetType()).ShouldEqual(new[]
{
typeof(ChannelAdapter),
typeof(BroadcastChannel),
typeof(TypedChannelAdapter<TestMessage>),
typeof(BroadcastChannel<TestMessage>),
typeof(ConsumerChannel<TestMessage>),
typeof(SelectiveConsumerChannel<TestMessage>),
});
}
}
示例13: 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>>),
});
}
}