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


C# EventAggregator.SendMessage方法代码示例

本文整理汇总了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);
		}
开发者ID:JakeGinnivan,项目名称:EventAggregator.Net,代码行数:14,代码来源:EventAggregatorTests.cs

示例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);
		}
开发者ID:JakeGinnivan,项目名称:EventAggregator.Net,代码行数:9,代码来源:EventAggregatorTests.cs

示例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();
		}
开发者ID:JakeGinnivan,项目名称:EventAggregator.Net,代码行数:10,代码来源:EventAggregatorExtensionTests.cs

示例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();
		}
开发者ID:JakeGinnivan,项目名称:EventAggregator.Net,代码行数:11,代码来源:EventAggregatorExtensionTests.cs

示例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);
		}
开发者ID:JakeGinnivan,项目名称:EventAggregator.Net,代码行数:11,代码来源:EventAggregatorTests.cs

示例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));
        }
开发者ID:andalera,项目名称:TailSentry,代码行数:35,代码来源:FileFollowerTests.cs

示例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();
		}
开发者ID:JakeGinnivan,项目名称:EventAggregator.Net,代码行数:11,代码来源:EventAggregatorTests.cs

示例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);
        }
开发者ID:stgwilli,项目名称:EventAggregator.Net,代码行数:22,代码来源:EventAggregatorTests.cs

示例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);
        }
开发者ID:stgwilli,项目名称:EventAggregator.Net,代码行数:10,代码来源:EventAggregatorTests.cs


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