Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取分组Helper
        /// </summary>
        /// <param name="groupJsonPropertyName">缓存名称(Json相对属性)/绝对名称(Json绝对属性)</param>
        /// <returns></returns>
        public JsonSettingHelper GetGroupHelper(string groupJsonPropertyName)
        {
            groupJsonPropertyName = GetJsonPropertyName(groupJsonPropertyName);
            // 分组 JsonSettingHelper 共享一个 JsonFile、JsonTime、JsonHelper
            var helper = new JsonSettingHelper
            {
                thisLock        = new ReaderWriterLockSlim(),
                jsonFile        = jsonFile,
                cacheJsonTime   = cacheJsonTime,
                cacheJsonHelper = cacheJsonHelper,

                jsonPropertyName       = groupJsonPropertyName,
                cacheSettingDictionary = cacheJsonHelper.ConvertNotNestedMap(groupJsonPropertyName)
            };

            return(helper);
        }