Exemple #1
0
 public BindInfo(Delegate clientHandler, EventHandlerShim shim, long handlerId)
 {
     ClientHandler        = clientHandler;
     Shim                 = shim;
     HandlerId            = handlerId;
     _eventHandlerInvoker = GetEventHandlerInvoker(ClientHandler.GetType(), ClientHandler.Method.GetParameters());
 }
Exemple #2
0
 protected void ProcessInUnitOfWork(List <IEventMessage> eventMessages, IUnitOfWork unitOfWork, Segment segment)
 {
     try
     {
         unitOfWork.ExecuteWithResult(() =>
         {
             var monitorCallback = _messageMonitor.OnMessageIngested(unitOfWork.Message);
             return(new DefaultInterceptorChain(unitOfWork, _interceptors.Keys.GetEnumerator(), MessageHandler <IEventMessage> .Create(m =>
             {
                 try
                 {
                     EventHandlerInvoker.Handle(m, segment);
                     monitorCallback.ReportSuccess();
                     return null;
                 }
                 catch (Exception exception)
                 {
                     monitorCallback.ReportFailure(exception);
                     throw;
                 }
             })).Proceed());
         }, _rollbackConfiguration);
     }
     catch (Exception e)
     {
         if (unitOfWork.IsRolledBack)
         {
             _errorHandler.HandleError(new ErrorContext(Name, e, eventMessages));
         }
         else
         {
             _logger.LogInformation($"Exception occurred while processing a message, but unit of work was committed. {e.GetType().Name}");
         }
     }
 }
Exemple #3
0
        void IHandleEvent.HandleEvent(EventHandlerInvoker binding, UIEventArgs args)
        {
            Console.WriteLine("Event: " + args.Type);

            if (args is UIKeyboardEventArgs keyboardArgs)
            {
                Console.WriteLine(keyboardArgs.Type);
                Console.WriteLine(keyboardArgs.Key);
                Console.WriteLine(keyboardArgs.Code);
                Console.WriteLine(keyboardArgs.Repeat);
            }
        }
Exemple #4
0
 public void DispatchEvent(EventHandlerInvoker binding, UIEventArgs eventArgs)
 {
     if (_component is IHandleEvent handleEventComponent)
     {
         handleEventComponent.HandleEvent(binding, eventArgs);
     }
     else
     {
         throw new InvalidOperationException(
                   $"The component of type {_component.GetType().FullName} cannot receive " +
                   $"events because it does not implement {typeof(IHandleEvent).FullName}.");
     }
 }
Exemple #5
0
 protected bool CanHandle(IEventMessage eventMessage, Segment segment)
 {
     try
     {
         return(EventHandlerInvoker.CanHandle(eventMessage, segment));
     }
     catch (Exception e)
     {
         _errorHandler.HandleError(new ErrorContext(Name, e, new List <IEventMessage> {
             eventMessage
         }));
         return(false);
     }
 }
