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


C# EventSubscription类代码示例

本文整理汇总了C#中EventSubscription的典型用法代码示例。如果您正苦于以下问题:C# EventSubscription类的具体用法?C# EventSubscription怎么用?C# EventSubscription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: userKicked_Published

 void userKicked_Published(object sender, EventSubscription<UserKicked>.PublishedEventArgs e)
 {
     // Inform that user has been kicked and exit the application when UserKicked event is published
     ExecuteOnUIThread(() =>
     {
         MessageBox.Show("You have been kicked");
         this.Close();
     });
 }
开发者ID:Turntwo,项目名称:nvents,代码行数:9,代码来源:MainWindow.xaml.cs

示例2: NullActionThrows

 public void NullActionThrows()
 {
     var filterDelegateReference = new MockDelegateReference()
     {
         Target = (Predicate<object>)(arg =>
         {
             return true;
         })
     };
     var eventSubscription = new EventSubscription<object>(null, filterDelegateReference);
 }
开发者ID:selvendiranj,项目名称:compositewpf-copy,代码行数:11,代码来源:EventSubscriptionFixture.cs

示例3: Create

        public static EventListener Create(EventSubscription eventSubscription)
        {
            switch (eventSubscription.EventType)
            {
                case "NewSensorData":
                    return new SensorDataEventListener(eventSubscription);
                case "NewPosition":
                    return new PositionEventListener(eventSubscription);
            }

            throw new ArgumentOutOfRangeException("eventSubscription", "EventType does not exist.");
        }
开发者ID:AmarChalla,项目名称:wsnlocalizationscala,代码行数:12,代码来源:EventListener.cs

示例4: FilterShouldNotBeNull

        public void FilterShouldNotBeNull()
        {
            var action = new Mock<IDelegateReference>();
            action.SetupGet(a => a.Target).Returns((Action<object>)delegate { });

            var filter = new Mock<IDelegateReference>();
            filter.SetupGet(a => a.Target).Returns((Predicate<object>)delegate { return true; });

            var subscription = new EventSubscription<object>(action.Object, filter.Object);

            Assert.That(subscription.Filter, Is.Not.Null);
        }
开发者ID:pleb,项目名称:Tank,代码行数:12,代码来源:EventSubscriptionFixture.cs

示例5: Create

 /// <summary>
 /// Creates an instance of the correct child eventlistener
 /// </summary>
 /// <param name="eventSubscription"></param>
 /// <returns></returns>
 public static EventListener Create(EventSubscription eventSubscription)
 {
     switch (eventSubscription.EventType)
     {
         case "ButtonPressed":
         case "HumidityChanged":
         case "LightChanged":
         case "TemperatureChanged":
             return new SensorDataEventListener(eventSubscription);
         case "LocationUpdated":
             return new PositionEventListener(eventSubscription);
     }
     throw new ArgumentOutOfRangeException("eventSubscription", "EventType does not exist.");
 }
开发者ID:AmarChalla,项目名称:wsnlocalizationscala,代码行数:19,代码来源:EventListener.cs

示例6: CanInitEventSubscription

        public void CanInitEventSubscription()
        {
            var actionDelegateReference = new MockDelegateReference((Action<object>)delegate { });
            var filterDelegateReference = new MockDelegateReference((Predicate<object>)delegate { return true; });
            var eventSubscription = new EventSubscription<object>(actionDelegateReference, filterDelegateReference, null, EventCommunicatorsRelationship.All);

            var subscriptionToken = new SubscriptionToken(t => { });

            eventSubscription.SubscriptionToken = subscriptionToken;

            Assert.Same(actionDelegateReference.Target, eventSubscription.Action);
            Assert.Same(filterDelegateReference.Target, eventSubscription.Filter);
            Assert.Same(subscriptionToken, eventSubscription.SubscriptionToken);
        }
开发者ID:Marfusios,项目名称:MKEventAggregator,代码行数:14,代码来源:EventSubscriptionTests.cs

示例7: NullTargetInFilterThrows

        public void NullTargetInFilterThrows()
        {
            var actionDelegateReference = new MockDelegateReference()
            {
                Target = (Action<object>)delegate { }
            };

            var filterDelegateReference = new MockDelegateReference()
            {
                Target = null
            };
            var eventSubscription = new EventSubscription<object>(actionDelegateReference,
                                                                                filterDelegateReference);
        }
开发者ID:selvendiranj,项目名称:compositewpf-copy,代码行数:14,代码来源:EventSubscriptionFixture.cs

示例8: DifferentTargetTypeInActionThrows

 public void DifferentTargetTypeInActionThrows()
 {
     var actionDelegateReference = new MockDelegateReference()
     {
         Target = (Action<int>)delegate { }
     };
     var filterDelegateReference = new MockDelegateReference()
     {
         Target = (Predicate<string>)(arg =>
         {
             return true;
         })
     };
     var eventSubscription = new EventSubscription<string>(actionDelegateReference,
                                                                     filterDelegateReference);
 }
开发者ID:jeffras,项目名称:Prism-4-with-WinForms,代码行数:16,代码来源:EventSubscriptionFixture.cs

示例9: SubscribeToEvents

        private void SubscribeToEvents()
        {
            // Workaround for issue #2 'EventSubscription<TEvent> default constructor does not start the service'
            // This issue is fixed in nvents 0.7
            Events.Service.Start();

            // Create a EventSubscription for the MessageSent event
            var messageSent = new EventSubscription<MessageSent>();
            // Register a handler for when Published is raised for MessageSent event
            messageSent.Published += messageSent_Published;

            // Create a EventSubscription for the UserKicked event and filter to only the current user
            var userKicked = new EventSubscription<UserKicked>(user => user.UserId == currentUser.Id);
            // Register a handler for when Published is raised for UserKicked event (will only be raised for events that passes the subscription filter)
            userKicked.Published += userKicked_Published;
        }
