예제 #1
0
        /// <summary>
        ///     Process an event asynchronously.
        /// </summary>
        /// <param name="e">event to process</param>
        /// <returns>
        ///     Task to wait on.
        /// </returns>
        public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            _logger.Debug("doing collections");
            var collections = await _repository.GetCollectionsAsync(e.Incident.ApplicationId);

            foreach (var collectionDto in e.Report.ContextCollections)
            {
                var isNew = false;
                var meta  =
                    collections.FirstOrDefault(x => x.Name.Equals(collectionDto.Name, StringComparison.OrdinalIgnoreCase));
                if (meta == null)
                {
                    isNew = true;
                    meta  = new CollectionMetadata(e.Incident.ApplicationId, collectionDto.Name);
                }

                foreach (var property in collectionDto.Properties)
                {
                    meta.AddOrUpdateProperty(property.Key);
                }

                if (!meta.IsUpdated)
                {
                    continue;
                }

                if (isNew)
                {
                    await _repository.CreateAsync(meta);
                }
                else
                {
                    await _repository.UpdateAsync(meta);
                }
            }

            _logger.Debug("collections done");
        }
        /// <summary>
        ///     Execute a command asynchronously.
        /// </summary>
        /// <param name="command">Command to execute.</param>
        /// <returns>
        ///     Task which will be completed once the command has been executed.
        /// </returns>
        public async Task HandleAsync(IMessageContext context, CreateTrigger command)
        {
            var domainModel = new Trigger(command.ApplicationId)
            {
                Description       = command.Description,
                LastTriggerAction = DtoToDomainConverters.ConvertLastAction(command.LastTriggerAction),
                Id   = command.Id,
                Name = command.Name,
                RunForExistingIncidents = command.RunForExistingIncidents,
                RunForReopenedIncidents = command.RunForReOpenedIncidents,
                RunForNewIncidents      = command.RunForNewIncidents
            };

            foreach (var action in command.Actions)
            {
                domainModel.AddAction(DtoToDomainConverters.ConvertAction(action));
            }
            foreach (var rule in command.Rules)
            {
                domainModel.AddRule(DtoToDomainConverters.ConvertRule(rule));
            }

            await _repository.CreateAsync(domainModel);
        }