Esempio n. 1
0
        public static OSParser FromList(List <Dictionary <String, String> > configList)
        {
            List <OSPattern> configPatterns = new List <OSPattern>();

            foreach (Dictionary <String, String> configMap in configList)
            {
                configPatterns.Add(OSParser.PatternFromMap(configMap));
            }
            return(new OSParser(configPatterns));
        }
Esempio n. 2
0
        private void Initialize(Stream regexYaml)
        {
            TextReader input = new StreamReader(regexYaml);
            YamlStream yaml  = new YamlStream();

            yaml.Load(input);

            var regexConfigNode = (YamlMappingNode)yaml.Documents[0].RootNode;
            var regexConfig     = new Dictionary <String, YamlNode>();

            foreach (var entry in regexConfigNode.Children)
            {
                regexConfig.Add(((YamlScalarNode)entry.Key).Value, entry.Value);
            }

            var uaParserConfigs = (YamlSequenceNode)regexConfig["user_agent_parsers"];

            if (uaParserConfigs == null)
            {
                throw new ArgumentException("user_agent_parsers is missing from yaml");
            }
            uaParser = UserAgentParser.FromList(uaParserConfigs.ToListOfDictionaries());


            var osParserConfigs = (YamlSequenceNode)regexConfig["os_parsers"];

            if (osParserConfigs == null)
            {
                throw new ArgumentException("os_parsers is missing from yaml");
            }
            osParser = OSParser.FromList(osParserConfigs.ToListOfDictionaries());

            var deviceParserConfigs = (YamlSequenceNode)regexConfig["device_parsers"];

            if (deviceParserConfigs == null)
            {
                throw new ArgumentException("device_parsers is missing from yaml");
            }

            var mobileUAFamiliesList = (YamlSequenceNode)regexConfig["mobile_user_agent_families"];
            var mobileOSFamiliesList = (YamlSequenceNode)regexConfig["mobile_os_families"];

            List <String> mobileUAFamilies = (new List <String>(mobileUAFamiliesList.Select(f => f.ToString())));
            List <String> mobileOSFamilies = (new List <String>(mobileOSFamiliesList.Select(f => f.ToString())));

            deviceParser = DeviceParser.FromList(deviceParserConfigs.ToListOfDictionaries(), uaParser, mobileUAFamilies, mobileOSFamilies);
        }