コード例 #1
0
        public override BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            List<Device> foundDevices = new List<Device>();
            foreach (string token in orderedRules.Keys)
            {
                Device d = ElaborateWinPhoneDeviceWithToken(userAgent, token);
                if (d != null)
                {
                    if (d.confidence > confidenceTreshold)
                    {
                        return d;

                    }
                    else
                    {
                        if (d.confidence > 0)
                        {
                            foundDevices.Add(d);
                        }
                    }
                }
            }
            if (foundDevices.Count > 0)
            {
                foundDevices.Sort();
                foundDevices.Reverse();
                return foundDevices[0];
            }
            return null;
        }
コード例 #2
0
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            OSModel.OperatingSystem model = new OSModel.OperatingSystem();
            model.majorRevision = "-";
            model.SetVendor("-");
            model.SetModel("Linux");

            int confidence = 60;

            if (descriptionRegex.IsMatch(userAgent.GetPatternElementsInside()))
            {
                Match descriptionMatcher = descriptionRegex.Match(userAgent.GetPatternElementsInside());
                GroupCollection groups = descriptionMatcher.Groups;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    confidence += 10;
                }
                if (groups[2] != null && groups[2].Value.Trim().Length > 0)
                {
                    model.SetDescription(groups[2].Value);
                    confidence += 10;
                }
            }

            model.confidence = confidence;

            return model;
        }
コード例 #3
0
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            List<OSModel.OperatingSystem> founds = new List<OSModel.OperatingSystem>();
            OSModel.OperatingSystem found = null;
            foreach (IBuilder builder in builders) {
                if (builder.CanBuild(userAgent)) {
                    OSModel.OperatingSystem builded = (OSModel.OperatingSystem) builder.Build(userAgent, confidenceTreshold);
                    if (builded != null) {
                        founds.Add(builded);
                        if (builded.confidence >= confidenceTreshold) {
                            found = builded;
                            break;
                        }
                    }
                }
            }

            if (found != null) {
                return found;

            } else {
                if (founds.Count > 0)
                {
                    founds.Sort();
                    founds.Reverse();
                    return founds[0];
                }

                return null;
            }
        }
コード例 #4
0
        public override BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            List<Device> foundDevices = new List<Device>();
            ICollection tokens = orderedRules.Keys;
            string userAgentWithoutAndroid = userAgent.completeUserAgent.Replace("Android", "");
            foreach (string token in tokens)
            {
                Device d = ElaborateAndroidDeviceWithToken(userAgent, token, userAgentWithoutAndroid);
                if (d != null)
                {
                    if (d.confidence > confidenceTreshold)
                    {
                        return d;
                    }
                    else
                    {
                        if (d.confidence > 0)
                        {
                            foundDevices.Add(d);
                        }
                    }
                }
            }

            if (foundDevices.Count > 0)
            {
                foundDevices.Sort();
                foundDevices.Reverse();
                return foundDevices[0];
            }
            return null;
        }
コード例 #5
0
 public override bool CanBuild(UserAgent userAgent)
 {
     if (netfrontRegex.IsMatch(userAgent.completeUserAgent) || userAgent.completeUserAgent.Contains("ACS-NF") || userAgent.completeUserAgent.Contains("NF-Browser"))
     {
         return true;
     }
     return false;
 }
コード例 #6
0
 public override bool CanBuild(UserAgent userAgent)
 {
     if (obigoTelecaRegex.IsMatch(userAgent.completeUserAgent))
     {
         return true;
     }
     return false;
 }
コード例 #7
0
 public bool CanBuild(UserAgent userAgent)
 {
     foreach (String token in simpleTokenMap.Keys)
     {
         Regex tokenRegex = new Regex(/*"(?i).*"*/".*" + Regex.Escape(token) + ".*", RegexOptions.IgnoreCase);
         if (tokenRegex.IsMatch(userAgent.completeUserAgent))
         {
             return true;
         }
     }
     return false;
 }
コード例 #8
0
        protected override Browser BuildBrowser(UserAgent userAgent, string layoutEngine, string layoutEngineVersion, int hintedWidth, int hintedHeight)
        {
            String version = null;

            if (!versionRegex.IsMatch(userAgent.completeUserAgent))
            {
                return null;

            }
            else
            {
                Match versionMatcher = versionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = versionMatcher.Groups;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    version = groups[1].Value;
                }
            }

            int confidence = 60;
            Browser identified = new Browser();

            identified.SetVendor("HP");
            identified.SetModel("Web OS Browser");
            identified.SetVersion(version);
            String[] versionEl = version.Split(".".ToCharArray());

            if (versionEl.Length > 0)
            {
                identified.majorRevision = versionEl[0];
            }

            if (versionEl.Length > 1)
            {
                identified.microRevision = versionEl[1];
                confidence += 10;
            }

            if (layoutEngine != null)
            {
                identified.SetLayoutEngine(layoutEngine);
                identified.SetLayoutEngineVersion(layoutEngineVersion);
            }

            identified.SetDisplayWidth(hintedWidth);
            identified.SetDisplayHeight(hintedHeight);
            identified.confidence = confidence;

            return identified;
        }
