Ejemplo n.º 1
0
        private IResponseDetails ProcessGetCommand(IRequestDetails requestDetails, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Get configuration");

            var requestDefinitionWriter = _requestDefinitionWriteProvider.GetWriter();

            var definitionSets   = _requestDefinitionProvider.GetDefinitionSets();
            var fisrstDefinition = definitionSets.FirstOrDefault();

            if (fisrstDefinition == null)
            {
                return(ResponseDetailsFactory.Status404NotFound());
            }

            var configurationDefinition = ConfigurationDefinitionConverter.ToConfigurationDefinition(fisrstDefinition);

            if (!ConfigurationDefinitionExtensions.HasData(ref configurationDefinition))
            {
                return(ResponseDetailsFactory.Status400BadRequest());
            }

            var content = requestDefinitionWriter.Write(ref configurationDefinition);

            if (content == null)
            {
                return(ResponseDetailsFactory.Status400BadRequest());
            }

            return(ResponseDetailsFactory.Status200OK(content));
        }
    public static RequestDefinitionItemSet?ToDefinitionSet(ref ConfigurationDefinition configurationDefinition)
    {
        if (!ConfigurationDefinitionExtensions.HasData(ref configurationDefinition))
        {
            return(null);
        }

        var items = configurationDefinition.Map !.Select(ToRequestDefinition);

        return(new RequestDefinitionItemSet(
                   configurationDefinition.Info,
                   items.ToArray()
                   ));
    }
Ejemplo n.º 3
0
        public async Task <IResponseDetails> Execute(IRequestDetails requestDetails, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Set configuration");

            cancellationToken.ThrowIfCancellationRequested();

            if (_httpContextAccessor.HttpContext == null)
            {
                return(ResponseDetailsFactory.Status400BadRequest());
            }

            var requestDefinitionReader = _requestDefinitionReaderProvider.GetReader();

            var configurationDefinition = await requestDefinitionReader.Read(_httpContextAccessor.HttpContext.Request.Body);

            if (!ConfigurationDefinitionExtensions.HasData(ref configurationDefinition))
            {
                return(ResponseDetailsFactory.Status404NotFound());
            }

            var requestDefinitions = ConfigurationDefinitionConverter.ToDefinitionSet(ref configurationDefinition);

            if (requestDefinitions == null)
            {
                return(ResponseDetailsFactory.Status404NotFound());
            }

            cancellationToken.ThrowIfCancellationRequested();

            _logger.LogInformation($"Setup configuration: {requestDefinitions.DefinitionItems.Count()} items");

            _requestDefinitionStorage.AddSet(requestDefinitions);

            _requestHistoryStorage.Clear();

            return(ResponseDetailsFactory.Status202Accepted());
        }