本文整理汇总了C#中IEventHandler类的典型用法代码示例。如果您正苦于以下问题:C# IEventHandler类的具体用法?C# IEventHandler怎么用?C# IEventHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IEventHandler类属于命名空间,在下文中一共展示了IEventHandler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BuildHandlerInvocations
private IEnumerable<Tuple<Type, Action<IEvent>>> BuildHandlerInvocations(IEventHandler handler)
{
return handler.GetType().GetInterfaces()
.Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEventHandler<>))
.Select(i => new { HandlerInterface = i, EventType = i.GetGenericArguments()[0] })
.Select(e => new Tuple<Type, Action<IEvent>>(e.EventType, this.BuildHandlerInvocation(handler, e.HandlerInterface, e.EventType)));
}
开发者ID:AlexShkorParalect,项目名称:cqrs-journey-code,代码行数:7,代码来源:MessageDispatcher.cs
示例2: CreateEventProcessor
// Can't really infer the topic from the subscription, since subscriptions of the same
// name can exist across different topics (i.e. "all" currently)
public EventProcessor CreateEventProcessor(string subscription, IEventHandler handler, ITextSerializer serializer)
{
if (!this.initialized)
throw new InvalidOperationException("Service bus configuration has not been initialized.");
var topicSettings = this.settings.Topics.Find(x => x.IsEventBus);
if (topicSettings == null)
throw new ArgumentOutOfRangeException("No topic has been marked with the IsEventBus attribute. Cannot create event processor.");
var subscriptionSettings = topicSettings.Subscriptions.Find(x => x.Name == subscription);
if (subscriptionSettings == null)
throw new ArgumentOutOfRangeException(string.Format(
CultureInfo.CurrentCulture,
"Subscription '{0}' for topic '{1}' has not been registered in the service bus configuration.",
subscription, topicSettings.Path));
var receiver = subscriptionSettings.RequiresSession ?
(IMessageReceiver)new SessionSubscriptionReceiver(this.settings, topicSettings.Path, subscription) :
(IMessageReceiver)new SubscriptionReceiver(this.settings, topicSettings.Path, subscription);
var processor = new EventProcessor(receiver, serializer);
processor.Register(handler);
return processor;
}
开发者ID:garystanford,项目名称:cqrs-journey-code,代码行数:27,代码来源:ServiceBusConfig.cs
示例3: RegisterEventHandler
public static void RegisterEventHandler(IEventHandler handler)
{
Monitor.Enter(_lock);
if (!_handlers.Contains(handler))
_handlers.Add(handler);
Monitor.Exit(_lock);
}
开发者ID:marquismark,项目名称:freeswitchconfig,代码行数:7,代码来源:EventController.cs
示例4: DetachHandler
/// <summary>
/// Detaches a handler
/// </summary>
/// <param name="handler">A event handler/subscriber</param>
public void DetachHandler(IEventHandler handler)
{
if (!_handlers.Remove(handler))
{
throw new ArgumentException("Referenced handler is not attached to this emmiter!");
}
}
开发者ID:PJK,项目名称:Discrete-Event-Simulation-Framework,代码行数:11,代码来源:EventEmmitingProvider.cs
示例5:
void IEventHelpers.RegisterSocketRead(IEvent e, BufferedSocket socket, IEventHandler protocol,
ReadFunction callback)
{
//Contract.Requires(socket != null);
Contract.Requires(protocol != null);
Contract.Requires(callback != null);
}
开发者ID:splitice,项目名称:EventCore,代码行数:7,代码来源:IEventHelpers.cs
示例6: _ProcessEvent
private static void _ProcessEvent(object obj)
{
IEvent evnt = (IEvent)obj;
lock(_rand){
Thread.CurrentThread.Name = "EventProcessor{" + evnt.Name + "}["+_rand.Next().ToString()+"]";
}
Thread.CurrentThread.IsBackground = true;
IEventHandler[] handlers = new IEventHandler[0];
Monitor.Enter(_lock);
handlers = new IEventHandler[_handlers.Count];
_handlers.CopyTo(handlers);
Monitor.Exit(_lock);
foreach (IEventHandler handler in handlers)
{
Log.Trace("Checking if " + handler.GetType().FullName + " handles event " + evnt.Name);
if (handler.HandlesEvent(evnt))
{
Thread delThread = null;
Log.Trace("Handling event " + evnt.Name + " with handler " + handler.GetType().FullName);
IAsyncResult res = _eventHandle.BeginInvoke(handler, evnt,ref delThread, null, null);
if (res.AsyncWaitHandle.WaitOne(_EVENT_HANDLING_TIMEOUT))
_eventHandle.EndInvoke(ref delThread,res);
else
{
Log.Error("Handle " + handler.GetType().FullName + " timed out handling event " + evnt.Name);
try
{
delThread.Abort();
}
catch (Exception e) { }
_eventHandle.EndInvoke(ref delThread,res);
}
}
}
}
开发者ID:marquismark,项目名称:freeswitchconfig,代码行数:35,代码来源:EventController.cs
示例7: RegisterEventHandler
private static void RegisterEventHandler(IEventHandler eventHandler)
{
object instance = eventHandler.Model;
_modelMap.Add(instance.GetType(), instance);
RegisterMessageHandler("SubscribeEventHandler", eventHandler);
}
开发者ID:ymotton,项目名称:CQRS-Sample1,代码行数:7,代码来源:ProcessHandler.cs
示例8: GetMatchingMethod
private static MethodInfo GetMatchingMethod(IEventHandler eventHandler, Type interfaceType, string methodName, IDictionary<string, object> arguments)
{
var allMethods = new List<MethodInfo>(interfaceType.GetMethods());
var candidates = new List<MethodInfo>(allMethods);
foreach (var method in allMethods) {
if (string.Equals(method.Name, methodName, StringComparison.OrdinalIgnoreCase)) {
ParameterInfo[] parameterInfos = method.GetParameters();
foreach (var parameter in parameterInfos) {
if (!arguments.ContainsKey(parameter.Name)) {
candidates.Remove(method);
break;
}
}
}
else {
candidates.Remove(method);
}
}
// treating common case separately
if (candidates.Count == 1) {
return candidates[0];
}
if (candidates.Count != 0) {
return candidates.OrderBy(x => x.GetParameters().Length).Last();
}
return null;
}
开发者ID:nicklv,项目名称:Orchard2,代码行数:31,代码来源:DefaultOrchardEventBus.cs
示例9: TimerStage
/// <summary>Constructs a timer stage</summary>
/// <param name="handler">an event handler</param>
/// <param name="initialDelay">an initial delay</param>
/// <param name="period">a period in milli-seconds</param>
public TimerStage(IEventHandler<PeriodicEvent> handler, long initialDelay, long period)
{
_handler = handler;
_timer = new Timer(period);
_timer.Elapsed += (sender, e) => OnTimedEvent(sender, e, _handler, _value);
_timer.Enabled = true;
}
开发者ID:NurimOnsemiro,项目名称:reef,代码行数:11,代码来源:TimerStage.cs
示例10: RegisterListener
/// <summary>
/// Registers a listener for a specific event
/// </summary>
/// <param name="eventType">Event the listener is listening for</param>
/// <param name="listener">Listener receiving messages for the specified event</param>
public void RegisterListener(EventType eventType, IEventHandler listener)
{
List<IEventHandler> listeners = RegisterEvent(eventType);
if (listeners.Contains(listener))
throw new Exception(string.Format("Listener {0} already listen to event {1}", listener, eventType.EventName));
listeners.Add(listener);
}
开发者ID:Julien-Pires,项目名称:Pulsar,代码行数:13,代码来源:Mediator.cs
示例11: Invoke
public virtual void Invoke(IEventHandler handler, IEvent @event)
{
Ensure.That(handler, "handler").IsNotNull();
Ensure.That(@event, "event").IsNotNull();
var container = ContainerFactory.Invoke(handler.ContainerType);
handler.Handler.Invoke(container, new object[] { @event });
}
开发者ID:girish66,项目名称:LiteCQRS,代码行数:8,代码来源:EventHandlerInvoker.cs
示例12: InitializeEventBus
private static IEventBus InitializeEventBus(IEventHandler<NewNoteAdded> handler, TextChangedHandler textChangedHandler)
{
var bus = new InProcessEventBus();
bus.RegisterHandler(handler);
bus.RegisterHandler(textChangedHandler);
return bus;
}
开发者ID:kajaljatakia,项目名称:ncqrs,代码行数:8,代码来源:BootStrapper.cs
示例13: RegisterHandler
public string RegisterHandler(IEventHandler handler)
{
_mut.WaitOne();
string ret = _rand.NextString(_ID_LENGTH);
_handlers.Add(new sEventHandler(handler, ret));
_mut.ReleaseMutex();
return ret;
}
开发者ID:roger-castaldo,项目名称:MultiDomain,代码行数:8,代码来源:EventController.cs
示例14: TryInvoke
private static bool TryInvoke(IEventHandler eventHandler, string interfaceName, string methodName, IDictionary<string, object> arguments, out IEnumerable returnValue) {
Type type = eventHandler.GetType();
foreach (var interfaceType in type.GetInterfaces()) {
if (String.Equals(interfaceType.Name, interfaceName, StringComparison.OrdinalIgnoreCase)) {
return TryInvokeMethod(eventHandler, interfaceType, methodName, arguments, out returnValue);
}
}
returnValue = null;
return false;
}
开发者ID:akhurst,项目名称:ricealumni,代码行数:10,代码来源:DefaultOrchardEventBus.cs
示例15: TimerStage
/// <summary>Constructs a timer stage</summary>
/// <param name="handler">an event handler</param>
/// <param name="initialDelay">an initial delay in the interval [0,MaxTimeValue]</param>
/// <param name="period">a period in milli-seconds in the interval [0,MaxTimeValue]</param>
public TimerStage(IEventHandler<PeriodicEvent> handler, long initialDelay, long period)
{
// Core .NET only supports 32 bit timers.
Validate("initialDelay", initialDelay);
Validate("period", period);
_handler = handler;
_timer = new Timer(
(object state) => { OnTimedEvent(_handler, _value); }, this, (int)initialDelay, (int)period);
}
开发者ID:beomyeol,项目名称:reef,代码行数:14,代码来源:TimerStage.cs
示例16: TryNotifyHandler
private bool TryNotifyHandler(IEventHandler eventHandler, string messageName, string interfaceName, string methodName, IDictionary<string, object> eventData, out IEnumerable returnValue) {
try {
return TryInvoke(eventHandler, messageName, interfaceName, methodName, eventData, out returnValue);
} catch (Exception exception) {
if (!_exceptionPolicy.HandleException(this, exception))
throw;
returnValue = null;
return false;
}
}
开发者ID:hsb0307,项目名称:Nut.NET,代码行数:11,代码来源:DefaultEventBus.cs
示例17: addHandler
public void addHandler(GameEventType gameEventType, int listeningToEntityId, IEventHandler handler)
{
if (!_handlers.ContainsKey(gameEventType))
_handlers.Add(gameEventType, new Dictionary<int,List<IEventHandler>>());
if (!_handlers[gameEventType].ContainsKey(listeningToEntityId))
_handlers[gameEventType].Add(listeningToEntityId, new List<IEventHandler>());
if (!_handlers[gameEventType][listeningToEntityId].Contains(handler))
{
_handlers[gameEventType][listeningToEntityId].Add(handler);
}
}
开发者ID:klutch,项目名称:StasisEngine,代码行数:11,代码来源:EventSystem.cs
示例18: Context
protected override void Context()
{
_handler = MockRepository.GenerateMock<IEventHandler<EventData>>();
IEventPublisher eventPublisher = new EventPublisher();
eventPublisher.RegisterHandler(_handler);
eventPublisher.UnregisterHandler(_handler);
eventPublisher.Publish(new EventData("My Event Data"));
}
开发者ID:panshuiqing,项目名称:appcontroller,代码行数:11,代码来源:EventAggregatorSpecs.cs
示例19: factory
/// <summary>
/// A factory method for creating a consumer from an array of hashes.
/// </summary>
/// <param name="user">The user object that's creating this consumer.</param>
/// <param name="type">The consumer type.</param>
/// <param name="hashes">An array of stream hashes.</param>
/// <param name="event_handler">An object that implements IEventHandler which will receive the events.</param>
/// <returns>An object of a type derived from this class.</returns>
public static StreamConsumer factory(User user, string type, string[] hashes, IEventHandler event_handler)
{
switch (type)
{
case "http":
return new StreamConsumer_Http(user, hashes, event_handler);
default:
throw new InvalidDataException("Consumer type \"" + type + "\" is unknown");
}
}
开发者ID:pavitardua,项目名称:datasift-dotnet,代码行数:19,代码来源:StreamConsumer.cs
示例20: EventRegistration
public EventRegistration(
IEventHandler handler,
Func<IEventHandler, Envelope, object> interceptor)
{
this.Handler = handler;
_interceptor = interceptor;
_registrationInfo = new Dictionary<string, string>();
_registrationInfo.SetMessageTopic(handler.Topic);
_log = LogManager.GetLogger(this.GetType());
}
开发者ID:berico-tpinney,项目名称:AMP,代码行数:12,代码来源:EventRegistration.cs
注:本文中的IEventHandler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论