Skip to content
Browse files

Adding OS Discovery

Adding Operating System information and discovery to help identify the
correct .NET version to push to a visitor.
  • Loading branch information...
1 parent 9eb699a commit 89c419e18bff6b4834b733a2fea3f7727d99c671 @msarchet msarchet committed Oct 7, 2012
View
155 SmallestDotNet/Default.aspx
@@ -2,25 +2,52 @@
<!DOCTYPE html>
<html>
<head>
+ <title>Get the .NET Framework Fast - Download the smallest .NET Framework Distribution possible</title>
<meta name="Description" content="Get the right .NET Framework download for you, as fast as possible by downloading as little as possible." />
<meta name="Keywords" content=".NET Framework Gast" />
<meta charset="utf-8" />
<meta name="Distribution" content="Global" />
<meta name="t_omni_extblogid" content="msstoextblogs1" />
<meta name="t_omni_blogname" content="Scott Hanselman" />
- <meta name="viewport" content="width=device-width" />
+ <meta name="viewport" content="width=device-width" />
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="css/bootstrap-responsive.min.css" type="text/css" />
<link href="css/font-awesome.css" rel="stylesheet" type="text/css" />
- <!--[if IE 7]><link rel="stylesheet" href="/css/font-awesome-ie7.css"><![endif]-->
<link href="css/m-buttons.min.css" rel="stylesheet" media="screen" />
<link rel="Stylesheet" href="css/main.css" type="text/css" />
- <title>Get the .NET Framework Fast - Download the smallest .NET Framework Distribution possible</title>
+ <!--[if IE 7]><link rel="stylesheet" href="/css/font-awesome-ie7.css"><![endif]-->
+ <style type="text/css">
+ body
+ {
+ font-family: 'Droid Sans', sans-serif;
+ }
+
+
+ .header
+ {
+ padding-bottom: 10%;
+ }
+ .bottom-container
+ {
+ color: #eee;
+ background: #aaa;
+ }
+
+ pre
+ {
+ background: #aaa;
+ color: #000;
+ }
+ i
+ {
+ padding-right: 5px;
+ }
+ </style>
</head>
<body>
- <div class="navbar navbar-inverse navbar-fixed-top">
+ <div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
@@ -30,10 +57,11 @@
</a>
<a class="brand" href="#">SmallestDotNET</a>
<div class="nav-collapse pull-right">
- <ul class="nav">
- <li><a href="http://www.hanselman.com"><i class="icon-sign-blank"></i> Scott's Blog</a></li>
- <li><a href="https://github.com/shanselman/SmallestDotNet/"><i class="icon-github-sign"></i> This site on GitHub</a></li>
- <li><a href="https://github.com/shanselman/SmallestDotNet/issues"><i class="icon-heart"></i> Report a Bug</a></li>
+ <ul class="nav pull-right">
+ <li><a href="<%= Constants.Version45URL %>"><i class="icon-download-alt"></i>Get .NET</a></li>
+ <li><a href="http://www.hanselman.com"><i class="icon-sign-blank"></i>Scott's Blog</a></li>
+ <li><a href="https://github.com/shanselman/SmallestDotNet/"><i class="icon-github-sign"></i>This site on GitHub</a></li>
+ <li><a href="https://github.com/shanselman/SmallestDotNet/issues"><i class="icon-heart"></i>Report a Bug</a></li>
</ul>
</div>
<!--/.nav-collapse -->
@@ -42,7 +70,6 @@
</div>
<div class="container">
-
<div class="row-fluid">
<div class="span12">
<div class="result-header">
@@ -57,8 +84,8 @@
</div>
</div>
- </div>
-
+ </div>
+ </div>
<div class="row-fluid">
<div class="span12">
<h2>What about .NET 4.5?</h2>
@@ -67,74 +94,77 @@
This harmless code signed application will tell us if you have .NET 4.5. Don't trust us? Here's <a href="https://github.com/shanselman/SmallestDotNet/blob/master/CheckForDotNet45/Program.cs">the code</a>.
</div>
</div>
- <!-- Example row of columns -->
- <div class="row-fluid">
- <div class="span4">
- <h2><i class="icon-question-sign"></i> What happened</h2>
- This site looked at your browser's "UserAgent" and figured out what version (if any) of the .NET Framework you have (or don't have) installed, then calculated the total size if you chose to download the .NET Framework.
- <br />
+ <!-- Example row of columns -->
+ <div class="row-fluid">
+ <div class="span4">
+ <h2><i class="icon-question-sign"></i>What happened</h2>
+ This site looked at your browser's "UserAgent" and figured out what version (if any) of the .NET Framework you have (or don't have) installed, then calculated the total size if you chose to download the .NET Framework.
<br />
- There's no database, no cookies, and nothing about your computer has been stored or kept. We just look at the information your browser already reports about your computer and make a suggestion as to the best .NET Framework download for you.
+ <br />
+ There's no database, no cookies, and nothing about your computer has been stored or kept. We just look at the information your browser already reports about your computer and make a suggestion as to the best .NET Framework download for you.
<br />
- <br />
- </div>
+ <br />
+ </div>
<div class="span8">
- <h2><i class="icon-download-alt"></i> Offline Download</h2>
- <asp:Literal runat="server" ID="developerOfflineResult" />
- <h2><i class="icon-download-alt"></i> Online Download</h2>
+ <h2><i class="icon-download-alt"></i>Downloads</h2>
+ <ul class="unstyled">
<asp:Literal runat="server" ID="developerOnline" />
+ </li>
+ <li>
+ <asp:Literal runat="server" ID="developerOfflineResult" />
+ </li>
+ </ul>
+ </div>
</div>
- </div>
- <div class="row-fluid">
- <div class="span8">
- <h3>Are you a .NET Programmer?</h3>
- If you're a programmer/developer, you might be trying to figure out which .NET Framework for your users to use.
- <br />
- <br />
- Sometimes finding the right .NET Framework is confusing because different kinds of machines (x86, x64, ia64) that may or may not have different versions of .NET already on them.
- <br />
- <br />
- If you look for .NET Downloads on Microsoft's site, it might look like the .NET Framework is 200+ megs. It's not. Those big downloads are the Complete Offline Versions of every version of the .NET Framework for every kind of machine possible. The big .NET download includes x86, x64, and ia64. It includes .NET 2.0, 3.0, and 3.5 code for all systems all in one super-archive. The download for .NET 4.5 is even smaller.
- <br />
- <br />
- Why would you EVER want to download the whole archive? Only if you're a developer and you want to distribute the .NET Framework the widest possible audience in a format like a CD or DVD.
- </div>
- <div class="span4">
- <h3>Your User Agent</h3>
- For technical or debugging purposes, this is exactly what your browser said about itself:
+ <div class="row-fluid">
+ <div class="span8">
+ <h3>Are you a .NET Programmer?</h3>
+ If you're a programmer/developer, you might be trying to figure out which .NET Framework for your users to use.
+ <br />
+ <br />
+ Sometimes finding the right .NET Framework is confusing because different kinds of machines (x86, x64, ia64) that may or may not have different versions of .NET already on them.
+ <br />
+ <br />
+ If you look for .NET Downloads on Microsoft's site, it might look like the .NET Framework is 200+ megs. It's not. Those big downloads are the Complete Offline Versions of every version of the .NET Framework for every kind of machine possible. The big .NET download includes x86, x64, and ia64. It includes .NET 2.0, 3.0, and 3.5 code for all systems all in one super-archive. The download for .NET 4.5 is even smaller.
+ <br />
+ <br />
+ Why would you EVER want to download the whole archive? Only if you're a developer and you want to distribute the .NET Framework the widest possible audience in a format like a CD or DVD.
+ </div>
+ <div class="span4">
+ <h3>Your User Agent</h3>
+ For technical or debugging purposes, this is exactly what your browser said about itself:
<br />
- <pre><asp:Literal runat="server" ID="userAgent" /></pre>
+ <pre id="userAgentPre"><asp:Literal runat="server" ID="userAgent" /></pre>
+ </div>
</div>
- </div>
- <div class="row-fluid">
- <div class="span12">
- <h3>Integration</h3>
- Want SmallestDotNet functionality for your own site? Add this chunk of JavaScript, it'll spit out HTML and you can style to taste.
+ <div class="row-fluid">
+ <div class="span12">
+ <h3>Integration</h3>
+ Want SmallestDotNet functionality for your own site? Add this chunk of JavaScript, it'll spit out HTML and you can style to taste.
<br />
- <pre>&LT;script type="text/javascript" src="http://www.smallestdotnet.com/javascript.ashx"&GT;&LT;/script&GT;</pre>
+ <pre>&LT;script type="text/javascript" src="http://www.smallestdotnet.com/javascript.ashx"&GT;&LT;/script&GT;</pre>
+ </div>
</div>
- </div>
- <div class="row-fluid">
- <div class="span12">
- Prefer a JavaScript Object (JSON) to detect .NET Framework installations? Try this instead:
+ <div class="row-fluid">
+ <div class="span12">
+ Prefer a JavaScript Object (JSON) to detect .NET Framework installations? Try this instead:
<br />
- <pre>&LT;script type="text/javascript" src="http://www.smallestdotnet.com/javascriptdom.ashx"&GT;&LT;/script&GT;</pre>
- Get examples on <a href="http://www.hanselman.com/blog/SmallestDotNetUpdateNowWithNet4SupportandanincludableJavascriptapi.aspx">how to use the JSON object on Scott's Blog.</a>
+ <pre>&LT;script type="text/javascript" src="http://www.smallestdotnet.com/javascriptdom.ashx"&GT;&LT;/script&GT;</pre>
+ Get examples on <a href="http://www.hanselman.com/blog/SmallestDotNetUpdateNowWithNet4SupportandanincludableJavascriptapi.aspx">how to use the JSON object on Scott's Blog.</a>
+ </div>
</div>
- </div>
- <div class="row-fluid">
+ <div class="row-fluid">
<div class="span12 ">
- <footer>
+ <hr />
<hr />
<p>&copy; <a href="http://www.hanselman.com">Scott Hanselman</a>, <a href="http://www.MichaelSarchet.com">Michael Sarchet</a> and Friends 2012. <a href="http://www.github.com/shanselman/smallestdotnet">See the Source and report issues</a>.
The lovely <a href="http://ace-subido.github.com/css3-microsoft-metro-buttons/index.html">CSS3 Microsoft-Modern Buttons</a> are by <a href="http://acesubido.com/">Ace Subido</a>.</p>
- </footer>
</div>
</div>
</div>
@@ -145,10 +175,10 @@
<script type="text/javascript">
$(function () {
$('.result-header').hide();
- if (document.location.search.indexOf('realversion') > -1) {
- $('#header-statement').text('We Found .NET!');
- $('.result-header').fadeIn(1000);
- return;
+ if (document.location.search.indexOf('realversion') > -1) {
+ $('#header-statement').text('We Found .NET!');
+ $('.result-header').fadeIn(1000);
+ return;
}
$('.result-header').show();
var userAgent = navigator.userAgent;
@@ -159,6 +189,7 @@
$('#javascriptResult').html(data);
}
);
+ $('#userAgentPre').text(userAgent);
}
})
</script>
View
4 SmallestDotNet/Default.aspx.cs
@@ -12,10 +12,6 @@ public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
-
-
- getdotnet.HRef = Constants.Version45URL;
-
userAgent.Text = HttpUtility.HtmlEncode(Request.UserAgent);
if (Request.QueryString["realversion"] != null)
{
View
13 SmallestDotNet/Default.aspx.designer.cs
@@ -21,13 +21,13 @@ public partial class _Default {
protected global::System.Web.UI.WebControls.Literal userResult;
/// <summary>
- /// getdotnet control.
+ /// developerOnline control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
- protected global::System.Web.UI.HtmlControls.HtmlAnchor getdotnet;
+ protected global::System.Web.UI.WebControls.Literal developerOnline;
/// <summary>
/// checkdotnet control.
@@ -48,15 +48,6 @@ public partial class _Default {
protected global::System.Web.UI.WebControls.Literal developerOfflineResult;
/// <summary>
- /// developerOnline control.
- /// </summary>
- /// <remarks>
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
- /// </remarks>
- protected global::System.Web.UI.WebControls.Literal developerOnline;
-
- /// <summary>
/// userAgent control.
/// </summary>
/// <remarks>
View
4 SmallestDotNet/SmallestDotNet.csproj
@@ -71,7 +71,9 @@
<Content Include="img\hero_home.jpg" />
<Content Include="js\bootstrap.min.js" />
<Content Include="testjs.html" />
- <Content Include="Web.config" />
+ <Content Include="Web.config">
+ <SubType>Designer</SubType>
+ </Content>
</ItemGroup>
<ItemGroup>
<Compile Include="Default.aspx.designer.cs">
View
8 SmallestDotNetLib/CLRVersion.cs
@@ -40,5 +40,13 @@ public class CLRVersion
/// </summary>
public string PrettyVersion { get; set; }
+
+ public override bool Equals(object obj)
+ {
+ var version = (CLRVersion)obj;
+
+ return version.Major == this.Major && version.Minor == this.Minor && version.Profile == this.Profile && version.ServicePack == this.ServicePack;
+ }
+
}
}
View
20 SmallestDotNetLib/CLRVersions.cs
@@ -9,16 +9,16 @@ namespace SmallestDotNetLib
/// </summary>
public class CLRVersions
{
- private static CLRVersion NET10Full = new CLRVersion() { Major = 1, Minor = 0, Profile = "full", PrettyVersion = ".NET 1.0" };
- private static CLRVersion NET11Full = new CLRVersion() { Major = 1, Minor = 1, Profile = "full", Url = Constants.Version11URL, PrettyVersion = ".NET 1.1" };
- private static CLRVersion NET20Full = new CLRVersion() { Major = 2, Minor = 0, Profile = "full", Url = Constants.Version20URL, PrettyVersion = ".NET 2.0" };
- private static CLRVersion NET30Full = new CLRVersion() { Major = 3, Minor = 0, Profile = "full", Url = Constants.Version30URL, PrettyVersion = ".NET 3.0" };
- private static CLRVersion NET35Full = new CLRVersion() { Major = 3, Minor = 5, Profile = "full", PrettyVersion = ".NET 3.5" };
- private static CLRVersion NET35SP1Client = new CLRVersion() { Major = 3, Minor = 5, Profile = "client", ServicePack = 1, Url = Constants.Version35SP1ClientURL, PrettyVersion = ".NET 3.5 Client SP1" };
- private static CLRVersion NET35SP1Full = new CLRVersion() { Major = 3, Minor = 5, Profile = "full", ServicePack = 1, Url = Constants.Version35SP1FullURL, PrettyVersion = ".NET 3.5 SP1" };
- private static CLRVersion NET40Client = new CLRVersion() { Major = 4, Minor = 0, Profile = "client", Url = Constants.Version40ClientURL, PrettyVersion = ".NET 4.0 Client" };
- private static CLRVersion NET40Full = new CLRVersion() { Major = 4, Minor = 0, Profile = "full", Url = Constants.Version40FullURL, PrettyVersion = ".NET 4.0" };
- private static CLRVersion NET45Full = new CLRVersion() { Major = 4, Minor = 5, Profile = "full", Url = Constants.Version45URL, PrettyVersion = ".NET 4.5" };
+ public static CLRVersion NET10Full = new CLRVersion() { Major = 1, Minor = 0, Profile = "full", PrettyVersion = ".NET 1.0" };
+ public static CLRVersion NET11Full = new CLRVersion() { Major = 1, Minor = 1, Profile = "full", Url = Constants.Version11URL, PrettyVersion = ".NET 1.1" };
+ public static CLRVersion NET20Full = new CLRVersion() { Major = 2, Minor = 0, Profile = "full", Url = Constants.Version20URL, PrettyVersion = ".NET 2.0" };
+ public static CLRVersion NET30Full = new CLRVersion() { Major = 3, Minor = 0, Profile = "full", Url = Constants.Version30URL, PrettyVersion = ".NET 3.0" };
+ public static CLRVersion NET35Full = new CLRVersion() { Major = 3, Minor = 5, Profile = "full", PrettyVersion = ".NET 3.5" };
+ public static CLRVersion NET35SP1Client = new CLRVersion() { Major = 3, Minor = 5, Profile = "client", ServicePack = 1, Url = Constants.Version35SP1ClientURL, PrettyVersion = ".NET 3.5 Client SP1" };
+ public static CLRVersion NET35SP1Full = new CLRVersion() { Major = 3, Minor = 5, Profile = "full", ServicePack = 1, Url = Constants.Version35SP1FullURL, PrettyVersion = ".NET 3.5 SP1" };
+ public static CLRVersion NET40Client = new CLRVersion() { Major = 4, Minor = 0, Profile = "client", Url = Constants.Version40ClientURL, PrettyVersion = ".NET 4.0 Client" };
+ public static CLRVersion NET40Full = new CLRVersion() { Major = 4, Minor = 0, Profile = "full", Url = Constants.Version40FullURL, PrettyVersion = ".NET 4.0" };
+ public static CLRVersion NET45Full = new CLRVersion() { Major = 4, Minor = 5, Profile = "full", Url = Constants.Version45URL, PrettyVersion = ".NET 4.5" };
/// <summary>
/// A Dictionary of CLR Versions with information
View
47 SmallestDotNetLib/OperatingSystemSupport.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace SmallestDotNetLib
+{
+ public class OperatingSystem
+ {
+ public string UserAgentVersion { get; set; }
+ public string PrettyVersion { get; set; }
+ public CLRVersion LatestCLRVersion { get; set; }
+ }
+
+ public class OperatingSystems
+ {
+ public static OperatingSystem Windows8 = new OperatingSystem() { UserAgentVersion = "Windows NT 6.2", PrettyVersion = "Windows 8", LatestCLRVersion = CLRVersions.NET45Full };
+ public static OperatingSystem Windows7 = new OperatingSystem() { UserAgentVersion = "Windows NT 6.1", PrettyVersion = "Windows 7", LatestCLRVersion = CLRVersions.NET45Full };
+ public static OperatingSystem WindowsVista = new OperatingSystem() { UserAgentVersion = "Windows NT 6.0", PrettyVersion = "Windows Vista", LatestCLRVersion = CLRVersions.NET45Full };
+ public static OperatingSystem WindowsXP64ORServer2003 = new OperatingSystem {UserAgentVersion = "Windows NT 5.2", PrettyVersion = "Windows XP x64, Windows Server 2003", LatestCLRVersion = CLRVersions.NET40Full };
+ public static OperatingSystem WindowsXP = new OperatingSystem() { UserAgentVersion = "Windows NT 5.1", PrettyVersion = "Windows XP", LatestCLRVersion = CLRVersions.NET40Full };
+ public static OperatingSystem Windows2000SP1 = new OperatingSystem() { UserAgentVersion = "Windows NT 5.01", PrettyVersion = "Windows 2000 SP1", LatestCLRVersion = CLRVersions.NET20Full };
+ public static OperatingSystem Windows2000 = new OperatingSystem() { UserAgentVersion = "Windows NT 5.0", PrettyVersion = "Windows 2000", LatestCLRVersion = CLRVersions.NET20Full };
+ public static OperatingSystem Windows98 = new OperatingSystem() { UserAgentVersion = "Windows 98", PrettyVersion = "Windows 98", LatestCLRVersion = CLRVersions.NET20Full };
+ public static OperatingSystem Macintosh = new OperatingSystem() { UserAgentVersion = "Mac", PrettyVersion = "Macintosh", LatestCLRVersion = null };
+ public static OperatingSystem UnixBased = new OperatingSystem() { UserAgentVersion = "nix", PrettyVersion = "Unix/Linux", LatestCLRVersion = null };
+
+ public static List<OperatingSystem> OSVersions = new List<OperatingSystem>
+ {
+ Windows8,
+ Windows7,
+ WindowsVista,
+ WindowsXP64ORServer2003,
+ WindowsXP,
+ Windows2000SP1,
+ Windows2000,
+ Windows98,
+ Macintosh,
+ UnixBased
+ };
+
+ public static OperatingSystem GetOperatingSystem(string UserAgent)
+ {
+ return OSVersions.FirstOrDefault(o => UserAgent.Contains(o.UserAgentVersion));
+ }
+
+ }
+}
View
1 SmallestDotNetLib/SmallestDotNetLib.csproj
@@ -47,6 +47,7 @@
<Compile Include="Constants.cs" />
<Compile Include="Helpers.cs" />
<Compile Include="JsonVersions.cs" />
+ <Compile Include="OperatingSystemSupport.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
View
68 SmallestTest/OperatingSystemVersionTests.cs
@@ -0,0 +1,68 @@
+using System;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using SmallestDotNetLib;
+
+namespace SmallestTest
+{
+ [TestClass]
+ public class OperatingSystemVersionTests
+ {
+ [TestMethod]
+ public void CheckNoMatch()
+ {
+ var UserAgent = "Apeture";
+
+ var actualOS = OperatingSystems.GetOperatingSystem(UserAgent);
+
+ Assert.IsNull(actualOS);
+
+ }
+
+
+ [TestMethod]
+ public void CheckWindows8()
+ {
+ var UserAgent = "Windows NT 6.2";
+ var Windows8OperatingSystem = OperatingSystems.Windows8;
+
+ var actualOS = OperatingSystems.GetOperatingSystem(UserAgent);
+
+ Assert.AreEqual(Windows8OperatingSystem, actualOS);
+ }
+
+ [TestMethod]
+ public void CheckWindows7()
+ {
+ var UserAgent = "Windows NT 6.1";
+ var Windows7OperatingSystem = OperatingSystems.Windows7;
+
+ var actualOS = OperatingSystems.GetOperatingSystem(UserAgent);
+
+ Assert.AreEqual(Windows7OperatingSystem, actualOS);
+ }
+
+ [TestMethod]
+ public void CheckWindowsVista()
+ {
+ var UserAgent = "Windows NT 6.0";
+ var WinodwsVistaOperatingSytem = OperatingSystems.WindowsVista;
+
+ var actualOS = OperatingSystems.GetOperatingSystem(UserAgent);
+
+ Assert.AreEqual(WinodwsVistaOperatingSytem, actualOS);
+ }
+
+ [TestMethod]
+ public void CheckoutWindowsServer2003()
+ {
+ var UserAgent = "Windows NT 5.2";
+ var WindowsServer2003OperatingSystem = OperatingSystems.WindowsXP64ORServer2003;
+
+ var actualOS = OperatingSystems.GetOperatingSystem(UserAgent);
+
+ Assert.AreEqual(WindowsServer2003OperatingSystem, actualOS);
+ }
+
+
+ }
+}
View
1 SmallestTest/SmallestTest.csproj
@@ -53,6 +53,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="JavascriptDomTests.cs" />
<Compile Include="CLRVersionDictionaryTests.cs" />
+ <Compile Include="OperatingSystemVersionTests.cs" />
<Compile Include="VersionCheckTest.cs" />
<Compile Include="VersionWriterTests.cs" />
</ItemGroup>

0 comments on commit 89c419e

Please sign in to comment.
Something went wrong with that request. Please try again.