Beispiel #1
0
        private bool CheckIsDictRule(ref RuleInfo info)
        {
            bool   isOk = true;
            string rule = info._rule;

            info._isKey   = rule.StartsWith(KEY, StringComparison.OrdinalIgnoreCase);
            info._isValue = rule.StartsWith(VALUE, StringComparison.OrdinalIgnoreCase);
            bool isDict = _define.IsContainer && _define.OriginalType == Setting.DICT;

            if (!isDict && info.IsDict)
            {
                isOk = info._isKey = info._isValue = false;
                Warning("基本规则:非dict类型数据,使用key|value无法正常检查");
            }
            else
            {
                if (info._isKey)
                {
                    rule = rule.Substring(KEY.Length);
                }
                if (info._isValue)
                {
                    rule = rule.Substring(VALUE.Length);
                }
                if (rule.StartsWith(":"))
                {
                    rule = rule.Substring(1);
                }
                info._rule = rule;
            }
            return(isOk);
        }
Beispiel #2
0
        private bool Check(Data data, RuleInfo file)
        {
            string relativePath = file._rule.Replace("*", data.ToString());
            Uri    uri          = new Uri($"{Setting.ApplicationDir}\\{relativePath}");
            string path         = uri.LocalPath;

            if (File.Exists(path))
            {
                return(true);
            }
            return(false);
        }
Beispiel #3
0
        public override bool VerifyRule()
        {
            bool isOk = base.VerifyRule();

            if (_rules.IsEmpty() || _ruleTable.Length == 0)
            {
                Warning($"File检查规则:未填写内容!");
                isOk = false;
            }
            if (_define.IsRaw && _define.OriginalType != Setting.STRING)
            {
                Warning($"File检查规则:基础类型数据类型仅支持string类型");
                isOk = false;
            }
            for (int i = 0; i < _ruleTable.Length; i++)
            {
                RuleInfo info = _ruleTable[i];
                string   rule = info._rule;
                if (rule.IsEmpty())
                {
                    Warning($"File检查规则:表达式为空");
                    isOk = false;
                }
                switch (_define.OriginalType)
                {
                case Setting.LIST:
                    if (_define.GetItemDefine().FullName != Setting.STRING)
                    {
                        Warning($"File检查规则:list中数据类型仅支持string类型");
                        isOk = false;
                    }
                    break;

                case Setting.DICT:
                    if (info._isKey && _define.GetKeyDefine().FullName != Setting.STRING)
                    {
                        Warning($"File检查规则:dict.key数据类型仅支持string类型");
                        isOk = false;
                    }
                    else if (info._isValue && _define.GetValueDefine().FullName != Setting.STRING)
                    {
                        Warning($"File检查规则:dict.value数据类型仅支持string类型");
                        isOk = false;
                    }
                    break;
                }
            }
            return(isOk);
        }
Beispiel #4
0
 public Checker(FieldWrap define, string rules)
 {
     _define = define;
     _rules  = rules;
     string[] nodes = rules.Split(Setting.CheckSplit, System.StringSplitOptions.RemoveEmptyEntries);
     _ruleTable = new RuleInfo[nodes.Length];
     for (int i = 0; i < nodes.Length; i++)
     {
         _ruleTable[i] = new RuleInfo()
         {
             _rule = nodes[i]
         }
     }
     ;
 }
Beispiel #5
0
        // 检查集合中文件路径是否存在
        private bool Check(FList data)
        {
            bool isOk = true;
            var  list = (data as FList).Values;

            for (int k = 0; k < list.Count; k++)
            {
                bool flag = false;
                for (int i = 0; i < _ruleTable.Length; i++)
                {
                    RuleInfo info = _ruleTable[i];
                    flag |= Check(list[k], info);
                }
                isOk &= flag;
            }
            return(isOk);
        }
Beispiel #6
0
        private bool Check(FDict data, RefRule rule, RuleInfo info)
        {
            bool isOk = true;
            var  dict = data.Values;

            foreach (var item in dict)
            {
                if (info._isKey)
                {
                    isOk &= Check(item.Key, rule);
                }
                if (info._isValue)
                {
                    isOk &= Check(item.Value, rule);
                }
            }
            return(isOk);
        }
