Пример #1
0
        public static IEnumerable <DhcpConfig.LineModel> AssignGlobal(string input)
        {
            var global        = new List <DhcpConfig.LineModel>();
            var globalStr     = "(?!range|prefix|zone|host|algor|secret)(^[^#{{}}\\s].*?;)";
            var globalRegex   = new Regex(globalStr, RegexOptions.Multiline);
            var globalMatches = globalRegex.Matches(input);

            for (var i = 0; i < globalMatches.Count; i++)
            {
                var split = globalMatches[i].Value.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                if (split.Length > 1)
                {
                    var k   = split[0].Trim();
                    var v   = split[1].Trim().Replace(";", "").Trim();
                    var ddd = new DhcpConfig.LineModel {
                        Key          = k,
                        Value        = v,
                        Type         = Helper.ServiceData.SupposeDataType(v),
                        BooleanVerbs = Helper.ServiceData.SupposeBooleanVerbs(v),
                        FilePath     = ""
                    };
                    global.Add(ddd);
                }
            }
            return(global);
        }
Пример #2
0
        public static IEnumerable <DhcpConfig.LineModel> AssignPrefix6(string input)
        {
            var prefix6        = new List <DhcpConfig.LineModel>();
            var prefix6Str     = $"prefix6[\\s\\w\\d\\-{{.:\"=/]*;";
            var prefix6Regex   = new Regex(prefix6Str);
            var prefix6Matches = prefix6Regex.Matches(input);

            for (var i = 0; i < prefix6Matches.Count; i++)
            {
                var v   = prefix6Matches[i].Value.Replace("\t", " ").Replace("prefix6 ", "").Trim();
                var ddd = new DhcpConfig.LineModel()
                {
                    Key          = "prefix6",
                    Value        = v,
                    Type         = Helper.ServiceData.SupposeDataType(v),
                    BooleanVerbs = Helper.ServiceData.SupposeBooleanVerbs(v),
                    FilePath     = ""
                };
                prefix6.Add(ddd);
            }
            return(prefix6);
        }
Пример #3
0
        public static IEnumerable <DhcpConfig.LineModel> AssignInclude(string input)
        {
            var include        = new List <DhcpConfig.LineModel>();
            var includeStr     = $"include[\\s\\w\\d\\-{{.:\"=/]*;";
            var includeRegex   = new Regex(includeStr);
            var includeMatches = includeRegex.Matches(input);

            for (var i = 0; i < includeMatches.Count; i++)
            {
                var v   = includeMatches[i].Value.Replace("\t", " ").Replace("include ", "").Trim();
                var ddd = new DhcpConfig.LineModel()
                {
                    Key          = "include",
                    Value        = v,
                    Type         = Helper.ServiceData.SupposeDataType(v),
                    BooleanVerbs = Helper.ServiceData.SupposeBooleanVerbs(v),
                    FilePath     = ""
                };
                include.Add(ddd);
            }
            return(include);
        }
Пример #4
0
        public static IEnumerable <DhcpConfig.OptionModel> AssignSubclass(string input)
        {
            var subclass        = new List <DhcpConfig.OptionModel>();
            var subclassStr     = $"[^\\S]subclass[\\s\\w\\d\\-{{.:;\"=/]*";
            var subclassRegex   = new Regex(subclassStr);
            var subclassMatches = subclassRegex.Matches(input);
            var data            = (subclassMatches.Count > 0) ? subclassMatches[0].Value : "";
            var dataList        = new List <DhcpConfig.LineModel>();

            if (data.Length > 0)
            {
                var txt = data.Replace("subclass {", "");
                var simpleDataMatches = new Regex($"(?!([a-zA-Z0-9\\s-\"/._*;]*}})|(;))[a-zA-Z0-9\\s-/._\"*]*[;]").Matches(txt);
                for (var i = 0; i < simpleDataMatches.Count; i++)
                {
                    var split = simpleDataMatches[i].Value.Replace("\t", " ").Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    if (split.Length > 1 && !split[0].StartsWith("//"))
                    {
                        var k   = split[0];
                        var v   = split[1].Replace(";", "").Replace("\"", "");
                        var ddd = new DhcpConfig.LineModel()
                        {
                            Key          = k,
                            Value        = v,
                            Type         = Helper.ServiceData.SupposeDataType(v),
                            BooleanVerbs = Helper.ServiceData.SupposeBooleanVerbs(v),
                            FilePath     = ""
                        };
                        dataList.Add(ddd);
                    }
                }
                var multipleDataMatches = new Regex($"[\\w\\d\\s-\"/._*]*{{[\\w\\d\\s-\"/._*;]*}};").Matches(txt);
                for (var i = 0; i < multipleDataMatches.Count; i++)
                {
                    var split = multipleDataMatches[i].Value.Replace("\t", " ").Trim().Split(new[] { " {" }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    if (split.Length > 1)
                    {
                        var k           = split[0];
                        var v           = split[1].Replace("};", "").Trim();
                        var splitValue  = v.Split(new[] { ";" }, StringSplitOptions.None).ToArray();
                        var splitValue2 = splitValue[0].Split(new[] { " " }, StringSplitOptions.None).ToArray();
                        var type        = (splitValue2.Length > 0) ? ServiceDataType.DataArray : ServiceDataType.StringArray;
                        var ddd         = new DhcpConfig.LineModel()
                        {
                            Key          = k,
                            Value        = v,
                            Type         = type,
                            BooleanVerbs = new KeyValuePair <string, string>(";", ";"),
                            FilePath     = ""
                        };
                        dataList.Add(ddd);
                    }
                }
            }
            var option = new DhcpConfig.OptionModel()
            {
                Name = "subclass",
                Data = dataList
            };

            subclass.Add(option);
            return(subclass);
        }