开发者ID:Turntwo,项目名称:nvents,代码行数:16,代码来源:MainWindow.xaml.cs

示例10: NullTargetInActionThrows

 public void NullTargetInActionThrows()
 {
     Assert.ThrowsException<ArgumentException>(() =>
     {
         var actionDelegateReference = new MockDelegateReference()
         {
             Target = null
         };
         var filterDelegateReference = new MockDelegateReference()
         {
             Target = (Predicate<object>)(arg =>
             {
                 return true;
             })
         };
         var eventSubscription = new EventSubscription<object>(actionDelegateReference,
                                                                         filterDelegateReference);
     });
 }
开发者ID:stevenh77,项目名称:ItineraryHunter-Win8,代码行数:19,代码来源:EventSubscriptionFixture.cs

示例11: GetExecutionStrategyDoesNotExecuteActionIfFilterReturnsFalse

        public void GetExecutionStrategyDoesNotExecuteActionIfFilterReturnsFalse()
        {
            bool actionExecuted = false;
            var actionDelegate = new Mock<IDelegateReference>();

            actionDelegate.SetupGet(d => d.Target).Returns((Action<int>)delegate { actionExecuted = true; });

            var filterDelegate = new Mock<IDelegateReference>();

            filterDelegate.SetupGet(d => d.Target).Returns((Predicate<int>)delegate { return false; });

            var eventSubscription = new EventSubscription<int>(actionDelegate.Object, filterDelegate.Object);

            var publishAction = eventSubscription.GetExecutionStrategy();

            publishAction.Invoke(new object[] { null });

            Assert.That(actionExecuted, Is.False);
        }
开发者ID:pleb,项目名称:Tank,代码行数:19,代码来源:EventSubscriptionFixture.cs

示例12: DifferentTargetTypeInActionThrows

        public void DifferentTargetTypeInActionThrows()
        {
            var actionDelegateReference = new MockDelegateReference()
            {
                Target = (Action<int>)delegate { }
            };
            var filterDelegateReference = new MockDelegateReference()
            {
                Target = (Predicate<string>)(arg =>
                {
                    return true;
                })
            };

            Assert.Throws<ArgumentException>(
                () =>
                {
                    var eventSubscription = new EventSubscription<string>(actionDelegateReference,
                        filterDelegateReference, null, EventCommunicatorsRelationship.All);
                });
        }
开发者ID:Marfusios,项目名称:MKEventAggregator,代码行数:21,代码来源:EventSubscriptionTests.cs

示例13: GetAll

        public IEnumerable<EventSubscription> GetAll()
        {
            var subscriptions = new List<EventSubscription>();
            var path = GetPathForSubscriptions();
            var files = Directory.GetFiles(path);

            foreach (var file in files)
            {
                var json = File.ReadAllText(file);
                var holder = _serializer.FromJson<EventSubscriptionHolder>(json);
                var subscription = new EventSubscription();
                subscription.Id = Guid.Parse(holder.Id);
                subscription.LastEventId = holder.LastEventId;
                subscription.Owner = Type.GetType(holder.Owner);
                subscription.EventType = Type.GetType(holder.EventType);
                subscription.EventName = holder.EventName;
                subscription.Method = subscription.Owner.GetMethod(Bifrost.Events.ProcessMethodInvoker.ProcessMethodName, new Type[] { subscription.EventType });
                subscriptions.Add(subscription);
            }

            return subscriptions;
        }
开发者ID:LenFon,项目名称:Bifrost,代码行数:22,代码来源:EventSubscriptions.cs

示例14: GetExecutionStrategyShouldReturnDelegateThatExecutesTheFilterAndThenTheAction

        public void GetExecutionStrategyShouldReturnDelegateThatExecutesTheFilterAndThenTheAction()
        {
            var executedDelegates = new List<string>();

            var actionDelegate = new Mock<IDelegateReference>();

            actionDelegate.SetupGet(d => d.Target).Returns((Action<object>) delegate { executedDelegates.Add("Action"); });

            var filterDelegate = new Mock<IDelegateReference>();

            filterDelegate.SetupGet(d => d.Target).Returns((Predicate<object>) delegate { executedDelegates.Add("Filter"); return true; });

            var eventSubscription = new EventSubscription<object>(actionDelegate.Object, filterDelegate.Object);

            var publishAction = eventSubscription.GetExecutionStrategy();

            Assert.That(publishAction, Is.Not.Null);

            publishAction.Invoke(null);

            Assert.That(executedDelegates.Count, Is.EqualTo(2));
            Assert.That(executedDelegates[0], Is.EqualTo("Filter"));
            Assert.That(executedDelegates[1], Is.EqualTo("Action"));
        }
开发者ID:pleb,项目名称:Tank,代码行数:24,代码来源:EventSubscriptionFixture.cs

示例15: NullTargetInFilterThrows

        public void NullTargetInFilterThrows()
        {
            var actionDelegateReference = new MockDelegateReference()
            {
                Target = (Action<object>)delegate { }
            };

            var filterDelegateReference = new MockDelegateReference()
            {
                Target = null
            };

            Assert.Throws<ArgumentException>(
                () =>
                {
                    var eventSubscription = new EventSubscription<object>(actionDelegateReference,
                        filterDelegateReference, null, EventCommunicatorsRelationship.All);
                });
        }
开发者ID:Marfusios,项目名称:MKEventAggregator,代码行数:19,代码来源:EventSubscriptionTests.cs


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