Skip to content

Commit

Permalink
Return response object from GetUpdateInformation
Browse files Browse the repository at this point in the history
Return an Response class with strongly typed properties for
VersionCanBeDetermined and CanRunCheckApp.
Enables removal of "This is the worst thing I've ever done..." comment
  • Loading branch information
marcosnz committed Apr 7, 2015
1 parent fefae55 commit 83cabc9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
36 changes: 21 additions & 15 deletions SmallestDotNet/Default.aspx.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
using System;
using System.Web;

using SmallestDotNetLib;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string userAgentText;
bool runFromChecker = false;
userAgent.Text = HttpUtility.HtmlEncode(Request.UserAgent);

if (Request.QueryString["realversion"] != null)
{
userResult.Text = Helpers.GetUpdateInformation(Request.QueryString["realversion"], Request.Browser.ClrVersion);
userAgentText = this.Request.QueryString["realversion"];
runFromChecker = true;
}
else
{
userResult.Text = Helpers.GetUpdateInformation(Request.UserAgent, Request.Browser.ClrVersion);
userAgentText = this.Request.UserAgent;
}

UpdateInformationResponse response = Helpers.GetUpdateInformation(userAgentText, this.Request.Browser.ClrVersion);

userResult.Text = response.Text;
developerOnline.Text = String.Format(@"If your users have internet connectivity, the .NET Framework is only between {1} and {2} megs. Why such a wide range? Well, it depends on if they already have some version of .NET.
If you point your users to the online setup for the {0}, that {3} MB download will automatically detect and download the smallest archive possible to get the job done.", Constants.DotNetOnline, Constants.DotNetOfflineMB - Constants.Version3OfflineMB, Constants.DotNetOfflineMB, Constants.DotNetOnlineMB);

developerOfflineResult.Text = String.Format(@"If you are a developer and are distributing your code on CD or DVD, you might want to download the
{0} on your media. The download is about {1} MB", Constants.DotNetOffline, Constants.DotNetOfflineMB);
getdotnet.Visible = response.VersionCanBeDetermined;
checkdotnet.Visible = response.CanRunCheckApp;

if (userResult.Text.Contains("can't")) //This is the worst thing I've ever done. We will fix it soon.
{
getdotnet.Visible = false;
checkdotnet.Visible = true;
}

if (userResult.Text.Contains("Mac") || userResult.Text.Contains("Linux")) //No, THIS is the worst thing I've ever done. We will fix it soon.
{
getdotnet.Visible = false;
checkdotnet.Visible = false;
}

// Hide the 4.5 checker section if
// (a) we can't determine the dotnet version or
// (b) we're on an OS that doesn't support .Net or
// (c) the user has already run the checker so we know exactly what version they're on.
// Note that the checkdotnet section in the header will still be displayed as long as the OS supports it
dotnet45.Visible = response.VersionCanBeDetermined && response.CanRunCheckApp && !runFromChecker;
}

}
2 changes: 1 addition & 1 deletion SmallestDotNet/VersionCheck.ashx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void ProcessRequest(HttpContext context)
var netVersions = userAgent.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).Where(s => s.Contains(".NET CLR"));
Version version = GetNetVersion(netVersions);
context.Response.ContentType = "text/plain";
context.Response.Write(Helpers.GetUpdateInformation(userAgent, version));
context.Response.Write(Helpers.GetUpdateInformation(userAgent, version).Text);
}
}

Expand Down
4 changes: 2 additions & 2 deletions SmallestDotNet/javascript.ashx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class SmallestDotNet : IHttpHandler
public void ProcessRequest(HttpContext context)
{
WriteToResponse("<span class=\"smallerdotnet\">");
context.Response.ContentType = "text/javascript";
context.Response.ContentType = "text/javascript";

WriteToResponse(Helpers.GetUpdateInformation(context.Request.UserAgent, context.Request.Browser.ClrVersion).Replace("'", @"\'").Replace(Environment.NewLine, "<br />"));
WriteToResponse(Helpers.GetUpdateInformation(context.Request.UserAgent, context.Request.Browser.ClrVersion).Text.Replace("'", @"\'").Replace(Environment.NewLine, "<br />"));
WriteToResponse("</span>");
}

Expand Down
13 changes: 13 additions & 0 deletions SmallestDotNetLib/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,32 @@
/// </summary>
public class Helpers
{
public static UpdateInformationResponse GetUpdateInformation(string UserAgent, Version version)
{
bool net4 = false;
string netInfoString = "";
var response = new UpdateInformationResponse();

// We should check this first since we don't need to check .NET versions if they can't have .NET versions
// Check for windows phone first as it may contain 'Mac' in User Agent
if (UserAgent.Contains("Windows Phone"))
{
response.Text = "It looks like you're running a Windows Phone, awesome! There's no .NET Framework download for the Windows phone, but you might check out <a href=\"https://dev.windows.com/\"/>the Windows Dev Center</a> or <a href=\"http://www.windowsphone.com/store/\"/>the Windows Phone Store</a>";
return response;
}
if (UserAgent.Contains("Mac"))
{
response.Text = "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 response;
}
if (UserAgent.Contains("nix"))
{
response.Text = "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 response;
}

response.CanRunCheckApp = true;
response.VersionCanBeDetermined = true;

net4 = GetWindows8Message(UserAgent, ref netInfoString) || Get40Message(UserAgent, ref netInfoString);
if (Helpers.Has35(UserAgent) || Helpers.Has35SP1C(UserAgent) || Helpers.Has35SP1E(UserAgent))
Expand Down Expand Up @@ -60,6 +70,7 @@ public class Helpers
netInfoString += UnknownBrowserMessage();
}

response.VersionCanBeDetermined = false;
}

//need to see if windows 2000 has the latest version
Expand All @@ -68,6 +79,8 @@ public class Helpers
netInfoString += CheckDotNet3_5UnSupportedOs(UserAgent, windowsVersion.Key, windowsVersion.Value);
}

response.Text = netInfoString;
return response;
}

private static bool GetWindows8Message(string UserAgent, ref string userMessage)
Expand Down
1 change: 1 addition & 0 deletions SmallestDotNetLib/SmallestDotNetLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<Compile Include="JsonVersions.cs" />
<Compile Include="OperatingSystemSupport.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UpdateInformationResponse.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
Expand Down

0 comments on commit 83cabc9

Please sign in to comment.