Пример #1
0
        /// <summary>
        /// 计算表达式字典
        /// </summary>
        /// <param name="strFuncName"></param>
        /// <param name="arrParams"></param>
        /// <param name="calcContext"></param>
        /// <returns></returns>
        private static object CalculateExpressionDictionary(string strFuncName, ParamObjectCollection arrParams, CalculateContext calcContext)
        {
            ExpressionDictionaryCollection dictionaries = (ExpressionDictionaryCollection)ObjectContextCache.Instance.GetOrAddNewValue(
                "ExpressionDictionaries",
                (cache, key) =>
            {
                ExpressionDictionaryCollection expDicts = new ExpressionDictionaryCollection();

                expDicts.InitFromConfiguration(ExpressionDictionarySettings.GetConfig());

                cache.Add("ExpressionDictionaries", expDicts);

                return(expDicts);
            });

            ExpressionDictionary dictionary = dictionaries[strFuncName];

            object oValue = null;

            if (dictionary != null)
            {
                ExpressionDictionaryCalculatorContext context = new ExpressionDictionaryCalculatorContext(dictionary, calcContext.CallerContxt);

                string key = string.Empty;

                if (arrParams.Count > 0 && arrParams[0].Value != null)
                {
                    key = arrParams[0].Value.ToString();
                }

                oValue = dictionary.Calculator.Calculate(strFuncName, key, context);
            }

            return(oValue);
        }
Пример #2
0
        public object Calculate(string dictionaryName, string key, ExpressionDictionaryCalculatorContext context)
        {
            object oValue = null;

            _UserInfoDictionary.TryGetValue(key, out oValue);

            return oValue;
        }
Пример #3
0
        /// <summary>
        /// 计算表达式字典
        /// </summary>
        /// <param name="strFuncName"></param>
        /// <param name="arrParams"></param>
        /// <param name="calcContext"></param>
        /// <returns></returns>
        private static object CalculateExpressionDictionary(string strFuncName, ParamObjectCollection arrParams, CalculateContext calcContext)
        {
            ExpressionDictionaryCollection dictionaries = (ExpressionDictionaryCollection)ObjectContextCache.Instance.GetOrAddNewValue(
                "ExpressionDictionaries",
                (cache, key) =>
                {
                    ExpressionDictionaryCollection expDicts = new ExpressionDictionaryCollection();

                    expDicts.InitFromConfiguration(ExpressionDictionarySettings.GetConfig());

                    cache.Add("ExpressionDictionaries", expDicts);

                    return expDicts;
                });

            ExpressionDictionary dictionary = dictionaries[strFuncName];

            object oValue = null;

            if (dictionary != null)
            {
                ExpressionDictionaryCalculatorContext context = new ExpressionDictionaryCalculatorContext(dictionary, calcContext.CallerContxt);

                string key = string.Empty;

                if (arrParams.Count > 0 && arrParams[0].Value != null)
                    key = arrParams[0].Value.ToString();

                oValue = dictionary.Calculator.Calculate(strFuncName, key, context);
            }

            return oValue;
        }