Beispiel #7
0
        // 检查集合中文件路径是否存在
        // key|Value均可作该检查
        private bool Check(FDict data)
        {
            bool isOk = true;
            var  dict = (data as FDict).Values;

            foreach (var item in dict)
            {
                bool flagk    = false;
                bool flagv    = false;
                bool hasKey   = false;
                bool hasValue = false;
                for (int i = 0; i < _ruleTable.Length; i++)
                {
                    RuleInfo info = _ruleTable[i];
                    if (info._isKey)
                    {
                        flagk  |= Check(item.Key, info);
                        hasKey |= true;
                    }
                    else if (info._isValue)
                    {
                        flagv    |= Check(item.Value, info);
                        hasValue |= true;
                    }
                }
                if (hasKey && hasValue)
                {
                    isOk &= flagk && flagv;
                }
                else if (hasKey && !hasValue)
                {
                    isOk &= flagk;
                }
                else if (!hasKey && hasValue)
                {
                    isOk &= flagv;
                }
                else
                {
                    Error("File检查规则:程序Bug,未检查出规则配置错误!");
                }
            }
            return(isOk);
        }
Beispiel #8
0
        private bool SwitchData(Data data, string type, RangeRule range, RuleInfo info)
        {
            bool isOk = true;

            switch (type)
            {
            case Setting.INT:
                isOk &= Check((data as FInt).Value, range);
                break;

            case Setting.LONG:
                isOk &= Check((data as FLong).Value, range);
                break;

            case Setting.FLOAT:
                isOk &= Check((data as FFloat).Value, range);
                break;
            }
            return(isOk);
        }
Beispiel #9
0
        public override bool VerifyData(Data data)
        {
            bool isOk   = false;
            var  define = data.Define;

            if (define.OriginalType == Setting.DICT)
            {
                isOk |= Check(data as FDict);
            }
            else if (define.OriginalType == Setting.LIST)
            {
                isOk |= Check(data as FList);
            }
            else
            {
                for (int i = 0; i < _ruleTable.Length; i++)
                {
                    RuleInfo info = _ruleTable[i];
                    isOk |= Check(data, info);
                }
            }
            return(isOk);
        }
Beispiel #10
0
        public override bool VerifyRule()
        {
            bool isOk = base.VerifyRule();

            if (_define.IsRaw || _define.IsEnum)
            {//.是一个最外层的基础类型字段,检查整列数据.
                if (!_define.Host.IsConfig())
                {
                    Warning($"Unique检查规则:仅支持目标表结构最外层基础类型字段数据!");
                    isOk = false;
                }
            }
            else if (_define.IsContainer)
            { //.是一个集合结构,直接检查结构内部数据
                if (_define.OriginalType == Setting.LIST &&
                    _define.GetItemDefine().IsClass)
                {
                    Warning($"Unique检查规则:由于多态的复杂性,不支持list中数据类型为Class!仅支持基础类型.");
                    isOk = false;
                }
                else if (_define.OriginalType == Setting.DICT && _ruleTable.Length != 0 &&
                         _define.GetValueDefine().IsClass)//_ruleTable.Length != 0 表示需要检查dict.value
                {
                    for (int i = 0; i < _ruleTable.Length; i++)
                    {
                        RuleInfo info = _ruleTable[i];
                        if (info._isValue)
                        {
                            Warning($"Unique检查规则:由于多态的复杂性,不支持dict.value数据类型为Class!仅支持基础类型.");
                        }
                    }
                    isOk = false;
                }
            }
            return(isOk);
        }
