From e7b214390a09fc6edc7664bce0b48cecf1d986a8 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 31 Aug 2019 16:27:36 -0400 Subject: move platform to log parser model instead of middleware --- .../ClientPlatformMiddleware.cs | 53 ---------------------- .../ClientPlatformMiddlewareExtensions.cs | 16 ------- 2 files changed, 69 deletions(-) delete mode 100644 src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs delete mode 100644 src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs (limited to 'src/SMAPI.Web/Framework') diff --git a/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs b/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs deleted file mode 100644 index 2bf23ff9..00000000 --- a/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddleware.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using StardewModdingAPI.Toolkit.Utilities; - -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 deleted file mode 100644 index 274e5486..00000000 --- a/src/SMAPI.Web/Framework/ClientPlatformDetection/ClientPlatformMiddlewareExtensions.cs +++ /dev/null @@ -1,16 +0,0 @@ -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(); - } - } -} -- cgit