Beispiel #1
0
        /// <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 ExecuteAsync(UpdateTrigger command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            var domainEntity = await _triggerRepository.GetAsync(command.Id);

            domainEntity.Description       = command.Description;
            domainEntity.LastTriggerAction = DtoToDomainConverters.ConvertLastAction(command.LastTriggerAction);
            domainEntity.Name = command.Name;
            domainEntity.RunForExistingIncidents = command.RunForExistingIncidents;
            domainEntity.RunForReopenedIncidents = command.RunForReOpenedIncidents;
            domainEntity.RunForNewIncidents      = command.RunForNewIncidents;

            domainEntity.RemoveActions();
            foreach (var action in command.Actions)
            {
                domainEntity.AddAction(DtoToDomainConverters.ConvertAction(action));
            }

            domainEntity.RemoveRules();
            foreach (var rule in command.Rules)
            {
                domainEntity.AddRule(DtoToDomainConverters.ConvertRule(rule));
            }

            await _triggerRepository.UpdateAsync(domainEntity);
        }
Beispiel #2
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");
        }