Esempio n. 1
0
        /// <summary>
        /// Creates the configuration asynchronous.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <string> CreateConfigAsync(ConfigReadModel model)
        {
            EnsureArg.IsNotNull(model);
            EnsureArg.IsNotEmptyOrWhiteSpace(model.Block);
            EnsureArg.IsNotEmptyOrWhiteSpace(model.Module);

            return(await _service.CreateConfigTomlAsync(model));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the configuration toml asynchronous.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <string> CreateConfigTomlAsync(ConfigReadModel model, bool enableHidden = false)
        {
            _config.EnableHidden = enableHidden;
            string contents = GenerateToml(model.Version, ValueScheme.UnQuoted);

            contents += GenerateToml(model.Module, ValueScheme.UnQuoted) + Environment.NewLine;
            contents += Environment.NewLine + GenerateToml(model.Block, ValueScheme.Quoted);

            return(await Task.FromResult(contents));
        }
Esempio n. 3
0
        /// <summary>
        /// Creates from HTML asynchronous.
        /// </summary>
        /// <param name="htmlFile">The HTML file.</param>
        /// <param name="values">The values.</param>
        /// <returns></returns>
        public async Task <string> CreateFromHtmlAsync(IFormFile htmlFile, IEnumerable <ModuleReadModel> values)
        {
            var module = new { module = values };
            var model  = new ConfigReadModel {
                Module = JsonConvert.SerializeObject(module), Block = "{}", Version = "{}"
            };
            var Toml = new ConfigTOML
            {
                BaseToml = await _service.CreateConfigTomlAsync(model, true),
                ViewToml = string.Empty
            };

            var html = FileReaderExtensions.ReadAsString(htmlFile);

            return(await _service.CreateFromHtmlAsync(html, Toml));
        }
Esempio n. 4
0
        public async Task <IActionResult> CreateTomlConfig([FromBody] ConfigReadModel json)
        {
            var result = await _manager.CreateConfigAsync(json);

            return(Ok(result));
        }