From f04f7811536ba6e35c4ad6357fb6904826eda9dc Mon Sep 17 00:00:00 2001 From: Dan Volchek Date: Sun, 25 Aug 2019 17:21:03 -0700 Subject: rename namespace to be more accurate --- .../ClientPlatformMiddleware.cs | 52 ++++++++++++++++++++++ .../ClientPlatformMiddlewareExtensions.cs | 16 +++++++ .../Framework/ClientPlatformDetection/Platform.cs | 18 ++++++++ .../UserAgentParsing/ClientPlatformMiddleware.cs | 52 ---------------------- .../ClientPlatformMiddlewareExtensions.cs | 16 ------- .../Framework/UserAgentParsing/Platform.cs | 18 -------- src/SMAPI.Web/Startup.cs | 2 +- src/SMAPI.Web/Views/LogParser/Index.cshtml | 2 +- 8 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs create mode 100644 src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs create mode 100644 src/SMAPI.Web/Framework/ClientPlatformDetection/Platform.cs delete mode 100644 src/SMAPI.Web/Framework/UserAgentParsing/ClientPlatformMiddleware.cs delete mode 100644 src/SMAPI.Web/Framework/UserAgentParsing/ClientPlatformMiddlewareExtensions.cs delete mode 100644 src/SMAPI.Web/Framework/UserAgentParsing/Platform.cs (limited to 'src') diff --git a/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs b/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs new file mode 100644 index 00000000..2430d239 --- /dev/null +++ b/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs @@ -0,0 +1,52 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; + +namespace StardewModdingAPI.Web.Framework.ClientPlatformDetection +{ + /// Middleware that detects the client's platform. + public class ClientPlatformMiddleware + { + /// The key used to retrieve the client's platform from . + public const string ClientPlatformKey = "ClientPlatformKey"; + + /// The next delegate in the middleware pipeline. + private readonly RequestDelegate Next; + + /// Construct an instance. + /// The next delegate in the middleware pipeline. + public ClientPlatformMiddleware(RequestDelegate next) + { + this.Next = next; + } + + /// Invoke the middleware. + /// The HTTP request context. + public async Task InvokeAsync(HttpContext context) + { + context.Items[ClientPlatformMiddleware.ClientPlatformKey] = this.DetectClientPlatform(context.Request.Headers["User-Agent"]); + + await this.Next(context); + } + + /// Detect the platform that the client is on. + /// The client's user agent. + /// The client's platform, or null if no platforms could be detected. + private Platform? DetectClientPlatform(string userAgent) + { + switch (userAgent) + { + case string ua when ua.Contains("Windows"): + return Platform.Windows; + // check for Android before Linux because Android user agents also contain Linux + case string ua when ua.Contains("Android"): + return Platform.Android; + case string ua when ua.Contains("Linux"): + return Platform.Linux; + case string ua when ua.Contains("Mac"): + return Platform.Mac; + default: + return null; + } + } + } +} diff --git a/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs b/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs new file mode 100644 index 00000000..274e5486 --- /dev/null +++ b/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Builder; + +namespace StardewModdingAPI.Web.Framework.ClientPlatformDetection +{ + /// Extension methods for the client platform middleware. + internal static class ClientPlatformMiddlewareExtensions + { + /// Adds client platform detection to the request pipeline. + /// The application builder. + /// The application builder with the client platform middleware enabled. + public static IApplicationBuilder UseClientPlatform(this IApplicationBuilder builder) + { + return builder.UseMiddleware(); + } + } +} diff --git a/src/SMAPI.Web/Framework/ClientPlatformDetection/Platform.cs b/src/SMAPI.Web/Framework/ClientPlatformDetection/Platform.cs new file mode 100644 index 00000000..2fe1d324 --- /dev/null +++ b/src/SMAPI.Web/Framework/ClientPlatformDetection/Platform.cs @@ -0,0 +1,18 @@ +namespace StardewModdingAPI.Web.Framework.ClientPlatformDetection +{ + /// A software platform. + public enum Platform + { + /// The Android platform. + Android, + + /// The Linux platform. + Linux, + + /// The Mac platform. + Mac, + + /// The Windows platform. + Windows + } +} diff --git a/src/SMAPI.Web/Framework/UserAgentParsing/ClientPlatformMiddleware.cs b/src/SMAPI.Web/Framework/UserAgentParsing/ClientPlatformMiddleware.cs deleted file mode 100644 index d056d85c..00000000 --- a/src/SMAPI.Web/Framework/UserAgentParsing/ClientPlatformMiddleware.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; - -namespace StardewModdingAPI.Web.Framework.UserAgentParsing -{ - /// Middleware that detects the client's platform. - public class ClientPlatformMiddleware - { - /// The key used to retrieve the client's platform from . - public const string ClientPlatformKey = "ClientPlatformKey"; - - /// The next delegate in the middleware pipeline. - private readonly RequestDelegate Next; - - /// Construct an instance. - /// The next delegate in the middleware pipeline. - public ClientPlatformMiddleware(RequestDelegate next) - { - this.Next = next; - } - - /// Invoke the middleware. - /// The HTTP request context. - public async Task InvokeAsync(HttpContext context) - { - context.Items[ClientPlatformMiddleware.ClientPlatformKey] = this.DetectClientPlatform(context.Request.Headers["User-Agent"]); - - await this.Next(context); - } - - /// Detect the platform that the client is on. - /// The client's user agent. - /// The client's platform, or null if no platforms could be detected. - private Platform? DetectClientPlatform(string userAgent) - { - switch (userAgent) - { - case string ua when ua.Contains("Windows"): - return Platform.Windows; - // check for Android before Linux because Android user agents also contain Linux - case string ua when ua.Contains("Android"): - return Platform.Android; - case string ua when ua.Contains("Linux"): - return Platform.Linux; - case string ua when ua.Contains("Mac"): - return Platform.Mac; - default: - return null; - } - } - } -} diff --git a/src/SMAPI.Web/Framework/UserAgentParsing/ClientPlatformMiddlewareExtensions.cs b/src/SMAPI.Web/Framework/UserAgentParsing/ClientPlatformMiddlewareExtensions.cs deleted file mode 100644 index 4ac2ebfa..00000000 --- a/src/SMAPI.Web/Framework/UserAgentParsing/ClientPlatformMiddlewareExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Builder; - -namespace StardewModdingAPI.Web.Framework.UserAgentParsing -{ - /// Extension methods for the client platform middleware. - internal static class ClientPlatformMiddlewareExtensions - { - /// Adds client platform detection to the request pipeline. - /// The application builder. - /// The application builder with the client platform middleware enabled. - public static IApplicationBuilder UseClientPlatform(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } - } -} diff --git a/src/SMAPI.Web/Framework/UserAgentParsing/Platform.cs b/src/SMAPI.Web/Framework/UserAgentParsing/Platform.cs deleted file mode 100644 index 07a247cb..00000000 --- a/src/SMAPI.Web/Framework/UserAgentParsing/Platform.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace StardewModdingAPI.Web.Framework.UserAgentParsing -{ - /// A software platform. - public enum Platform - { - /// The Android platform. - Android, - - /// The Linux platform. - Linux, - - /// The Mac platform. - Mac, - - /// The Windows platform. - Windows - } -} diff --git a/src/SMAPI.Web/Startup.cs b/src/SMAPI.Web/Startup.cs index 04ec47a6..e12fa63b 100644 --- a/src/SMAPI.Web/Startup.cs +++ b/src/SMAPI.Web/Startup.cs @@ -15,6 +15,7 @@ using StardewModdingAPI.Web.Framework; using StardewModdingAPI.Web.Framework.Caching; using StardewModdingAPI.Web.Framework.Caching.Mods; using StardewModdingAPI.Web.Framework.Caching.Wiki; +using StardewModdingAPI.Web.Framework.ClientPlatformDetection; using StardewModdingAPI.Web.Framework.Clients.Chucklefish; using StardewModdingAPI.Web.Framework.Clients.GitHub; using StardewModdingAPI.Web.Framework.Clients.ModDrop; @@ -23,7 +24,6 @@ using StardewModdingAPI.Web.Framework.Clients.Pastebin; using StardewModdingAPI.Web.Framework.Compression; using StardewModdingAPI.Web.Framework.ConfigModels; using StardewModdingAPI.Web.Framework.RewriteRules; -using StardewModdingAPI.Web.Framework.UserAgentParsing; namespace StardewModdingAPI.Web { diff --git a/src/SMAPI.Web/Views/LogParser/Index.cshtml b/src/SMAPI.Web/Views/LogParser/Index.cshtml index 0dca003b..7f8036db 100644 --- a/src/SMAPI.Web/Views/LogParser/Index.cshtml +++ b/src/SMAPI.Web/Views/LogParser/Index.cshtml @@ -1,6 +1,6 @@ @using Newtonsoft.Json +@using StardewModdingAPI.Web.Framework.ClientPlatformDetection @using StardewModdingAPI.Web.Framework.LogParsing.Models -@using StardewModdingAPI.Web.Framework.UserAgentParsing @model StardewModdingAPI.Web.ViewModels.LogParserModel @{ -- cgit