GetPatternElementsInside() public méthode

public GetPatternElementsInside ( ) : String
Résultat String
        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;
        }
        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;
        }
        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;
        }
 public bool CanBuild(UserAgent userAgent)
 {
     return userAgent.GetPatternElementsInside().Contains("webOS");
 }
        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;
        }
        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;
        }
        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;
        }
        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;
        }
 public bool CanBuild(UserAgent userAgent)
 {
     return (userAgent.GetPatternElementsInside() != null && userAgent.GetPatternElementsInside().Contains("Bada"));
 }
 public bool CanBuild(UserAgent userAgent)
 {
     Regex brewRegex = new Regex(/*"(?i).*brew.*"*/".*brew.*", RegexOptions.IgnoreCase);
     return (userAgent.GetPatternElementsInside() != null && brewRegex.IsMatch(userAgent.GetPatternElementsInside()));
 }
        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("Amazon");
            identified.SetModel("Silk");
            identified.SetVersion("-");
            identified.majorRevision = "-";

            Match silkMatcher = silkVersionRegex.Match(userAgent.GetPatternElementsInside());
            GroupCollection groups = silkMatcher.Groups;

            if (silkMatcher.Success)
            {
                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[2] != null)
                    {
                        String[] subVersion = version[2].Split("-".ToCharArray());

                        if (subVersion.Length > 0)
                        {
                            identified.microRevision = subVersion[0];
                        }

                        if (subVersion.Length > 1)
                        {
                            identified.nanoRevision = subVersion[1];
                        }
                    }
                }

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

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

            if (userAgent.containsAndroid)
            {
                identified.SetReferenceBrowser("Android Browser");
                Match androidMatcher = versionRegex.Match(userAgent.completeUserAgent);
                GroupCollection androidGroups = androidMatcher.Groups;

                if (androidMatcher.Success)
                {
                    if (androidGroups[1] != null && androidGroups[1].Value.Trim().Length > 0)
                    {
                        identified.SetReferenceBrowserVersion(androidGroups[1].Value);
                        confidence += 5;
                    }
                }
                confidence += 5;
            }
            else if (userAgent.completeUserAgent.Contains("Safari") && !userAgent.completeUserAgent.Contains("Mobile"))
            {
                identified.SetReferenceBrowser("Safari");
                Match safariMatcher = versionRegex.Match(userAgent.completeUserAgent);
                GroupCollection safariGroups = safariMatcher.Groups;

                if (safariMatcher.Success)
                {
                    if (safariGroups[1] != null && safariGroups[1].Value.Trim().Length > 0)
                    {
                        identified.SetReferenceBrowserVersion(safariGroups[1].Value);
                        confidence += 5;
                    }
                }
                confidence += 5;
            }

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

            return identified;
        }
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            OSModel.OperatingSystem model = new OSModel.OperatingSystem();
            model.SetVendor("Microsoft");
            model.SetModel("Windows Phone");
            model.confidence = 40;
            bool isInPostMoz = false;

            String toSplit = userAgent.GetPatternElementsInside();

            if (!versionRegex.IsMatch(toSplit))
            {
                toSplit = userAgent.GetPatternElementsPost();
                isInPostMoz = true;
            }

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

                    if (isInPostMoz)
                    {
                        model.confidence = 85;

                    }
                    else
                    {
                        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;
                    }
                }

                if (model.majorRevision.Equals("0") && model.minorRevision.Equals("0"))
                {
                    model.majorRevision = "6";
                    model.minorRevision = "5";
                }
                model.SetDescription("Windows Phone " + model.majorRevision + "." + model.minorRevision + "." + model.microRevision + "." + model.nanoRevision);
            }
            return model;
        }
 public bool CanBuild(UserAgent userAgent)
 {
     if (userAgent.containsWindowsPhone)
     {
         Regex windowsPhoneRegex = new Regex(".*Windows.?Phone.*");
         if (windowsPhoneRegex.IsMatch(userAgent.GetPatternElementsInside() + userAgent.GetPatternElementsPost()))
         {
             return true;
         }
     }
     return false;
 }
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            OSModel.OperatingSystem model = new OSModel.OperatingSystem();

            String rebuilded = userAgent.GetPatternElementsInside() + ";" + userAgent.GetPatternElementsPost();

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

                    if (groups[11].Value != null && groups[11].Value.Trim().Length > 0)
                    {
                        model.SetVendor("Research In Motion");
                        model.SetModel("RIM Tablet OS");
                        model.majorRevision = "1";
                        model.confidence = 50;

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

                        }

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

                        }

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

                        }

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

                        }

                        if (groups[15].Value != null && groups[15].Value.Trim().Length > 0)
                        {
                            model.nanoRevision = groups[15].Value;
                            model.confidence = 90;

                        }
                        return model;

                    }
                    else if ((groups[1] != null && groups[1].Value.Trim().Length > 0) || (groups[6] != null && groups[6].Value.Trim().Length > 0))
                    {
                        model.SetVendor("Research In Motion");
                        model.SetModel("Black Berry OS");
                        model.majorRevision = "1";
                        model.confidence = 40;

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

                            }
                            else
                            {
                                model.confidence = 80;
                            }

                        }
                        else if (groups[6] != null && groups[6].Value.Trim().Length > 0)
                        {
                            model.confidence = 90;
                        }

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

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

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

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

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

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

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

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

                        if (groups[5] != null && groups[5].Value.Trim().Length > 0)
                        {
                            model.nanoRevision = groups[5].Value;

                        }
                        else if (groups[10] != null && groups[10].Value.Trim().Length > 0)
                        {
                            model.nanoRevision = groups[10].Value;
                        }
                        return model;

                    }
                }
            }
            return model;
        }
        public BuiltObject Build(UserAgent userAgent, int confidenceTreshold)
        {
            OSModel.OperatingSystem model = new OSModel.OperatingSystem();
            model.majorRevision = "1";
            model.SetVendor("Microsoft");
            model.SetModel("Windows Phone");
            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;

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

                    }
                    else
                    {
                        model.confidence = 85;
                    }

                    if (groups[1] != null && groups[1].Value.Trim().Length > 0)
                    {
                        model.SetDescription(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 (versionMsieRegex.IsMatch(tokenElement))
                {
                    Match versionMsieMatcher = versionMsieRegex.Match(tokenElement);
                    String version = model.GetVersion();
                    if (version == null || version.Length < 7)
                    {
                        version = "0.0.0.0";
                    }
                    String[] subVersion = version.Split(".".ToCharArray());
                    int count = 0;
                    GroupCollection groups = versionMsieMatcher.Groups;
                    for (int idx = 1; idx <= groups.Count; idx++)
                    {
                        if ((idx >= 1) && (idx <= 4) && groups[idx] != null && groups[idx].Value.Trim().Length > 0)
                        {
                            subVersion[idx - 1] = groups[idx].Value;
                            count++;
                        }
                    }
                    model.SetVersion(subVersion[0] + "." + subVersion[1] + "." + subVersion[2] + "." + subVersion[3]);

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

                    }
                    else
                    {
                        model.confidence = (count * 18);
                    }
                }
            }
            SetWinCeVersion(model);
            return model;
        }