private void ReadJson(Stream stream, string baseKey)
        {
            var newData = JsonConfigurationFileParser.Parse(stream).ToDictionary(
                kv => $"{baseKey}{ConfigurationPath.KeyDelimiter}{kv.Key}",
                kv => kv.Value);

            foreach (var kv in newData)
            {
                Data[kv.Key] = kv.Value;
            }
        }
Exemplo n.º 2
0
        internal static IEnumerable <KeyValuePair <string, string> > ConvertToConfig(
            this MsConfig kvPair,
            string rootKey)
        {
            return(JsonConfigurationFileParser.Parse(kvPair.Value).Select(pair =>
            {
                string key = $"{kvPair.Key}:{pair.Key}";

                return new KeyValuePair <string, string>(key, pair.Value);
            }));
        }
Exemplo n.º 3
0
                public static IDictionary <string, string> Parse(string input)
                {
                    var parser = new JsonConfigurationFileParser();

                    parser._reader = new JsonTextReader(new StringReader(input))
                    {
                        DateParseHandling = DateParseHandling.None
                    };
                    parser.VisitJObject(JObject.Load(parser._reader));
                    return(parser._data);
                }
        public override void Load()
        {
            var config = _configJsonProvider.Provide();

            if (config != null)
            {
                using (var mem = new MemoryStream(config))
                {
                    Data = JsonConfigurationFileParser.Parse(mem);
                }
            }
        }
    private void LoadData(QueryResult <KVPair> queryResult)
    {
        _currentIndex = queryResult.LastIndex;
        if (queryResult.Response == null ||
            queryResult.Response.Value == null ||
            !queryResult.Response.Value.Any())
        {
            return;
        }
        Stream stream = new MemoryStream(queryResult.Response.Value);

        Data = JsonConfigurationFileParser.Parse(stream);
    }
Exemplo n.º 6
0
        public IActionResult PreViewJsonFile()
        {
            List <IFormFile> files = Request.Form.Files.ToList();

            if (!files.Any())
            {
                return(Json(new
                {
                    success = false,
                    message = "请上传Json文件"
                }));
            }

            var jsonFile = files.First();

            using (var stream = jsonFile.OpenReadStream())
            {
                var dict = JsonConfigurationFileParser.Parse(stream);

                var addConfigs = new List <Config>();
                //judge if json key already in configs
                foreach (var key in dict.Keys)
                {
                    var newKey = key;
                    var group  = "";
                    var paths  = key.Split(":");
                    if (paths.Length > 1)
                    {
                        //如果是复杂key,取最后一个为真正的key,其他作为group
                        newKey = paths[paths.Length - 1];
                        group  = string.Join(":", paths.ToList().Take(paths.Length - 1));
                    }

                    var config = new Config();
                    config.Key         = newKey;
                    config.Description = "";
                    config.Value       = dict[key];
                    config.Group       = group;
                    config.Id          = Guid.NewGuid().ToString();
                    addConfigs.Add(config);
                }

                //var result = await _configService.AddRangeAsync(configs);

                return(Json(new
                {
                    success = true,
                    data = addConfigs
                }));
            }
        }
Exemplo n.º 7
0
        private static Dictionary <string, string> DeserializeJson(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase));
            }

            using (var stream = new MemoryStream())
            {
                var bytes = Encoding.UTF8.GetBytes(text);
                stream.Write(bytes, 0, bytes.Length);
                stream.Position = 0;

                // might throw FormatException if JSON is malformed.
                var data = JsonConfigurationFileParser.Parse(stream);

                return(new Dictionary <string, string>(data, StringComparer.OrdinalIgnoreCase));
            }
        }
 /// <summary>Loads the JSON data from a stream.</summary>
 /// <param name="stream">The stream to read.</param>
 public override void Load(Stream stream)
 {
     try
     {
         this.Data = JsonConfigurationFileParser.Parse(stream);
     }
     catch (JsonReaderException ex)
     {
         var str = string.Empty;
         if (stream.CanSeek)
         {
             stream.Seek(0L, SeekOrigin.Begin);
             using var streamReader = new StreamReader(stream);
             var fileContent = ReadLines(streamReader);
             str = RetrieveErrorContext(ex, fileContent);
         }
         throw new FormatException(
                   $"Could not parse the JSON file. Error on line number '{(object) ex.LineNumber}': '{(object) str}'", ex);
     }
 }
        public override void Load()
        {
            string value = Environment.GetEnvironmentVariable(_envVar);

            if (value == null)
            {
                if (_isOptional)
                {
                    value = "{}";
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }

            byte[] bytes = Encoding.UTF8.GetBytes(value);
            using (var stream = new MemoryStream(bytes))
            {
                Data = JsonConfigurationFileParser.Parse(stream);
            }
        }
Exemplo n.º 10
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            var redisString = _configuration.GetValue <string>("redis:configuration");
            var redisConfig = _configuration.GetSection("redis").Get <RedisConfig>();

            _configChangeTest.Test();
            ConfigContainer.Instance.Change(new ConfigChangeInfo {
                GroupCode = "common", Key = "redis", Value = "{configuration:\"110.240.225.136\"}"
            });

            _configChangeTest.Test();
            redisString = _configuration.GetValue <string>("redis:configuration");
            redisConfig = _configuration.GetSection("redis").Get <RedisConfig>();
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config/appsettings.json");

            using (var fs = File.OpenRead(path))
            {
                var data = JsonConfigurationFileParser.Parse(fs);
            }


            return(Task.CompletedTask);
        }