Example #1
0
        /// <summary>
        /// 设置分组Helper
        /// </summary>
        /// <param name="jsonSettingHelper"></param>
        public void SetGroupHelper(JsonSettingHelper jsonSettingHelper)
        {
            if (!jsonFile.Equals(jsonSettingHelper.jsonFile))
            {
                throw new NotSupportedException("cant set group with different json file");
            }
            cacheJsonTime = (cacheJsonTime > jsonSettingHelper.cacheJsonTime)
                ? cacheJsonTime
                : jsonSettingHelper.cacheJsonTime;
            cacheJsonHelper = (cacheJsonTime > jsonSettingHelper.cacheJsonTime)
                ? cacheJsonHelper
                : jsonSettingHelper.cacheJsonHelper;

            if (jsonPropertyName.Equals(jsonSettingHelper.jsonPropertyName))
            {
                //分组路径相同,直接合并
                cacheSettingDictionary = cacheSettingDictionary.Concat(jsonSettingHelper.cacheSettingDictionary)
                                         .GroupBy(d => d.Key)
                                         .ToDictionary(kv => kv.Key, kv => kv.First().Value);
            }
            else
            {
                //直接将Map设置到公用的JsonHelper里
                cacheJsonHelper.ConcatNotNestedMap(jsonSettingHelper.cacheSettingDictionary, jsonSettingHelper.jsonPropertyName);
                cacheSettingDictionary = cacheJsonHelper.ConvertNotNestedMap(jsonPropertyName);
            }
        }
Example #2
0
        /// <summary>
        /// 保存到文件
        /// Dictionary -> JObject -> File
        /// </summary>
        public void Apply()
        {
            string jsonText;

            //保存JSON
            thisLock.EnterReadLock();
            {
                cacheJsonHelper.ConcatNotNestedMap(cacheSettingDictionary, jsonPropertyName);
                jsonText = cacheJsonHelper.Convert <string>();
            }
            thisLock.ExitReadLock();

            StreamWriter sw = new StreamWriter(jsonFile);

            sw.Write(jsonText);
            sw.Close();
        }