コード例 #9
0
 public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
 {
     foreach (string token in simpleTokenMap.Keys)
     {
         Regex tokenRegex = new Regex(/*"(?i).*"*/".*" + Regex.Escape(token) + ".*", RegexOptions.IgnoreCase);
         if (tokenRegex.IsMatch(userAgent.completeUserAgent) && simpleTokenMap.Contains(token))
         {
             String desktopDeviceId = (string)simpleTokenMap[token];
             Device device = null;
             if (devices.TryGetValue(desktopDeviceId, out device))
             {
                 return device;
             }
         }
     }
     return null;
 }
コード例 #10
0
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            OSModel.OperatingSystem model = new OSModel.OperatingSystem();

            model.SetVendor("Research In Motion");
            model.SetModel("Black Berry OS");
            model.majorRevision = "1";

            if (versionRegex.IsMatch(userAgent.completeUserAgent))
            {
                Match versionMatcher = versionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = versionMatcher.Groups;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    model.confidence = 50;
                    model.SetVersion(groups[1].Value);

                    if (groups[2] != null && groups[2].Value.Trim().Length > 0)
                    {
                        model.majorRevision = groups[2].Value;
                        model.confidence = 60;
                    }

                    if (groups[3] != null && groups[3].Value.Trim().Length > 0)
                    {
                        model.minorRevision = groups[3].Value;
                        model.confidence = 70;
                    }

                    if (groups[4] != null && groups[4].Value.Trim().Length > 0)
                    {
                        model.microRevision = groups[4].Value;
                        model.confidence = 80;
                    }

                    if (groups[5] != null && groups[5].Value.Trim().Length > 0)
                    {
                        model.nanoRevision = groups[5].Value;
                        model.confidence = 90;
                    }
                }
            }
            return model;
        }
コード例 #11
0
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            OSModel.OperatingSystem model = new OSModel.OperatingSystem();
            model.majorRevision = "1";
            model.SetVendor("Palm");
            model.SetModel("Web OS");
            model.confidence = 40;

            string patternElementsInside = userAgent.GetPatternElementsInside();
            String[] splittedTokens = patternElementsInside.Split(";".ToCharArray());

            foreach (String tokenElement in splittedTokens)
            {
                if (versionRegex.IsMatch(tokenElement))
                {
                    Match versionMatcher = versionRegex.Match(tokenElement);
                    GroupCollection groups = versionMatcher.Groups;

                    model.confidence = 90;
                    if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                    {
                        model.SetVersion(groups[1].Value);
                    }
                    if (groups[2] != null && groups[2].Value.Trim().Length > 0)
                    {
                        model.majorRevision = groups[2].Value;
                    }
                    if (groups[3] != null && groups[3].Value.Trim().Length > 0)
                    {
                        model.minorRevision = groups[3].Value;
                    }
                    if (groups[4] != null && groups[4].Value.Trim().Length > 0)
                    {
                        model.microRevision = groups[4].Value;
                    }
                    if (groups[5] != null && groups[5].Value.Trim().Length > 0)
                    {
                        model.nanoRevision = groups[5].Value;
                    }
                }
            }
            return model;
        }
コード例 #12
0
 public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
 {
     foreach (string token in iOSDevices.Keys)
     {
         Regex tokenRegex = new Regex(".*" + token + ".*");
         if (tokenRegex.IsMatch(userAgent.completeUserAgent))
         {
             if (iOSDevices.Contains(token))
             {
                 String iosDeviceID = (string)iOSDevices[token];
                 Device retDevice = null;
                 if (devices.TryGetValue(iosDeviceID, out retDevice))
                 {
                     retDevice = (Device)retDevice.Clone();
                     retDevice.confidence = 90;
                     return retDevice;
                 }
             }
         }
     }
     return null;
 }
