本文整理汇总了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();
});
}
示例2: NullActionThrows
public void NullActionThrows()
{
var filterDelegateReference = new MockDelegateReference()
{
Target = (Predicate<object>)(arg =>
{
return true;
})
};
var eventSubscription = new EventSubscription<object>(null, filterDelegateReference);
}
示例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.");
}
示例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);
}
示例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.");
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
});
}
示例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);
}
示例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);
});
}
示例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;
}
示例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"));
}
示例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);
});
}