Exemple #6
0
        public IDisposable Subscribe <T>(Action <T> handler) where T : class, IMessage
        {
            var eventHandlerInvoker = new EventHandlerInvoker <T>(handler);
            var subscription        = new Subscription(eventHandlerInvoker.MessageTypeId);

            _messageDispatcher.AddInvoker(eventHandlerInvoker);

            AddSubscriptions(new[] { subscription });

            return(new DisposableAction(() =>
            {
                RemoveSubscriptions(new[] { subscription });
                _messageDispatcher.RemoveInvoker(eventHandlerInvoker);
            }));
        }
        private void BuildEventInvokers(IEnumerable<Type> eventHandlerTypes)
        {
            eventHandlerInvokers = new Dictionary<Type, EventHandlerInvoker>();
            foreach(var eventHandlerType in eventHandlerTypes)
            {
                foreach(var domainEventType in GetDomainEventTypes(eventHandlerType))
                {
                    EventHandlerInvoker eventInvoker;
                    if(!eventHandlerInvokers.TryGetValue(domainEventType, out eventInvoker))
                        eventInvoker = new EventHandlerInvoker(eventHandlerBuilder, domainEventType);

                    eventInvoker.AddEventHandlerType(eventHandlerType);
                    eventHandlerInvokers[domainEventType] = eventInvoker;
                }
            }
        }
        private void BuildEventInvokers(IEnumerable <Type> eventHandlerTypes)
        {
            eventHandlerInvokers = new Dictionary <Type, EventHandlerInvoker>();
            foreach (var eventHandlerType in eventHandlerTypes)
            {
                foreach (var domainEventType in GetDomainEventTypes(eventHandlerType))
                {
                    EventHandlerInvoker eventInvoker;
                    if (!eventHandlerInvokers.TryGetValue(domainEventType, out eventInvoker))
                    {
                        eventInvoker = new EventHandlerInvoker(eventHandlerBuilder, domainEventType);
                    }

                    eventInvoker.AddEventHandlerType(eventHandlerType);
                    eventHandlerInvokers[domainEventType] = eventInvoker;
                }
            }
        }
Exemple #9
0
        /// <inheritdoc />
        public void Subscribe <TMessage>(object handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            var messageType = typeof(TMessage);
            var invoker     = new EventHandlerInvoker(handler, messageType);

            if (this.handlers.ContainsKey(messageType))
            {
                this.handlers[messageType].Add(invoker);
            }
            else
            {
                this.handlers.Add(
                    messageType,
                    new List <EventHandlerInvoker> {
                    invoker
                });
            }
        }
Exemple #10
0
            public static IDisposable BindEvent(this object sender, string eventName, EventHandlerInvoker executeAction)
            {
                var t = sender.GetType();

                while (t != null)
                {
                    var       es = t.GetEventsFromCache();
                    EventInfo ei = es.MatchOrDefault(eventName);


                    if (ei != null)
                    {
                        var handlerType = ei.EventHandlerType;
                        var eventMethod = handlerType.GetMethodsFromCache().MatchOrDefault("Invoke");
                        if (eventMethod != null)
                        {
                            var pts = eventMethod.GetParameters().Select(p => p.ParameterType)
                                      .ToArray();
                            var newHandler = CreateHandler(
                                (o, e, en, ehtype) => executeAction(o, e, en, ehtype),
                                eventName,
                                handlerType,
                                pts
                                );

#if NETFX_CORE || WINDOWS_PHONE_8
                            var etmodule = sender.GetType().GetTypeOrTypeInfo().Module;
                            try
                            {
                                return(DoNetEventBind(sender, ei, newHandler));
                            }
                            catch (InvalidOperationException ex)
                            {
                                var newMI = WinRTEventBindMethodInfo.MakeGenericMethod(newHandler.GetType());

                                var rval = newMI.Invoke(null, new object[] { sender, ei, newHandler }) as IDisposable;


                                return(rval);
                            }
#else
                            return(DoNetEventBind(sender, ei, newHandler));
#endif
                        }

                        return(null);
                    }

                    t = t.GetTypeOrTypeInfo().BaseType;
                }

                return(null);
            }
Exemple #11
0
 public void HandleEvent(EventHandlerInvoker binding, UIEventArgs args)
 {
     binding.Invoke(args);
     TriggerRender();
 }
Exemple #12
0
            public void HandleEvent(EventHandlerInvoker binding, UIEventArgs args)
            {
                var task = binding.Invoke(args);

                Render();
            }
Exemple #13
0
 public void HandleEvent(EventHandlerInvoker binding, UIEventArgs args)
 {
     binding.Invoke(args);
 }
 public void FireEventWithArgsWithEventHandlerInvoker(object sender, object args)
 {
     EventHandlerInvoker.Invoke(EventWithArgs, sender, args);
 }
 public void FireSimpleActionEventWithEventHandlerInvoker()
 {
     EventHandlerInvoker.Invoke(SimpleActionEvent);
 }