Esempio n. 1
0
        private void ReadYaml(string rawYaml)
        {
            using (var reader = new StringReader(rawYaml))
            {
                YamlStream yaml = new YamlStream();
                yaml.Load(reader);

                //reading overall configurations
                var regexConfigNode = (YamlMappingNode)yaml.Documents[0].RootNode;
                var regexConfig     = regexConfigNode.Children.ToDictionary(entry => ((YamlScalarNode)entry.Key).Value, entry => entry.Value);

                //user agents regex
                var uaParserConfigs = (YamlSequenceNode)regexConfig["user_agent_parsers"];
                uaParserConfigs.ThrowIfNull("user_agent_parsers is missing from yaml");
                List <UserAgentPattern> userAgentPatterns = uaParserConfigs.ConvertToDictionaryList().Select(configMap => YamlParsing.UserAgentPatternFromMap(configMap)).ToList();
                m_userAgentParser = new UserAgentParser(userAgentPatterns);

                // operating system regex
                var osParserConfigs = (YamlSequenceNode)regexConfig["os_parsers"];
                osParserConfigs.ThrowIfNull("os_parsers is missing from yaml");
                List <OSPattern> osPatterns = osParserConfigs.ConvertToDictionaryList().Select(configMap => YamlParsing.OSPatternFromMap(configMap)).ToList();
                m_osParser = new OSParser(osPatterns);

                // device parser setup
                var deviceParserConfigs = (YamlSequenceNode)regexConfig["device_parsers"];
                deviceParserConfigs.ThrowIfNull("device_parsers is missing from yaml");
                List <DevicePattern> devicePatterns = deviceParserConfigs.ConvertToDictionaryList().Select(configMap => YamlParsing.DevicePatternFromMap(configMap)).ToList();
                m_deviceParser = new DeviceParser(devicePatterns, m_userAgentParser);
            }
        }
Esempio n. 2
0
 public DeviceParser(List <DevicePattern> patterns, UserAgentParser uaParser)
 {
     m_patterns        = patterns;
     m_userAgentParser = uaParser;
 }