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; }
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 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(); 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 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; }