/// <summary>
        /// Parse result.
        /// </summary>
        /// <returns>Match.</returns>
        public override ParseResult <OsMatchResult> Parse()
        {
            var result  = new ParseResult <OsMatchResult>();
            Os  localOs = null;

            string[] localMatches = null;

            foreach (var os in this.RegexList)
            {
                var matches = this.MatchUserAgent(os.Regex);

                if (matches.Length > 0)
                {
                    localOs      = os;
                    localMatches = matches;
                    break;
                }
            }

            if (localMatches != null)
            {
                var name   = this.BuildByMatch(localOs.Name, localMatches);
                var @short = UnknownShort;

                foreach (var operatingSystem in operatingSystems)
                {
                    if (operatingSystem.Value.ToLower().Equals(name.ToLower()))
                    {
                        name   = operatingSystem.Value;
                        @short = operatingSystem.Key;
                    }
                }

                var os = new OsMatchResult
                {
                    Name      = name,
                    ShortName = @short,
                    Version   = this.BuildVersion(localOs.Version, localMatches),
                    Platform  = this.ParsePlatform(),
                };

                if (operatingSystems.ContainsKey(name))
                {
                    os.ShortName = operatingSystems.Keys.FirstOrDefault(o => o.Equals(name));
                }

                if (operatingSystems.ContainsValue(name))
                {
                    os.Name = operatingSystems.Values.FirstOrDefault(o => o.Equals(name));
                }

                result.Add(os);
            }

            return(result);
        }
예제 #2
0
        public ParseResult <OsMatchResult> Parse(bool simple)
        {
            var result  = new ParseResult <OsMatchResult>();
            Os  localOs = null;

            string[] localMatches = null;

            foreach (var os in regexList)
            {
                if (!simple)
                {
                    var matches = MatchUserAgent(os.CompiledRegex);
                    if (matches.Length > 0)
                    {
                        localOs      = os;
                        localMatches = matches;
                        break;
                    }
                }
                else
                {
                    bool matched = IsMatchUserAgent(os.CompiledRegex);
                    if (matched)
                    {
                        localOs      = os;
                        localMatches = SimpleMatches;
                        break;
                    }
                }
            }

            if (localMatches != null)
            {
                var name   = simple ? localOs.Name : BuildByMatch(localOs.Name, localMatches);
                var @short = UnknownShort;
                foreach (var operatingSystem in OperatingSystems)
                {
                    if (operatingSystem.Value.ToLower().Equals(name.ToLower()))
                    {
                        name   = operatingSystem.Value;
                        @short = operatingSystem.Key;
                    }
                }
                var os = new OsMatchResult
                {
                    Name      = name,
                    ShortName = @short,
                    Version   = simple ? string.Empty : BuildVersion(localOs.Version, localMatches),
                    Platform  = ParsePlatform()
                };

                if (OperatingSystems.ContainsKey(name))
                {
                    os.ShortName = name;
                }
                if (simple)
                {
                    os.Name = os.ShortName;
                }
                else if (OperatingSystems.ContainsValue(name))
                {
                    os.Name = OperatingSystems.Values.FirstOrDefault(o => o.Equals(name));
                }

                result.Add(os);
            }
            return(result);
        }