コード例 #13
0
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            OSModel.OperatingSystem model = new OSModel.OperatingSystem();
            model.majorRevision = "-";
            model.SetVendor("Apple");
            model.SetModel("Mac OS X");

            int confidence = 60;

            if (versionRegex.IsMatch(userAgent.GetPatternElementsInside()))
            {
                Match versionMatcher = versionRegex.Match(userAgent.GetPatternElementsInside());
                GroupCollection groups = versionMatcher.Groups;

                model.confidence = 80;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    model.SetVersion(groups[1].Value);
                }
                if (groups[2] != null && groups[2].Value.Trim().Length > 0)
                {
                    model.majorRevision = groups[2].Value;
                }
                if (groups[3] != null && groups[3].Value.Trim().Length > 0)
                {
                    model.minorRevision = groups[3].Value;
                }
                if (groups[4] != null && groups[4].Value.Trim().Length > 0)
                {
                    model.microRevision = groups[4].Value;
                }
            }

            model.confidence = confidence;

            return model;
        }
コード例 #14
0
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            int hintedWidth = -1;
            int hintedHeight = -1;

            if (resolutionHintWxHRegex.IsMatch(userAgent.completeUserAgent))
            {
                Match match = resolutionHintWxHRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = match.Groups;
                int.TryParse(groups[0].Value, out hintedWidth);
                int.TryParse(groups[1].Value, out hintedHeight);
            }
            else if (userAgent.completeUserAgent.Contains("VGA") || userAgent.completeUserAgent.Contains("WXGA"))
            {
                if (resolutionHintFWVGARegex.IsMatch(userAgent.completeUserAgent))
                {
                    hintedWidth = 480;
                    hintedHeight = 854;
                }
                else if (resolutionHintWVGARegex.IsMatch(userAgent.completeUserAgent))
                {
                    hintedWidth = 480;
                    hintedHeight = 800;
                }
                else if (resolutionHintWXGARegex.IsMatch(userAgent.completeUserAgent))
                {
                    hintedWidth = 768;
                    hintedHeight = 1280;
                }
                else if (resolutionHintWQVGARegex.IsMatch(userAgent.completeUserAgent))
                {
                    hintedWidth = 240;
                    hintedHeight = 400;
                }
            }

            return BuildBrowser(userAgent, hintedWidth, hintedHeight);
        }
コード例 #15
0
        private Device ElaborateWinPhoneDeviceWithToken(UserAgent userAgent, String token)
        {
            if (userAgent.mozillaPattern || userAgent.operaPattern)
            {
                int subtract = 0;
                String currentToken = token;

                String looseToken = (String)(regexs[token + "_loose"]);
                //String looseToken = Regex.Replace(token, "[ _/-]", ".?");

                Regex looseRegex = (Regex)(regexs[token + "_loose_icase_regex"]);
                //Regex looseRegex = new Regex(/*"(?i).*"*/".*" + looseToken + ".*", RegexOptions.IgnoreCase);

                if (!looseRegex.IsMatch(userAgent.completeUserAgent))
                {
                    return null;
                }

                Regex currentRegex = null;

                if (userAgent.operaPattern)
                {
                    subtract += 10;
                }

                for (int i = 0; i <= 1; i++)
                {
                    if (i == 1)
                    {
                        currentToken = looseToken;
                    }

                    currentRegex = new Regex(/*"(?i).*"*/".?>*" + currentToken, RegexOptions.IgnoreCase);
                    if (userAgent.GetPatternElementsInside() != null && currentRegex.IsMatch(userAgent.GetPatternElementsInside()))
                    {
                        String deviceId = (String)orderedRules[token];

                        Device retDevice = null;
                        if (devices.TryGetValue(deviceId, out retDevice))
                        {
                            retDevice = (Device)retDevice.Clone();
                            retDevice.confidence = (100 - subtract);
                            return retDevice;
                        }
                    }
                    if (userAgent.GetPatternElementsPre() != null && currentRegex.IsMatch(userAgent.GetPatternElementsPre()))
                    {
                        String deviceId = (String)orderedRules[token];

                        Device retDevice = null;
                        if (devices.TryGetValue(deviceId, out retDevice))
                        {
                            retDevice = (Device)retDevice.Clone();
                            retDevice.confidence = (95 - subtract);
                            return retDevice;
                        }
                    }

                    currentRegex = new Regex(/*"(?i).*"*/".?>*" + currentToken + ".?;.*", RegexOptions.IgnoreCase);
                    if (userAgent.GetPatternElementsInside() != null && currentRegex.IsMatch(userAgent.GetPatternElementsInside()))
                    {
                        String deviceId = (String)orderedRules[token];

                        Device retDevice = null;
                        if (devices.TryGetValue(deviceId, out retDevice))
                        {
                            retDevice = (Device)retDevice.Clone();
                            retDevice.confidence = (90 - subtract);
                            return retDevice;
                        }
                    }

                    if (i == 1)
                    {
                        currentRegex = looseRegex;

                    }
                    else
                    {
                        currentRegex = new Regex(/*"(?i).*"*/".?>*" + currentToken + ".*", RegexOptions.IgnoreCase);
                    }

                    if (userAgent.GetPatternElementsInside() != null && currentRegex.IsMatch(userAgent.GetPatternElementsInside()))
                    {
                        String deviceId = (String)orderedRules[token];

                        Device retDevice = null;
                        if (devices.TryGetValue(deviceId, out retDevice))
                        {
                            retDevice = (Device)retDevice.Clone();
                            retDevice.confidence = (80 - subtract);
                            return retDevice;
                        }
                    }
                    if (userAgent.GetPatternElementsPre() != null && currentRegex.IsMatch(userAgent.GetPatternElementsPre()))
                    {
                        String deviceId = (String)orderedRules[token];

                        Device retDevice = null;
                        if (devices.TryGetValue(deviceId, out retDevice))
                        {
                            retDevice = (Device)retDevice.Clone();
                            retDevice.confidence = (80 - subtract);
                            return retDevice;
                        }
                    }
                    if (userAgent.GetPatternElementsPost() != null && currentRegex.IsMatch(userAgent.GetPatternElementsPost()))
                    {
                        String deviceId = (String)orderedRules[token];

                        Device retDevice = null;
                        if (devices.TryGetValue(deviceId, out retDevice))
                        {
                            retDevice = (Device)retDevice.Clone();
                            retDevice.confidence = (60 - subtract);
                            return retDevice;
                        }
                    }
                    subtract += 20;
                }
            }

            return null;
        }
