예제 #1
0
        public async Task <ValidateResult> Validate(XElement securityElement, Dictionary <string, object> actionKeyInfo)
        {
            //获取节点下的子节点
            var childElements = securityElement.Elements();

            var strErrorReason = new StringBuilder();

            foreach (var childItem in childElements)
            {
                var elementValidate       = _selector.Choose(childItem.Name.ToString());
                var elementValidateResult = await elementValidate.Validate(childItem, actionKeyInfo);

                if (elementValidateResult.Result)
                {
                    return(elementValidateResult);
                }
                else
                {
                    if (!string.IsNullOrEmpty(elementValidateResult.Description))
                    {
                        strErrorReason.AppendLine(elementValidateResult.Description);
                        strErrorReason.AppendLine("\r");
                    }
                }
            }

            return(new ValidateResult {
                Result = false, Description = strErrorReason.ToString()
            });
        }
예제 #2
0
        /// <summary>
        /// 选择性翻译(选择合适的复数形式进行翻译)
        /// </summary>
        /// <param name="key">键</param>
        /// <param name="number">值</param>
        /// <param name="locale">语言</param>
        /// <param name="replace">替换的内容</param>
        /// <returns>翻译的值</returns>
        private string Choice(string key, int number, string locale, string[] replace)
        {
            if (string.IsNullOrEmpty(locale))
            {
                return(null);
            }

            var line = GetLine(key, locale, replace);

            if (line == null)
            {
                return(null);
            }

            var newReplace = new string[replace.Length + 2];

            Array.Copy(replace, newReplace, replace.Length);
            newReplace[replace.Length]     = "count";
            newReplace[replace.Length + 1] = number.ToString();

            if (selector != null)
            {
                line = selector.Choose(line, number, locale);
            }
            return(MakeReplacements(line, newReplace));
        }
예제 #3
0
        public async Task <ValidateResult> Validate(BusinessAction action, Dictionary <string, object> originalParameters)
        {
            //获取参数信息过滤器
            var filter = _originalParametersFilterServiceSelector.Choose(action.OriginalParametersFilterType);

            Dictionary <string, object> parameters = null;

            if (filter != null)
            {
                //获取过滤后的参数信息
                parameters = await filter.Execute(originalParameters);
            }



            //获取规则信息,转成xml
            var doc = XDocument.Parse(action.Rule);


            var result = await _conditionService.Validate(doc, parameters);

            //如果需要替换
            if (!result.Result && !string.IsNullOrEmpty(action.ErrorReplaceText))
            {
                LoggerHelper.LogInformation(_informationCategory, $"BusinessAction {action.Name} validate fail,detail:{result.Description}");

                var             lcId            = ContextContainer.GetValue <int>(ContextTypes.CurrentUserLcid);
                TemplateContext templateContext = new TemplateContext(lcId, parameters);
                result.Description = await _templateService.Convert(action.ErrorReplaceText, templateContext);
            }

            return(result);
        }
예제 #4
0
        protected string Choice(string key, int number, string[] replace)
        {
            string locale = this.locale;
            string line   = Get(locale, key, replace);

            if (line == null)
            {
                line   = Get(fallback, key, replace);
                locale = fallback;
            }

            replace = new string[] { "count", number.ToString() };

            return(MakeReplacements(selector.Choose(line, number, locale), replace));
        }
예제 #5
0
        public async Task <ValidateResult> Validate(XDocument doc, Dictionary <string, object> parameters)
        {
            var childElements = doc.Root.Elements();

            foreach (var childItem in childElements)
            {
                var elementValidate       = _validateElementServiceSelector.Choose(childItem.Name.ToString());
                var elementValidateResult = await elementValidate.Validate(childItem, parameters);

                if (!elementValidateResult.Result)
                {
                    return(elementValidateResult);
                }
            }

            return(new ValidateResult {
                Result = true, Description = string.Empty
            });
        }
예제 #6
0
        public async Task <ValidateResult> Validate(XElement securityElement, Dictionary <string, object> actionKeyInfo)
        {
            //获取节点下的子节点
            var childElements = securityElement.Elements();

            foreach (var childItem in childElements)
            {
                var elementValidate = _selector.Choose(childItem.Name.ToString());

                var elementValidateResult = await elementValidate.Validate(childItem, actionKeyInfo);

                if (!elementValidateResult.Result)
                {
                    return(elementValidateResult);
                }
            }

            return(new ValidateResult {
                Result = true, Description = string.Empty
            });
        }