本文整理汇总了C#中EventAggregator.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# EventAggregator.SendMessage方法的具体用法?C# EventAggregator.SendMessage怎么用?C# EventAggregator.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventAggregator
的用法示例。
在下文中一共展示了EventAggregator.SendMessage方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_unsubscribe_manually
public void Can_unsubscribe_manually()
{
var someMessageHandler = new SomeMessageHandler();
var eventAggregator = new EventAggregator();
eventAggregator.AddListener(someMessageHandler);
eventAggregator.SendMessage<SomeMessage>();
someMessageHandler.EventsTrapped.Count().ShouldEqual(1);
eventAggregator.RemoveListener(someMessageHandler);
eventAggregator.SendMessage<SomeMessage>();
someMessageHandler.EventsTrapped.Count().ShouldEqual(1);
}
示例2: Should_send_message
public void Should_send_message()
{
var someMessageHandler = new SomeMessageHandler();
var eventAggregator = new EventAggregator();
eventAggregator.AddListener(someMessageHandler);
eventAggregator.SendMessage<SomeMessage>();
someMessageHandler.EventsTrapped.Count().ShouldEqual(1);
}
示例3: Can_use_delegate_to_subscribe_to_message
public void Can_use_delegate_to_subscribe_to_message()
{
var eventAggregator = new EventAggregator();
SomeMessage messageTrapped = null;
eventAggregator.AddListenerAction<SomeMessage>(msg => { messageTrapped = msg; });
eventAggregator.SendMessage<SomeMessage>();
messageTrapped.ShouldNotBeNull();
}
示例4: Can_use_unsubscribe_from_delegate_handler
public void Can_use_unsubscribe_from_delegate_handler()
{
var eventAggregator = new EventAggregator();
SomeMessage messageTrapped = null;
var disposable = eventAggregator.AddListenerAction<SomeMessage>(msg => { messageTrapped = msg; });
disposable.Dispose();
eventAggregator.SendMessage<SomeMessage>();
messageTrapped.ShouldBeNull();
}
示例5: EventAggregator
public void When_a_listener_has_been_garbage_collected_and_an_event_is_published_the_zombied_handler_should_be_removed()
{
var eventAggregator = new EventAggregator();
AddHandlerInScopeThatWillRemoveInstanceWhenGarbageCollected(eventAggregator);
GC.Collect();
eventAggregator.SendMessage<SomeMessage>();
eventAggregator.GetListeners().Count().ShouldEqual(0);
}
示例6: TestFileFollowerwithEventAggregator
public void TestFileFollowerwithEventAggregator()
{
var broker = new EventAggregator(new ChannelManager(), new ContextFactory());
var publisher = new EventPublisher(broker);
var filefollower = new FileFollower(publisher);
Guid identifier = Guid.Empty;
var longrunningcontext = new PoolFiber();
longrunningcontext.Start();
//register with longrunning context.
broker.AddListener<StartFollowingFileMessage>(longrunningcontext, filefollower.Handle);
//register with normal context.
broker.AddListener<StopFollowingFileMessage>(filefollower.Handle);
var reset = new AutoResetEvent(false);
broker.AddListener<FollowerStartedMessage>(message =>
{
Console.WriteLine("Follower Started" + message.Identifier);
identifier = message.Identifier;
broker.SendMessage(new StopFollowingFileMessage(identifier));
});
broker.AddListener<FollowerStoppedMessage>(message =>
{
if (message.Identifier == identifier)
{
Console.WriteLine("Follower stopped" + message.Identifier);
reset.Set();
}
});
publisher.SendMessage(new StartFollowingFileMessage(@"ExampleFiles/ExampleLogFiles/LotroLog.txt"));
Assert.IsTrue(reset.WaitOne(5000, false));
}
示例7: When_no_subscribers_can_detect_nothing_was_published
public void When_no_subscribers_can_detect_nothing_was_published()
{
var config = new EventAggregator.Config();
bool warningWasCalled = false;
config.OnMessageNotPublishedBecauseZeroListeners = msg => { warningWasCalled = true; };
var eventAggregator = new EventAggregator(config);
eventAggregator.SendMessage<SomeMessage>();
warningWasCalled.ShouldBeTrue();
}
示例8: Can_remove_a_good_listener_with_a_zombied_listener
public void Can_remove_a_good_listener_with_a_zombied_listener()
{
var eventAggregator = new EventAggregator();
SomeMessageHandler2 messageHandler2 = new SomeMessageHandler2();
AddHandlerInScopeThatWillRemoveInstanceWhenGarbageCollected(eventAggregator, false);
eventAggregator.AddListener(messageHandler2);
GC.Collect();
// both good and zombied listeners
eventAggregator.GetListeners().Count().ShouldEqual(2);
// should not throw if removing a good listener
eventAggregator.RemoveListener(messageHandler2);
// should be only zombie left
eventAggregator.GetListeners().Count().ShouldEqual(1);
eventAggregator.SendMessage<SomeMessage>();
// after call to SendMessage, the zombied listener should be removed.
eventAggregator.GetListeners().Count().ShouldEqual(0);
}
示例9: When_object_has_multiple_listeners_defined_in_an_interface_should_subscribe_to_all
public void When_object_has_multiple_listeners_defined_in_an_interface_should_subscribe_to_all()
{
var eventAggregator = new EventAggregator();
var handler = new SomeMessageHandler3();
eventAggregator.AddListener(handler);
eventAggregator.SendMessage<SomeMessage>();
eventAggregator.SendMessage<SomeMessage2>();
handler.EventsTrapped.Count().ShouldEqual(2);
}