コード例 #16
0
        protected override Browser BuildBrowser(UserAgent userAgent, string layoutEngine, string layoutEngineVersion, int hintedWidth, int hintedHeight)
        {
            if (!(userAgent.mozillaPattern || userAgent.completeUserAgent.Contains("SymbianOS") || userAgent.completeUserAgent.Contains("Symbian/3") || userAgent.completeUserAgent.Contains("Nokia"))) {
                return null;
            }

            int confidence = 50;
            Browser identified = new Browser();

            identified.SetVendor("Nokia");
            identified.SetModel("Nokia Browser");
            identified.SetVersion("-");
            identified.majorRevision = "-";

            if (nokiaBrowserVersionRegex.IsMatch(userAgent.completeUserAgent)) {
                Match nokiaBrowserMatcher = nokiaBrowserVersionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = nokiaBrowserMatcher.Groups;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0) {
                    identified.SetVersion(groups[1].Value);

                    string versionFullString = groups[1].Value;
                    String[] version = versionFullString.Split(".".ToCharArray());

                    if (version.Length > 0) {
                        identified.majorRevision = version[0];
                        if (identified.majorRevision.Length == 0) {
                            identified.majorRevision = "1";
                        }
                    }

                    if (version.Length > 1) {
                        identified.minorRevision = version[1];
                        confidence += 10;
                    }

                    if (version.Length > 2) {
                        identified.microRevision = version[2];
                    }

                    if (version.Length > 3) {
                        identified.nanoRevision = version[3];
                    }
                }

            }

            if (layoutEngine != null) {
                identified.SetLayoutEngine(layoutEngine);
                identified.SetLayoutEngineVersion(layoutEngineVersion);
                if (layoutEngine.Equals(LayoutEngineBrowserBuilder.APPLEWEBKIT)) {
                    confidence += 10;
                }
            }

            if (safariVersionRegex.IsMatch(userAgent.completeUserAgent))
            {
                Match safariMatcher = safariVersionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = safariMatcher.Groups;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    identified.SetReferenceBrowser("Safari");
                    identified.SetReferenceBrowserVersion(groups[1].Value);
                    confidence += 10;
                }
            }

            identified.SetDisplayWidth(hintedWidth);
            identified.SetDisplayHeight(hintedHeight);
            identified.confidence = confidence;

            return identified;
        }
コード例 #17
0
 public override bool CanBuild(UserAgent userAgent)
 {
     return (userAgent.completeUserAgent.Contains("Nokia") || userAgent.completeUserAgent.Contains("NokiaBrowser") || userAgent.completeUserAgent.Contains("BrowserNG") || userAgent.completeUserAgent.Contains("Series60"));
 }
