public void CheckWindows8Detection() { const string userAgent = "Windows NT 6.2"; var userAgentReader = new UserAgentReader(userAgent); Assert.IsTrue(userAgentReader.HasWindows8, "Windows 8"); }
public void CheckAllCLRInUserAgentDetectionStrings() { var userAgentCLRString = String.Join(" ", CLRVersionStrings().ToArray()); var userAgentChecker = new UserAgentReader(userAgentCLRString); Assert.IsTrue(userAgentChecker.HasDotNet10, ".NET Version 1.0"); Assert.IsTrue(userAgentChecker.HasDotNet11, ".NET Version 1.1"); Assert.IsTrue(userAgentChecker.HasDotNet20, ".NET Version 2.0"); Assert.IsTrue(userAgentChecker.HasDotNet35, ".NET Version 3.5"); Assert.IsTrue(userAgentChecker.HasDotNet35SP1Client, ".NET Version 3.5 SP1 Client Profile"); Assert.IsTrue(userAgentChecker.HasDotNet35SP1Full, ".NET Version 3.5 SP1 Full"); Assert.IsTrue(userAgentChecker.HasDotNet40Client, ".NET Version 4.0 Client Profile"); Assert.IsTrue(userAgentChecker.HasDotNet40Full, ".NET Version 4.0 Full"); }
public Dictionary<string, CLRVersion> GetInstalledVersions() { var results = new Dictionary<string, CLRVersion>(); var foundVersions = UserAgent.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Where(s => s.Contains(".NET")); foreach (string match in foundVersions) { var v = match.Trim(); //this really sucks and makes me mad if (v.Contains(Constants.Version35Full) && !v.Contains(Constants.Version35SP1Client) && !v.Contains(Constants.Version35SP1Full)) v = Constants.Version35Full; if (v.Contains(Constants.Version30Full)) v = Constants.Version30Full; if (v.Contains(Constants.Version20Full)) v = Constants.Version20Full; if (v.Contains(Constants.Version11Full)) v = Constants.Version11Full; if (v.Contains(Constants.Version10Full)) v = Constants.Version10Full; if (Versions.ContainsKey(v)) { var version = Versions[v]; results.Add(v, version); } } var userAgentChecker = new UserAgentReader(UserAgent); if (userAgentChecker.HasWindows8) { results.Add(Constants.Version45Full, Versions[Constants.Version45Full]); } return results; }
public static string GetUpdateInformation(string userAgentString, Version version) { var userAgent = new UserAgentReader(userAgentString); string netInfoString = ""; //We should check this first since we don't need to check .NET versions if they can't have .NET versions if (userAgent.HasMac) { netInfoString = "It looks like you're running a Mac or an iPhone. There's no .NET Framework download from Microsoft for the Mac, but you might check out <a href=\"http://www.go-mono.com/mono-downloads/download.html\">Mono</a>, which is an Open Source platform that can run .NET code on a Mac. For your iPhone, check out <a href=\"http://xamarin.com/monotouch\">MonoTouch</a> and write .NET apps for iOS!"; return netInfoString; } if (userAgent.HasUnix) { netInfoString = "It looks like you're running a Unix machine. There's no .NET Framework download from Microsoft for Unix, but you might check out <a href=\"http://www.go-mono.com/mono-downloads/download.html\">Mono</a>, which is an Open Source platform that can run .NET code on Unix."; return netInfoString; } bool net4 = (GetWindows8Message(userAgentString, ref netInfoString) || Get40Message(userAgentString, ref netInfoString)); if (userAgent.HasDotNet35X) { netInfoString += DotNet3_5Message((userAgent.HasDotNet35SP1Client || userAgent.HasDotNet35SP1Full), net4); } else if (userAgent.HasDotNet30) { netInfoString += DotNet3Message(net4); } else if (userAgent.HasDotNet20) { netInfoString += DotNet2Message(net4); } else if (userAgent.HasDotNet11 || userAgent.HasDotNet10) { netInfoString += DotNet1Message(net4); } else if (!net4) { if (userAgentString.Contains("fox")) { netInfoString += MessageForBrowser("Firefox"); } else if (userAgentString.Contains("Chrome")) { netInfoString += MessageForBrowser("Chrome"); } else if (userAgentString.Contains("Safari")) // Chrome also uses safari in the user agent so this check must come after { netInfoString += MessageForBrowser("Safari"); } else { netInfoString += UnknownBrowserMessage(); } } //need to see if windows 2000 has the latest version foreach (KeyValuePair<string, string> windowsVersion in Constants.OldWindows) { netInfoString += CheckDotNet3_5UnSupportedOs(userAgentString, windowsVersion.Key, windowsVersion.Value); } return netInfoString; }
private static bool GetWindows8Message(string UserAgent, ref string userMessage) { var userAgent = new UserAgentReader(UserAgent); if (userAgent.HasWindows8 || userAgent.HasDotNet45) { userMessage += String.Format(Constants.EarlyAdopter, "full install of .NET 4.5"); return true; } return false; }
private static bool Get40Message(string UserAgent, ref string userMessage) { var userAgentChecker = new UserAgentReader(UserAgent); var whichVersion = ""; var ret = false; if (userAgentChecker.HasDotNet40Full) { whichVersion = ".NET 4.0"; ret = true; } else if (userAgentChecker.HasDotNet40Client) { whichVersion = ".NET 4.0 Client Profile"; ret = true; } if (ret) { userMessage += String.Format(@"You have {0}, this is a recent version of .NET. Download an installer for the newest version <strong>{1}</strong>.", whichVersion, Constants.DotNetOnline); } return ret; }