Exemple #1
0
        private async Task HandleUploadRequest(HttpContext context, string clientid, ConfigurationSetModel configSetModel)
        {
            var input = await context.GetJObjectFromJsonBodyAsync();

            var mappedConfigs    = configurationSetUploadMapper.MapConfigurationSetUpload(input, configSetModel).ToArray();
            var identity         = new ConfigurationIdentity(clientid);
            var validationResult = await ValidateConfigs(mappedConfigs, configSetModel, identity);

            if (validationResult.IsValid)
            {
                foreach (var config in mappedConfigs)
                {
                    var type = config.Value.GetType();
                    if (configSetModel.Get(type).IsReadOnly)
                    {
                        continue;
                    }
                    var instance = await configRepository.GetAsync(type, identity);

                    instance.SetConfiguration(config.Value);
                    await configRepository.UpdateConfigAsync(instance);

                    await eventService.Publish(new ConfigurationUpdatedEvent(instance));
                }
                responseFactory.BuildNoContentResponse(context);
            }
            else
            {
                responseFactory.BuildStatusResponse(context, 422);
            }
        }
Exemple #2
0
        public async Task <CommandResult> Handle(UpdateConfigurationSetFromJsonUploadCommand command)
        {
            var configSetModel      = registry.GetConfigSetDefinition(command.ConfigurationSetType);
            var mappedConfigs       = configurationSetUploadMapper.MapConfigurationSetUpload(command.JsonUpload, configSetModel).ToArray();
            var propertyModelLookup = configSetModel.Configs.ToDictionary(k => k.Name, StringComparer.OrdinalIgnoreCase);
            var validationResult    = await ValidateConfigs(mappedConfigs, propertyModelLookup, command.Identity);

            if (validationResult.IsValid)
            {
                foreach (var config in mappedConfigs)
                {
                    var model = propertyModelLookup[config.Key];
                    if (model.IsReadOnly)
                    {
                        continue;
                    }
                    ConfigInstance instance = BuildConfigInstance(command, model, config.Value);
                    await configRepository.UpdateConfigAsync(instance);

                    await eventService.Publish(new ConfigurationUpdatedEvent(instance));
                }
                return(CommandResult.Success());
            }
            else
            {
                return(CommandResult.Failure(string.Join(Environment.NewLine, validationResult.Errors)));
            }
        }
        private async Task HandleUploadRequest(HttpContext context, string clientid, ConfigurationSetModel configSetModel)
        {
            var input = await context.GetJObjectFromJsonBodyAsync();

            var mappedConfigs    = configurationSetUploadMapper.MapConfigurationSetUpload(input, configSetModel).ToArray();
            var validationResult = ValidateConfigs(mappedConfigs, configSetModel);

            if (validationResult.IsValid)
            {
                foreach (var config in mappedConfigs)
                {
                    var instance = await configRepository.GetAsync(config.Value.GetType(), new ConfigurationIdentity { ClientId = clientid });

                    instance.SetConfiguration(config.Value);
                    await configRepository.UpdateConfigAsync(instance);
                }
                responseFactory.BuildNoContentResponse(context);
            }
            else
            {
                responseFactory.BuildStatusResponse(context, 422);
            }
        }