Пример #1
0
        public async Task IndexAsync(CronusMessage message)
        {
            IEnumerable <Type> projectionTypes = projectionsContainer.Items;

            if (message.IsRepublished)
            {
                projectionTypes = message.RecipientHandlers.Intersect(projectionsContainer.Items.Select(t => t.GetContractId())).Select(dc => dc.GetTypeByContract());
            }

            List <Task> projectionSaveTasks = new List <Task>();
            Type        messagePayloadType  = message.Payload.GetType();

            foreach (var projectionType in projectionTypes)
            {
                bool isInterested = projectionType.GetInterfaces()
                                    .Where(x => x.IsGenericType && x.GetGenericArguments().Length == 1 && (baseMessageType.IsAssignableFrom(x.GetGenericArguments()[0])))
                                    .Where(@interface => @interface.GetGenericArguments()[0].IsAssignableFrom(messagePayloadType))
                                    .Any();

                if (isInterested)
                {
                    projectionSaveTasks.Add(projection.SaveAsync(projectionType, message));
                }
            }

            await Task.WhenAll(projectionSaveTasks).ConfigureAwait(false);
        }