コード例 #18
0
        protected override Browser BuildBrowser(UserAgent userAgent, string layoutEngine, string layoutEngineVersion, int hintedWidth, int hintedHeight)
        {
            if ((!userAgent.operaPattern || userAgent.operaVersion == null || userAgent.operaVersion.Length == 0) && (!operaVersionRegex.IsMatch(userAgent.completeUserAgent)))
            {
                return null;
            }

            int confidence = 60;
            Browser identified = new Browser();

            identified.SetVendor("Opera");
            if (userAgent.completeUserAgent.Contains("Mobi"))
            {
                identified.SetModel("Opera Mobile");
                confidence += 10;

            }
            else if (userAgent.completeUserAgent.Contains("Tablet"))
            {
                identified.SetModel("Opera Tablet");

            }
            else
            {
                identified.SetModel("Opera");
            }

            if (userAgent.operaVersion != null)
            {
                identified.SetVersion(userAgent.operaVersion);
            }
            else
            {
                if (operaVersionRegex.IsMatch(userAgent.completeUserAgent))
                {
                    Match operaMatcher = operaVersionRegex.Match(userAgent.completeUserAgent);
                    GroupCollection groups = operaMatcher.Groups;

                    if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                    {
                        identified.SetVersion(groups[1].Value);
                    }
                }
            }

            String[] version = identified.GetVersion().Split(".".ToCharArray());

            if (version.Length > 0)
            {
                identified.majorRevision = version[0];
            }

            if (version.Length > 1)
            {
                identified.minorRevision = version[1];
                confidence += 10;
            }

            if (version.Length > 2)
            {
                identified.microRevision = version[2];
            }

            if (version.Length > 3)
            {
                identified.nanoRevision = version[3];
            }

            if (layoutEngine != null)
            {
                identified.SetLayoutEngine(layoutEngine);
                identified.SetLayoutEngineVersion(layoutEngineVersion);
                if (layoutEngine.Equals(LayoutEngineBrowserBuilder.PRESTO))
                {
                    confidence += 10;
                }
            }

            if (userAgent.GetPatternElementsInside() != null)
            {
                String[] inside = userAgent.GetPatternElementsInside().Split(";".ToCharArray());
                foreach (String token in inside)
                {
                    String element = token.Trim();

                    if (operaMiniVersionRegex.IsMatch(element))
                    {
                        Match miniMatcher = operaMiniVersionRegex.Match(element);
                        GroupCollection groups = miniMatcher.Groups;

                        if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                        {
                            identified.SetReferenceBrowser("Opera Mobi");
                            identified.SetReferenceBrowserVersion(groups[1].Value);
                            confidence += 10;
                            break;
                        }
                    }
                }
            }

            identified.SetDisplayWidth(hintedWidth);
            identified.SetDisplayHeight(hintedHeight);
            identified.confidence = confidence;

            return identified;
        }
コード例 #19
0
 public override bool CanBuild(UserAgent userAgent)
 {
     return ((userAgent.operaPattern || operaVersionRegex.IsMatch(userAgent.completeUserAgent)) && (!userAgent.completeUserAgent.Contains("Opera Mini")));
 }
コード例 #20
0
 public bool CanBuild(UserAgent userAgent)
 {
     return userAgent.operaPattern;
 }
コード例 #21
0
 public override bool CanBuild(UserAgent userAgent)
 {
     return userAgent.containsWindowsPhone;
 }
コード例 #22
0
 public override bool CanBuild(UserAgent userAgent)
 {
     return (userAgent.completeUserAgent.Contains("Fennec") || (userAgent.completeUserAgent.Contains("Firefox") && userAgent.completeUserAgent.Contains("Mobile")));
 }
コード例 #23
0
 public override bool CanBuild(UserAgent userAgent)
 {
     return userAgent.containsWindowsPhone && (userAgent.mozillaPattern || userAgent.operaPattern);
 }
