本文整理汇总了C#中MessageBus.AsObservable方法的典型用法代码示例。如果您正苦于以下问题:C# MessageBus.AsObservable方法的具体用法?C# MessageBus.AsObservable怎么用?C# MessageBus.AsObservable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageBus
的用法示例。
在下文中一共展示了MessageBus.AsObservable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanListenPositionChangeEvents
public void CanListenPositionChangeEvents()
{
// ARRANGE
var waitEvent = new ManualResetEvent(false);
var messageBus = new MessageBus();
NmeaPositionMocker mocker;
int count = 0;
messageBus.AsObservable<GeoPosition>()
.ObserveOn(Scheduler.ThreadPool)
.Subscribe(position => count++);
// ACT
Action<TimeSpan> delayAction = _ => Thread.Sleep(0); // do not wait to make test faster
using (Stream stream = new FileStream(TestHelper.NmeaFilePath, FileMode.Open))
{
mocker = new NmeaPositionMocker(stream, messageBus);
mocker.OnDone += (s, e) => waitEvent.Set();
mocker.Start(delayAction);
}
// ASSERT
if(!waitEvent.WaitOne(TimeSpan.FromSeconds(60)))
throw new TimeoutException();
mocker.Stop();
Assert.AreEqual(16, count);
}
示例2: GetEarlyEventBus
private static MessageBus GetEarlyEventBus(Entities dataContext, IWorkspace workspace, MessageBus persistedEventBus)
{
var messageBus = new MessageBus();
messageBus
.AsObservable<IDomainEvent>()
.Do(e =>
workspace.Committing += (s, ea) =>
{
ObjectStateEntry entry;
if (dataContext.ObjectStateManager.TryGetObjectStateEntry(e.Sender, out entry))
{
//resend the same event after commit
persistedEventBus.Send(e);
}
})
.Subscribe();
return messageBus;
}