public void Agents()
		{
			var userAgentParser = new UserAgentParser(this.xml);

			var chrome = userAgentParser.Parse("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2");
			Assert.AreEqual("Chrome", chrome.ClientName);
			Assert.AreEqual(15, chrome.ClientMajorVersion);

			var ios = userAgentParser.Parse("Mozilla/5.0 (iPhone; U; XXXXX like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/241 Safari/419.3");
			Assert.AreEqual("Mobile Safari", ios.ClientName);

			var wp7 = userAgentParser.Parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0) Asus;Galaxy6");
			Assert.AreEqual("IE Mobile", wp7.ClientName);
		}
Ejemplo n.º 2
0
        public static BrowserType GetBrowserType(string userAgent)
        {
            if (userAgent == null)
            {
                return(BrowserType.Other);
            }
            string a    = null;
            string text = null;

            UserAgentParser.UserAgentVersion userAgentVersion;
            UserAgentParser.Parse(userAgent, out a, out userAgentVersion, out text);
            if (string.Equals(a, "MSIE", StringComparison.OrdinalIgnoreCase))
            {
                return(BrowserType.IE);
            }
            if (string.Equals(a, "Opera", StringComparison.OrdinalIgnoreCase))
            {
                return(BrowserType.Opera);
            }
            if (string.Equals(a, "Safari", StringComparison.OrdinalIgnoreCase))
            {
                return(BrowserType.Safari);
            }
            if (string.Equals(a, "Firefox", StringComparison.OrdinalIgnoreCase))
            {
                return(BrowserType.Firefox);
            }
            if (string.Equals(a, "Chrome", StringComparison.OrdinalIgnoreCase))
            {
                return(BrowserType.Chrome);
            }
            return(BrowserType.Other);
        }
Ejemplo n.º 3
0
        private void Init(
            Provider devices,
            string deviceId,
            string userAgent)
        {
            if (userAgent == null)
            {
                throw new ArgumentNullException("userAgent");
            }

            _userAgent = UserAgentParser.Parse(userAgent);

            Init(devices, deviceId);
        }
Ejemplo n.º 4
0
        public static bool IsDownLevelClient(this HttpRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            ExTraceGlobals.VerboseTracer.TraceDebug <string>(0L, "Extensions.IsDownLevelClient. user-agent = {0}", (request.UserAgent == null) ? string.Empty : request.UserAgent);
            string a;

            UserAgentParser.UserAgentVersion userAgentVersion;
            string a2;

            UserAgentParser.Parse(request.UserAgent, out a, out userAgentVersion, out a2);
            return((!string.Equals(a, "rv:", StringComparison.OrdinalIgnoreCase) || userAgentVersion.Build < 11 || !string.Equals(a2, "Windows NT", StringComparison.OrdinalIgnoreCase)) && (!string.Equals(a, "MSIE", StringComparison.OrdinalIgnoreCase) || userAgentVersion.Build < 7 || (!string.Equals(a2, "Windows NT", StringComparison.OrdinalIgnoreCase) && !string.Equals(a2, "Windows 98; Win 9x 4.90", StringComparison.OrdinalIgnoreCase) && !string.Equals(a2, "Windows 2000", StringComparison.OrdinalIgnoreCase))) && (!string.Equals(a, "Safari", StringComparison.OrdinalIgnoreCase) || userAgentVersion.Build < 3 || !string.Equals(a2, "Macintosh", StringComparison.OrdinalIgnoreCase)) && (!string.Equals(a, "Firefox", StringComparison.OrdinalIgnoreCase) || userAgentVersion.Build < 3 || (!string.Equals(a2, "Windows NT", StringComparison.OrdinalIgnoreCase) && !string.Equals(a2, "Windows 98; Win 9x 4.90", StringComparison.OrdinalIgnoreCase) && !string.Equals(a2, "Windows 2000", StringComparison.OrdinalIgnoreCase) && !string.Equals(a2, "Macintosh", StringComparison.OrdinalIgnoreCase) && !string.Equals(a2, "Linux", StringComparison.OrdinalIgnoreCase))) && (!string.Equals(a, "Chrome", StringComparison.OrdinalIgnoreCase) || userAgentVersion.Build < 1 || (!string.Equals(a2, "Windows NT", StringComparison.OrdinalIgnoreCase) && !string.Equals(a2, "Macintosh", StringComparison.OrdinalIgnoreCase))));
        }