コード例 #24
0
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            OSModel.OperatingSystem model = new OSModel.OperatingSystem();
            model.majorRevision = "1";
            model.SetVendor("Nokia");
            model.SetModel("Symbian OS");
            model.confidence = 40;

            string patternElementsInside = userAgent.GetPatternElementsInside();
            String[] splittedTokens = patternElementsInside.Split(";".ToCharArray());
            foreach (String tokenElement in splittedTokens)
            {
                if (versionRegex.IsMatch(tokenElement))
                {
                    Match versionMatcher = versionRegex.Match(tokenElement);
                    GroupCollection groups = versionMatcher.Groups;

                    model.SetDescription("Series60");
                    if (model.confidence > 40)
                    {
                        model.confidence = 100;

                    }
                    else
                    {
                        model.confidence = 90;
                    }

                    if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                    {
                        model.majorRevision = groups[1].Value;
                    }
                    if (groups[2] != null && groups[2].Value.Trim().Length > 0)
                    {
                        model.minorRevision = groups[2].Value;
                    }
                    if (groups[3] != null && groups[3].Value.Trim().Length > 0)
                    {
                        model.microRevision = groups[3].Value;
                    }
                }

                if (versionExtraRegex.IsMatch(tokenElement))
                {
                    Match versionExtraMatcher = versionExtraRegex.Match(tokenElement);
                    GroupCollection groups = versionExtraMatcher.Groups;

                    if (model.confidence > 40)
                    {
                        model.confidence = 100;

                    }
                    else
                    {
                        model.confidence = 85;
                    }

                    if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                    {
                        string groupValueTrimmed = groups[1].Value.Trim();
                        model.SetVersion(groupValueTrimmed);
                    }
                }
                //TODO: inference VERSION_EXTRA/VERSION_REGEXP and vice-versa
            }
            return model;
        }
コード例 #25
0
 public bool CanBuild(UserAgent userAgent)
 {
     return userAgent.GetPatternElementsInside().Contains("webOS");
 }
コード例 #26
0
        private Device ElaborateSymbianDeviceWithToken(UserAgent userAgent, String token)
        {
            String originalToken = token;

            if (userAgent.mozillaPattern || userAgent.operaPattern)
            {
                int subtract = 0;
                String currentToken = token;

                String looseToken = (String)(regexs[token + "_loose"]);
                //String looseToken = Regex.Replace(token, "[ _/-]", ".?");

                Regex looseRegex = (Regex)(regexs[token + "_loose_icase_regex"]);
                //Regex looseRegex = new Regex(".*" + looseToken + ".*");

                if (!looseRegex.IsMatch(userAgent.completeUserAgent))
                {
                    return null;
                }

                Regex currentRegex = null;

                if (userAgent.operaPattern)
                {
                    subtract += 10;
                }
                for (int i = 0; i <= 1; i++)
                {
                    if (i == 1)
                    {
                        currentToken = looseToken;
                    }

                    currentRegex = new Regex(".?>*Series60.?(\\d+)\\.(\\d+).?" + currentToken + ".*");
                    if (userAgent.GetPatternElementsInside() != null && currentRegex.IsMatch(userAgent.GetPatternElementsInside()))
                    {
                        if (orderedRules.Contains(originalToken))
                        {
                            String deviceId = (String)orderedRules[originalToken];
                            Device retDevice = null;
                            if (devices.TryGetValue(deviceId, out retDevice))
                            {
                                retDevice = (Device)retDevice.Clone();
                                retDevice.confidence = (100 - subtract);
                                return retDevice;
                            }
                        }
                    }

                    currentRegex = new Regex(".?>*" + currentToken);
                    if (userAgent.GetPatternElementsPre() != null && currentRegex.IsMatch(userAgent.GetPatternElementsPre()))
                    {
                        if (orderedRules.Contains(originalToken))
                        {
                            String deviceId = (String)orderedRules[originalToken];
                            Device retDevice = null;
                            if (devices.TryGetValue(deviceId, out retDevice))
                            {
                                retDevice = (Device)retDevice.Clone();
                                retDevice.confidence = (95 - subtract);
                                return retDevice;
                            }
                        }
                    }

                    if (userAgent.GetPatternElementsInside() != null && currentRegex.IsMatch(userAgent.GetPatternElementsInside()))
                    {
                        if (orderedRules.Contains(originalToken))
                        {
                            String deviceId = (String)orderedRules[originalToken];
                            Device retDevice = null;
                            if (devices.TryGetValue(deviceId, out retDevice))
                            {
                                retDevice = (Device)retDevice.Clone();
                                retDevice.confidence = (90 - subtract);
                                return retDevice;
                            }
                        }
                    }

                    currentRegex = new Regex(".?>*" + currentToken + ".?;.*");
                    if (userAgent.GetPatternElementsInside() != null && currentRegex.IsMatch(userAgent.GetPatternElementsInside()))
                    {
                        if (orderedRules.Contains(originalToken))
                        {
                            String deviceId = (String)orderedRules[originalToken];
                            Device retDevice = null;
                            if (devices.TryGetValue(deviceId, out retDevice))
                            {
                                retDevice = (Device)retDevice.Clone();
                                retDevice.confidence = (90 - subtract);
                                return retDevice;
                            }
                        }
                    }

                    if (i == 1)
                    {
                        currentRegex = looseRegex;

                    }
                    else
                    {
                        currentRegex = new Regex(".?>*" + currentToken + ".*");
                    }

                    if (userAgent.GetPatternElementsInside() != null && currentRegex.IsMatch(userAgent.GetPatternElementsInside()))
                    {
                        if (orderedRules.Contains(originalToken))
                        {
                            String deviceId = (String)orderedRules[originalToken];
                            Device retDevice = null;
                            if (devices.TryGetValue(deviceId, out retDevice))
                            {
                                retDevice = (Device)retDevice.Clone();
                                retDevice.confidence = (80 - subtract);
                                return retDevice;
                            }
                        }
                    }

                    if (userAgent.GetPatternElementsPre() != null && currentRegex.IsMatch(userAgent.GetPatternElementsPre()))
                    {
                        if (orderedRules.Contains(originalToken))
                        {
                            String deviceId = (String)orderedRules[currentToken];
                            Device retDevice = null;
                            if (devices.TryGetValue(deviceId, out retDevice))
                            {
                                retDevice = (Device)retDevice.Clone();
                                retDevice.confidence = (80 - subtract);
                                return retDevice;
                            }
                        }
                    }

                    if (userAgent.GetPatternElementsPost() != null && currentRegex.IsMatch(userAgent.GetPatternElementsPost()))
                    {
                        if (orderedRules.Contains(originalToken))
                        {
                            String deviceId = (String)orderedRules[currentToken];
                            Device retDevice = null;
                            if (devices.TryGetValue(deviceId, out retDevice))
                            {
                                retDevice = (Device)retDevice.Clone();
                                retDevice.confidence = (60 - subtract);
                                return retDevice;
                            }
                        }
                    }
                    subtract += 20;
                }
            }
            else
            {
                String ua = Regex.Replace(userAgent.completeUserAgent, "SN[0-9]*", "");

                int subtract = 0;
                String currentToken = token;

                String looseToken = (String)(regexs[token + "_loose"]);
                //String looseToken = Regex.Replace(token, "[ _/-]", ".?");

                Regex looseRegex = (Regex)(regexs[token + "_loose_icase_regex"]);
                //Regex looseRegex = new Regex(".*" + looseToken + ".*");

                if (!looseRegex.IsMatch(userAgent.completeUserAgent))
                {
                    return null;
                }

                Regex currentRegex = null;

                for (int i = 0; i <= 1; i++)
                {
                    if (i == 1)
                    {
                        currentToken = looseToken;
                    }

                    currentRegex = new Regex(".?>*" + currentToken + ".*");
                    if (currentRegex.IsMatch(ua))
                    {
                        if (orderedRules.Contains(originalToken))
                        {
                            string deviceId = orderedRules[originalToken] as string;

                            if (devices.ContainsKey(deviceId))
                            {
                                Device retDevice = (Device)devices[deviceId].Clone();
                                retDevice.confidence = 100 - subtract;
                                return retDevice;
                            }
                        }
                    }

                    subtract += 20;
                }
            }

            return null;
        }
