Exemplo n.º 1
0
        public async Task Consume(ConsumeContext <TMessage> context)
        {
            var token          = CancellationToken.None;
            var configurations = await _provisioningConfigurationRepository.GetAll(token);

            foreach (var configuration in configurations)
            {
                if (configuration.IsRepresentationProvisioned(context.Message.Id, context.Message.Version) ||
                    configuration.ResourceType != context.Message.ResourceType)
                {
                    continue;
                }

                var          provisioner = _provisioners.First(p => p.Type == configuration.Type);
                ITransaction transaction = null;
                var          description = $"{Enum.GetName(typeof(ProvisioningOperations), Type)} the resource {configuration.ResourceType}";
                try
                {
                    transaction = await _provisioningConfigurationRepository.StartTransaction(token);

                    var workflowResult = await LaunchWorkflow(configuration, context);

                    await provisioner.Seed(Type,
                                           context.Message.Id,
                                           context.Message.Representation,
                                           configuration,
                                           token);

                    configuration.Complete(context.Message.Id, description, workflowResult.InstanceId, workflowResult.FileId, context.Message.Version);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.ToString());
                    configuration.Error(context.Message.Id, description, context.Message.Version, ex.ToString());
                }
                finally
                {
                    await _provisioningConfigurationRepository.Update(configuration, token);

                    await transaction.Commit(token);
                }
            }
        }
        public async Task <IActionResult> UpdateConfiguration(string id, [FromBody] UpdateProvisioningConfigurationParameter parameter, CancellationToken cancellationToken)
        {
            using (var transaction = await _provisioningConfigurationRepository.StartTransaction(cancellationToken))
            {
                var configuration = await _provisioningConfigurationRepository.Get(id, cancellationToken);

                if (configuration == null)
                {
                    return(new NotFoundResult());
                }

                configuration.Update(parameter.Records.Select(r => r.ToDomain()));
                await _provisioningConfigurationRepository.Update(configuration, cancellationToken);

                await transaction.Commit();

                return(new NoContentResult());
            }
        }