Beispiel #11
0
        public override bool VerifyRule()
        {
            bool isOk = base.VerifyRule();

            if (_define.IsRaw && !HASH.Contains(_define.OriginalType))
            {
                Warning($"Range检查规则:基础类型数据类型仅支持int,long,float类型!当前类型:{_define.OriginalType}");
                isOk = false;
            }
            _ranges = new RangeRule[_ruleTable.Length];
            for (int i = 0; i < _ruleTable.Length; i++)
            {
                RuleInfo info = _ruleTable[i];
                string   rule = info._rule;
                if (rule.IsEmpty())
                {
                    Warning($"Range检查规则:表达式为空");
                    isOk = false;
                }


                if (rule.Length < 5 || rule.IsEmpty())
                {
                    Warning($"Range检查规则:表达式长度必定大于等于5,而当前长度为{rule.Length}!");
                    isOk = false;
                }

                char left  = rule[0];
                char right = rule[rule.Length - 1];
                if (!(left == LEFT_FULL || left == LEFT_HALF || left == NEGATIVE) &&
                    (right == RIGHT_FULL || right == RIGHT_HALF || right == POSITIVE))
                {
                    Warning("Range检查规则:支持区间标识符错误(),[],(],[)!");
                    isOk = false;
                }

                RangeRule range = new RangeRule();
                switch (right)
                {
                case RIGHT_FULL: range._rightState = true; break;

                case RIGHT_HALF: range._rightState = false; break;
                }
                switch (left)
                {
                case LEFT_FULL: range._leftState = true; break;

                case LEFT_HALF: range._leftState = false; break;
                }

                string   content = rule.Trim(ARRAY);
                string[] nodes   = content.Split(new char[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
                if (nodes.Length != 2)
                {
                    Warning("Range检查规则:范围参数漏填!");
                    isOk = false;
                }

                switch (_define.OriginalType)
                {
                case Setting.INT:
                case Setting.LONG:
                case Setting.FLOAT:
                    isOk = PaserLeftRight(nodes, _define.OriginalType, ref range);
                    break;

                case Setting.LIST:
                    var item = _define.GetItemDefine();
                    if (!HASH.Contains(item.OriginalType))
                    {
                        Warning($"Range检查规则:list中数据类型仅支持int,long,float类型");
                        isOk = false;
                    }
                    else
                    {
                        isOk = PaserLeftRight(nodes, item.OriginalType, ref range);
                    }
                    break;

                case Setting.DICT:
                    if (info._isKey)
                    {
                        var key = _define.GetKeyDefine();
                        if (!HASH.Contains(key.FullName))
                        {
                            Warning($"Range检查规则:dict.key数据类型仅支持int,long,float类型");
                            isOk = false;
                        }
                        else
                        {
                            isOk = PaserLeftRight(nodes, key.FullName, ref range);
                        }
                    }
                    else if (info._isValue)
                    {
                        var value = _define.GetValueDefine();
                        if (!HASH.Contains(value.FullName))
                        {
                            Warning($"Range检查规则:dict.value数据类型仅支持int,long,float类型");
                            isOk = false;
                        }
                        else
                        {
                            isOk = PaserLeftRight(nodes, value.FullName, ref range);
                        }
                    }
                    break;
                }
                _ranges[i] = range;
            }
            return(isOk);
        }
Beispiel #12
0
        public override bool VerifyRule()
        {
            bool isOk = base.VerifyRule();

            _refs = new RefRule[_ruleTable.Length];
            for (int i = 0; i < _ruleTable.Length; i++)
            {
                RuleInfo info = _ruleTable[i];
                string   rule = info._rule;
                if (rule.IsEmpty())
                {
                    Warning($"Ref检查规则:表达式为空");
                    isOk = false;
                }
                else
                {
                    string[] nodes = rule.Split(Setting.DotSplit, System.StringSplitOptions.RemoveEmptyEntries);
                    if (nodes.Length == 3)
                    {
                        RefRule refr       = new RefRule();
                        string  targetName = $"{nodes[0]}.{nodes[1]}";
                        if (!ConfigWrap.IsConfig(targetName))
                        {
                            Warning($"Ref检查规则:目标{targetName}配置表无法获取!");
                            isOk = false;
                        }
                        refr._target      = ConfigWrap.Get(targetName);
                        refr._targetField = nodes[2];
                        if (refr._target == null)
                        {
                            Warning("Ref检查规则:仅支持引用表结构最外层基础类型字段数据");
                            isOk = false;
                        }
                        else
                        {
                            var targetCls = ClassWrap.Get(targetName);
                            var define    = targetCls.Fields.Find(field => field.Name == refr._targetField);
                            if (define.IsContainer)
                            {
                                if (define.OriginalType == Setting.LIST &&
                                    define.GetItemDefine().IsClass)
                                {
                                    Warning($"Ref检查规则:由于多态的复杂性,不支持list中数据类型为Class!仅支持基础类型.");
                                    isOk = false;
                                }
                                else if (define.OriginalType == Setting.DICT &&
                                         define.GetValueDefine().IsClass)
                                {
                                    Warning($"Ref检查规则:由于多态的复杂性,不支持dict.value数据类型为Class!仅支持基础类型.");
                                    isOk = false;
                                }
                            }
                            else if (define.IsEnum || define.IsRaw)
                            {
                            }
                            else
                            {
                                Warning($"Ref检查规则:由于多态的复杂性,不支持数据类型为Class!仅支持基础类型.");
                                isOk = false;
                            }
                        }
                        _refs[i] = refr;
                    }
                    else
                    {
                        Warning($"Ref检查规则:格式错误,正确格式[Namespace.Class.Field]");
                        isOk = false;
                    }
                }
            }
            return(isOk);
        }