コード例 #27
0
        protected override Browser BuildBrowser(UserAgent userAgent, string layoutEngine, string layoutEngineVersion, int hintedWidth, int hintedHeight)
        {
            if (!(userAgent.mozillaPattern))
            {
                return null;
            }

            int confidence = 60;
            Browser identified = new Browser();

            identified.SetVendor("Mozilla");
            identified.SetModel("Firefox Mobile");
            identified.SetVersion("-");
            identified.majorRevision = "-";

            if (fennecVersionRegex.IsMatch(userAgent.completeUserAgent))
            {
                Match fennecMatcher = fennecVersionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = fennecMatcher.Groups;
                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    identified.SetVersion(groups[1].Value);

                    string versionFullString = groups[1].Value;
                    String[] version = versionFullString.Split(".".ToCharArray());

                    if (version.Length > 0)
                    {
                        identified.majorRevision = version[0];
                        if (identified.majorRevision.Length == 0)
                        {
                            identified.majorRevision = "1";
                        }
                    }

                    if (version.Length > 1)
                    {
                        identified.minorRevision = version[1];
                        confidence += 10;
                    }

                    if (version.Length > 2)
                    {
                        identified.microRevision = version[2];
                    }

                    if (version.Length > 3)
                    {
                        identified.nanoRevision = version[3];
                    }
                }

            }
            else if (firefoxVersionRegex.IsMatch(userAgent.completeUserAgent))
            {
                Match firefoxMatcher = firefoxVersionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = firefoxMatcher.Groups;
                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    identified.SetVersion(groups[1].Value);

                    string versionFullString = groups[1].Value;
                    String[] version = versionFullString.Split(".".ToCharArray());

                    if (version.Length > 0)
                    {
                        identified.majorRevision = version[0];
                        if (identified.majorRevision.Length == 0)
                        {
                            identified.majorRevision = "1";
                        }
                    }

                    if (version.Length > 1)
                    {
                        identified.minorRevision = version[1];
                        confidence += 10;
                    }

                    if (version.Length > 2)
                    {
                        identified.microRevision = version[2];
                    }

                    if (version.Length > 3)
                    {
                        identified.nanoRevision = version[3];
                    }
                }
            }
            else
            {
                //fallback version
                identified.SetVersion("1.0");
                identified.majorRevision = "1";
            }

            if (layoutEngine != null)
            {
                identified.SetLayoutEngine(layoutEngine);
                identified.SetLayoutEngineVersion(layoutEngineVersion);
                if (layoutEngine.Equals(LayoutEngineBrowserBuilder.GECKO))
                {
                    confidence += 10;
                }
            }

            if (firefoxVersionRegex.IsMatch(userAgent.completeUserAgent))
            {
                Match firefoxMatcher = firefoxVersionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = firefoxMatcher.Groups;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    identified.SetReferenceBrowser("Firefox");
                    identified.SetReferenceBrowserVersion(groups[1].Value);
                    confidence += 10;
                }
            }

            identified.SetDisplayWidth(hintedWidth);
            identified.SetDisplayHeight(hintedHeight);
            identified.confidence = confidence;

            return identified;
        }
