Esempio n. 1
0
        public async Task HandleAsync(IEvent @event)
        {
            var type = @event.GetType();
            var denormalizerGroups = mapping
                                     .Resolve(type)
                                     .GroupBy(x => x.ParentType)
                                     .ToList();

            var watch = Stopwatch.StartNew();

            foreach (IGrouping <TypeInfo, EventHandlerMethod> denormailzer in denormalizerGroups)
            {
                KeyValuePair <TypeInfo, object> instance =
                    normalizerInstances.Single(x => x.Key.Equals(denormailzer.Key));

                foreach (EventHandlerMethod method in denormailzer)
                {
                    if (method.Background && backgroundEventQueue != null)
                    {
                        var task = SafeInvoke(@event, @method, instance.Value);
                        await backgroundEventQueue.QueueBackgroundWorkItemAsync(x => task);
                    }
                    else
                    {
                        await SafeInvoke(@event, method, instance.Value);
                    }
                }
            }

            watch.Stop();
            logger?.LogTrace("\"{type.FullName}\" handled in {watch.ElapsedMilliseconds}ms", type.FullName,
                             watch.ElapsedMilliseconds);
        }