コード例 #28
0
 public override bool CanBuild(UserAgent userAgent)
 {
     return userAgent.containsSymbian;
 }
コード例 #29
0
        protected override Browser BuildBrowser(UserAgent userAgent, string layoutEngine, string layoutEngineVersion, int hintedWidth, int hintedHeight)
        {
            if (!userAgent.containsWindowsPhone || !(windowsCePhoneRegex.IsMatch(userAgent.completeUserAgent)))
            {
                return null;
            }

            int confidence = 40;
            Browser identified = new Browser();

            identified.SetVendor("Microsoft");
            identified.SetModel("IEMobile");

            if (userAgent.completeUserAgent.Contains("MSIEMobile"))
            {
                confidence += 10;
            }

            if (userAgent.mozillaPattern)
            {
                confidence += 10;
            }

            if (versionRegex.IsMatch(userAgent.completeUserAgent))
            {
                Match versionMatcher = versionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = versionMatcher.Groups;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    identified.SetVersion(groups[1].Value);

                    string versionFullString = groups[1].Value;
                    String[] version = versionFullString.Split(".".ToCharArray());

                    if (version.Length > 0)
                    {
                        identified.majorRevision = version[0];
                        if (identified.majorRevision.Length == 0)
                        {
                            identified.majorRevision = "1";
                        }
                    }

                    if (version.Length > 1)
                    {
                        identified.minorRevision = version[1];
                        confidence += 10;
                    }

                    if (version.Length > 2)
                    {
                        identified.microRevision = version[2];
                    }

                    if (version.Length > 3)
                    {
                        identified.nanoRevision = version[3];
                    }
                }

            }
            else
            {
                //fallback version
                identified.SetVersion("1.0");
                identified.majorRevision = "1";
            }

            if (msieVersionRegex.IsMatch(userAgent.completeUserAgent))
            {
                Match msieMatcher = msieVersionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = msieMatcher.Groups;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    identified.SetReferenceBrowser("MSIE");
                    identified.SetReferenceBrowserVersion(groups[1].Value);
                    confidence += 10;
                }
            }

            if (msieMobileVersionRegex.IsMatch(userAgent.completeUserAgent))
            {
                Match msieMobileMatcher = msieMobileVersionRegex.Match(userAgent.completeUserAgent);
                GroupCollection groups = msieMobileMatcher.Groups;

                if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                {
                    identified.SetLayoutEngine("MSIEMobile");
                    identified.SetLayoutEngineVersion(groups[1].Value);
                    confidence += 10;
                }
            }

            if (layoutEngine != null)
            {
                identified.SetLayoutEngine(layoutEngine);
                identified.SetLayoutEngineVersion(layoutEngineVersion);
                if (layoutEngine.Equals(LayoutEngineBrowserBuilder.TRIDENT))
                {
                    confidence += 10;
                }
            }

            identified.SetDisplayWidth(hintedWidth);
            identified.SetDisplayHeight(hintedHeight);
            identified.confidence = confidence;

            return identified;
        }
コード例 #30
0
 public override bool CanBuild(UserAgent userAgent)
 {
     return userAgent.completeUserAgent.Contains("Konqueror");
 }