From 06fdc15d30c856ec3d7f1c72dd1e825158d48729 Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Sun, 17 Dec 2023 19:41:24 -0800 Subject: [PATCH] General cleanup (#21) * Minor cleanup * git ignore fix --- .gitignore | 148 +++++++++++++++--- BrowserDetector.sln | 14 +- .../DetectorBenchmarks.cs | 3 +- .../BrowserDetector.WebApi.csproj} | 3 + .../Controllers/HomeController.cs | 30 ++++ .../Middlewares/BrowserDetectionMiddleware.cs | 21 +++ sample/BrowserDetector.WebApi/Program.cs | 26 +++ .../Properties/launchSettings.json | 26 +-- .../appsettings.Development.json | 8 + .../appsettings.json | 3 +- .../Controllers/HomeController.cs | 31 ---- sample/DemoApp.NET5/Program.cs | 26 --- sample/DemoApp.NET5/Startup.cs | 50 ------ .../DemoApp.NET5/appsettings.Development.json | 9 -- .../BrowserDetector.Net.csproj | 9 ++ .../Browsers/Chrome.cs | 2 +- src/BrowserDetector.NetCore/Browsers/Edge.cs | 2 +- .../Browsers/EdgeChromium.cs | 8 +- .../Browsers/InternetExplorer.cs | 2 +- src/BrowserDetector.NetCore/Browsers/Opera.cs | 2 +- .../Browsers/Safari.cs | 2 +- .../Constants/Constants.cs | 2 +- .../Detection/BrowserDetector.cs | 17 +- .../Detection/PlatformDetector.cs | 12 +- ...serDetectionServiceCollectionExtensions.cs | 12 +- .../BrowserDetector.Tests.csproj | 1 - 26 files changed, 277 insertions(+), 192 deletions(-) rename sample/{DemoApp.NET5/DemoApp.NET5.csproj => BrowserDetector.WebApi/BrowserDetector.WebApi.csproj} (65%) create mode 100644 sample/BrowserDetector.WebApi/Controllers/HomeController.cs create mode 100644 sample/BrowserDetector.WebApi/Middlewares/BrowserDetectionMiddleware.cs create mode 100644 sample/BrowserDetector.WebApi/Program.cs rename sample/{DemoApp.NET5 => BrowserDetector.WebApi}/Properties/launchSettings.json (71%) create mode 100644 sample/BrowserDetector.WebApi/appsettings.Development.json rename sample/{DemoApp.NET5 => BrowserDetector.WebApi}/appsettings.json (56%) delete mode 100644 sample/DemoApp.NET5/Controllers/HomeController.cs delete mode 100644 sample/DemoApp.NET5/Program.cs delete mode 100644 sample/DemoApp.NET5/Startup.cs delete mode 100644 sample/DemoApp.NET5/appsettings.Development.json diff --git a/.gitignore b/.gitignore index e91961f..2697326 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files +*.rsuser *.suo *.user *.userosscache @@ -10,6 +13,9 @@ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +# Mono auto generated files +mono_crash.* + # Build results [Dd]ebug/ [Dd]ebugPublic/ @@ -17,42 +23,63 @@ [Rr]eleases/ x64/ x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ bld/ [Bb]in/ [Oo]bj/ +[Oo]ut/ [Ll]og/ +[Ll]ogs/ -# Visual Studio 2015 cache/options directory +# Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot #wwwroot/ +# Visual Studio 2017 auto generated files +Generated\ Files/ + # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* -# NUNIT +# NUnit *.VisualState.xml TestResult.xml +nunit-*.xml # Build Results of an ATL Project [Dd]ebugPS/ [Rr]eleasePS/ dlldata.c -# DNX +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core project.lock.json project.fragment.lock.json artifacts/ +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio *_i.c *_p.c -*_i.h +*_h.h *.ilk *.meta *.obj +*.iobj *.pch *.pdb +*.ipdb *.pgc *.pgd *.rsp @@ -62,6 +89,7 @@ artifacts/ *.tlh *.tmp *.tmp_proj +*_wpftmp.csproj *.log *.vspscc *.vssscc @@ -90,6 +118,9 @@ ipch/ *.vspx *.sap +# Visual Studio Trace Files +*.e2e + # TFS 2012 Local Workspace $tf/ @@ -101,15 +132,25 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user -# JustCode is a .NET coding add-in -.JustCode - # TeamCity is a build add-in _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch _NCrunch_* .*crunch*.local.xml @@ -141,9 +182,9 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings +# Note: Comment the next line if you want to checkin your web deploy settings, # but database connection strings (with potential passwords) will be unencrypted -#*.pubxml +*.pubxml *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to @@ -153,13 +194,15 @@ PublishScripts/ # NuGet Packages *.nupkg +# NuGet Symbol Packages +*.snupkg # The packages folder can be ignored because of Package Restore -**/packages/* +**/[Pp]ackages/* # except build/, which is used as an MSBuild target. -!**/packages/build/ +!**/[Pp]ackages/build/ # Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files *.nuget.props *.nuget.targets @@ -176,12 +219,15 @@ AppPackages/ BundleArtifacts/ Package.StoreAssociation.xml _pkginfo.txt +*.appx +*.appxbundle +*.appxupload # Visual Studio cache files # files ending in .cache can be ignored *.[Cc]ache # but keep track of directories ending in .cache -!*.[Cc]ache/ +!?*.[Cc]ache/ # Others ClientBin/ @@ -192,9 +238,12 @@ ClientBin/ *.jfm *.pfx *.publishsettings -node_modules/ orleans.codegen.cs +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + # Since there are multiple workflows, uncomment next line to ignore bower_components # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) #bower_components/ @@ -209,15 +258,22 @@ _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak # SQL Server files *.mdf *.ldf +*.ndf # Business Intelligence projects *.rdl.data *.bim.layout *.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl # Microsoft Fakes FakesAssemblies/ @@ -227,6 +283,7 @@ FakesAssemblies/ # Node.js Tools for Visual Studio .ntvs_analysis.dat +node_modules/ # Visual Studio 6 build log *.plg @@ -234,6 +291,9 @@ FakesAssemblies/ # Visual Studio 6 workspace options file *.opt +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts @@ -249,14 +309,58 @@ paket-files/ # FAKE - F# Make .fake/ -# JetBrains Rider -.idea/ -*.sln.iml - -# CodeRush -.cr/ +# CodeRush personal settings +.cr/personal # Python Tools for Visual Studio (PTVS) __pycache__/ *.pyc -sample/DemoApp/Properties/PublishProfiles/browser-detection - Web Deploy.pubxml \ No newline at end of file + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# Rider +.idea/ \ No newline at end of file diff --git a/BrowserDetector.sln b/BrowserDetector.sln index f3275e9..a0a1b0e 100644 --- a/BrowserDetector.sln +++ b/BrowserDetector.sln @@ -15,10 +15,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "perf", "perf", "{5AB86EFC-4 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserDetector.Benchmarks", "perf\BrowserDetector.Benchmarks\BrowserDetector.Benchmarks.csproj", "{74E28CEE-CBE2-49DB-811A-B63E8FDD744E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoApp.NET5", "sample\DemoApp.NET5\DemoApp.NET5.csproj", "{FC9EDDF8-1A96-4814-87E4-4EEAF2BCFD39}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrowserDetector.Net", "src\BrowserDetector.NetCore\BrowserDetector.Net.csproj", "{2E0D3C7A-98AA-475A-816B-3B51EA377C6A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BrowserDetector.WebApi", "sample\BrowserDetector.WebApi\BrowserDetector.WebApi.csproj", "{6369627B-5878-4CFE-A996-859D8663603C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,14 +33,14 @@ Global {74E28CEE-CBE2-49DB-811A-B63E8FDD744E}.Debug|Any CPU.Build.0 = Debug|Any CPU {74E28CEE-CBE2-49DB-811A-B63E8FDD744E}.Release|Any CPU.ActiveCfg = Release|Any CPU {74E28CEE-CBE2-49DB-811A-B63E8FDD744E}.Release|Any CPU.Build.0 = Release|Any CPU - {FC9EDDF8-1A96-4814-87E4-4EEAF2BCFD39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FC9EDDF8-1A96-4814-87E4-4EEAF2BCFD39}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FC9EDDF8-1A96-4814-87E4-4EEAF2BCFD39}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FC9EDDF8-1A96-4814-87E4-4EEAF2BCFD39}.Release|Any CPU.Build.0 = Release|Any CPU {2E0D3C7A-98AA-475A-816B-3B51EA377C6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2E0D3C7A-98AA-475A-816B-3B51EA377C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU {2E0D3C7A-98AA-475A-816B-3B51EA377C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU {2E0D3C7A-98AA-475A-816B-3B51EA377C6A}.Release|Any CPU.Build.0 = Release|Any CPU + {6369627B-5878-4CFE-A996-859D8663603C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6369627B-5878-4CFE-A996-859D8663603C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6369627B-5878-4CFE-A996-859D8663603C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6369627B-5878-4CFE-A996-859D8663603C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -48,8 +48,8 @@ Global GlobalSection(NestedProjects) = preSolution {AC18FC9B-5E79-4FDA-9B35-9F2E716C2BD9} = {12F52172-93E2-490D-B544-6BC9BFCBDE4F} {74E28CEE-CBE2-49DB-811A-B63E8FDD744E} = {5AB86EFC-4E36-4570-BB16-C09AC8C71BAC} - {FC9EDDF8-1A96-4814-87E4-4EEAF2BCFD39} = {9E1E33C8-9F0A-42A5-909F-54079AB3AEF3} {2E0D3C7A-98AA-475A-816B-3B51EA377C6A} = {B909FEDF-3397-4308-B8E3-E538D84AC14D} + {6369627B-5878-4CFE-A996-859D8663603C} = {9E1E33C8-9F0A-42A5-909F-54079AB3AEF3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {05CFD6CC-3235-4365-8458-99DED6DBDE2D} diff --git a/perf/BrowserDetector.Benchmarks/DetectorBenchmarks.cs b/perf/BrowserDetector.Benchmarks/DetectorBenchmarks.cs index 4cc8b07..7427223 100644 --- a/perf/BrowserDetector.Benchmarks/DetectorBenchmarks.cs +++ b/perf/BrowserDetector.Benchmarks/DetectorBenchmarks.cs @@ -1,4 +1,5 @@ -namespace BrowserDetector.Benchmarks + +namespace BrowserDetector.Benchmarks { using System; using BenchmarkDotNet.Attributes; diff --git a/sample/DemoApp.NET5/DemoApp.NET5.csproj b/sample/BrowserDetector.WebApi/BrowserDetector.WebApi.csproj similarity index 65% rename from sample/DemoApp.NET5/DemoApp.NET5.csproj rename to sample/BrowserDetector.WebApi/BrowserDetector.WebApi.csproj index d7aff1f..6b67644 100644 --- a/sample/DemoApp.NET5/DemoApp.NET5.csproj +++ b/sample/BrowserDetector.WebApi/BrowserDetector.WebApi.csproj @@ -2,6 +2,9 @@ net8.0 + enable + enable + true diff --git a/sample/BrowserDetector.WebApi/Controllers/HomeController.cs b/sample/BrowserDetector.WebApi/Controllers/HomeController.cs new file mode 100644 index 0000000..9fbbf54 --- /dev/null +++ b/sample/BrowserDetector.WebApi/Controllers/HomeController.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNetCore.Mvc; +using Shyjus.BrowserDetection; + +namespace BrowserDetector.WebApi.Controllers +{ + [ApiController] + public class HomeController : ControllerBase + { + private readonly ILogger _logger; + private readonly IBrowserDetector _browserDetector; + public HomeController(IBrowserDetector browserDetector, ILogger logger) + { + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + _browserDetector = browserDetector ?? throw new ArgumentNullException(nameof(browserDetector)); + } + + [HttpGet] + [Route("")] + public string Get() + { + this._logger.LogInformation("Inside GET action method"); + + var browser = _browserDetector.Browser; + + _logger.LogInformation($"Browser:{browser?.Name},OS: {browser?.OS}"); + + return $".NET APP. Browser:{browser?.Name}, Version: {browser?.Version},Device type: {browser?.DeviceType}, OS: {browser?.OS}"; + } + } +} diff --git a/sample/BrowserDetector.WebApi/Middlewares/BrowserDetectionMiddleware.cs b/sample/BrowserDetector.WebApi/Middlewares/BrowserDetectionMiddleware.cs new file mode 100644 index 0000000..669ce3c --- /dev/null +++ b/sample/BrowserDetector.WebApi/Middlewares/BrowserDetectionMiddleware.cs @@ -0,0 +1,21 @@ +using Shyjus.BrowserDetection; + +namespace BrowserDetector.WebApi.Middlewares +{ + public class BrowserDetectionMiddleware + { + private RequestDelegate _next; + public BrowserDetectionMiddleware(RequestDelegate next) + { + _next = next; + } + public async Task InvokeAsync(HttpContext httpContext, IBrowserDetector browserDetector) + { + var browser = browserDetector.Browser; + + // to do: do something with the browser information + + await _next.Invoke(httpContext); + } + } +} diff --git a/sample/BrowserDetector.WebApi/Program.cs b/sample/BrowserDetector.WebApi/Program.cs new file mode 100644 index 0000000..d5a1eb2 --- /dev/null +++ b/sample/BrowserDetector.WebApi/Program.cs @@ -0,0 +1,26 @@ +using BrowserDetector.WebApi.Middlewares; + +namespace BrowserDetector.WebApi +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + + builder.Services.AddControllers(); + builder.Services.AddBrowserDetection(); + builder.Services.AddLogging(); + + var app = builder.Build(); + + app.MapControllers(); + + app.UseMiddleware(); + + app.Run(); + } + } +} diff --git a/sample/DemoApp.NET5/Properties/launchSettings.json b/sample/BrowserDetector.WebApi/Properties/launchSettings.json similarity index 71% rename from sample/DemoApp.NET5/Properties/launchSettings.json rename to sample/BrowserDetector.WebApi/Properties/launchSettings.json index 8f4fb9d..de2a069 100644 --- a/sample/DemoApp.NET5/Properties/launchSettings.json +++ b/sample/BrowserDetector.WebApi/Properties/launchSettings.json @@ -1,31 +1,31 @@ -{ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:47323", + "applicationUrl": "http://localhost:4608", "sslPort": 0 } }, - "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { - "IIS Express": { - "commandName": "IISExpress", + "http": { + "commandName": "Project", + "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "home", + "launchUrl": "", + "applicationUrl": "http://localhost:5261", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, - "DemoApp.NET5": { - "commandName": "Project", + "IIS Express": { + "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "home", + "launchUrl": "", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - }, - "dotnetRunMessages": "true", - "applicationUrl": "http://localhost:5000" + } } } -} \ No newline at end of file +} diff --git a/sample/BrowserDetector.WebApi/appsettings.Development.json b/sample/BrowserDetector.WebApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/sample/BrowserDetector.WebApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/sample/DemoApp.NET5/appsettings.json b/sample/BrowserDetector.WebApi/appsettings.json similarity index 56% rename from sample/DemoApp.NET5/appsettings.json rename to sample/BrowserDetector.WebApi/appsettings.json index d9d9a9b..10f68b8 100644 --- a/sample/DemoApp.NET5/appsettings.json +++ b/sample/BrowserDetector.WebApi/appsettings.json @@ -2,8 +2,7 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*" diff --git a/sample/DemoApp.NET5/Controllers/HomeController.cs b/sample/DemoApp.NET5/Controllers/HomeController.cs deleted file mode 100644 index 1d74a78..0000000 --- a/sample/DemoApp.NET5/Controllers/HomeController.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using System; -using Shyjus.BrowserDetection; - -namespace DemoApp.NET5.Controllers -{ - [ApiController] - [Route("[controller]")] - public class HomeController : ControllerBase - { - private readonly ILogger _logger; - private readonly IBrowserDetector browserDetector; - public HomeController(IBrowserDetector browserDetector, ILogger logger) - { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - this.browserDetector = browserDetector ?? throw new ArgumentNullException(nameof(browserDetector)); - } - - [HttpGet] - public string Get() - { - this._logger.LogInformation("Inside GET action method"); - - IBrowser browser = this.browserDetector.Browser; - - return $".NET APP. Browser:{browser.Name}, Version: {browser.Version},Device type: {browser.DeviceType}, OS: {browser.OS}"; - } - } - -} diff --git a/sample/DemoApp.NET5/Program.cs b/sample/DemoApp.NET5/Program.cs deleted file mode 100644 index d11df8d..0000000 --- a/sample/DemoApp.NET5/Program.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DemoApp.NET5 -{ - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } -} diff --git a/sample/DemoApp.NET5/Startup.cs b/sample/DemoApp.NET5/Startup.cs deleted file mode 100644 index 407456a..0000000 --- a/sample/DemoApp.NET5/Startup.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace DemoApp.NET5 -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddHttpContextAccessor(); - services.AddBrowserDetection(); - services.AddControllers(); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } - } -} diff --git a/sample/DemoApp.NET5/appsettings.Development.json b/sample/DemoApp.NET5/appsettings.Development.json deleted file mode 100644 index 8983e0f..0000000 --- a/sample/DemoApp.NET5/appsettings.Development.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/src/BrowserDetector.NetCore/BrowserDetector.Net.csproj b/src/BrowserDetector.NetCore/BrowserDetector.Net.csproj index 310e2a8..184235c 100644 --- a/src/BrowserDetector.NetCore/BrowserDetector.Net.csproj +++ b/src/BrowserDetector.NetCore/BrowserDetector.Net.csproj @@ -2,6 +2,15 @@ net6.0;net7.0;net8.0 + Shyjus.BrowserDetector + Shyjus.BrowserDetector + Shyjus.BrowserDetector + Shyju Krishnankutty + Browser detection, device detection and operating system detection capabilities in asp.net core. + https://github.com/kshyju/BrowserDetector + BrowserDetection BrowserCapabilities BrowserDetectionASP.NETCore HttpContext.Request.Browser DeviceDetection + true + 2.0.1-preview1 diff --git a/src/BrowserDetector.NetCore/Browsers/Chrome.cs b/src/BrowserDetector.NetCore/Browsers/Chrome.cs index c9aeac2..6de31d9 100644 --- a/src/BrowserDetector.NetCore/Browsers/Chrome.cs +++ b/src/BrowserDetector.NetCore/Browsers/Chrome.cs @@ -9,7 +9,7 @@ /// internal class Chrome : Browser { - public Chrome(ReadOnlySpan userAgent, string version) + private Chrome(ReadOnlySpan userAgent, string version) : base(userAgent, version) { } diff --git a/src/BrowserDetector.NetCore/Browsers/Edge.cs b/src/BrowserDetector.NetCore/Browsers/Edge.cs index a840783..8d4ad44 100644 --- a/src/BrowserDetector.NetCore/Browsers/Edge.cs +++ b/src/BrowserDetector.NetCore/Browsers/Edge.cs @@ -7,7 +7,7 @@ /// internal class Edge : Browser { - public Edge(ReadOnlySpan userAgent, string version) + private Edge(ReadOnlySpan userAgent, string version) : base(userAgent, version) { } diff --git a/src/BrowserDetector.NetCore/Browsers/EdgeChromium.cs b/src/BrowserDetector.NetCore/Browsers/EdgeChromium.cs index 73154a4..e18d074 100644 --- a/src/BrowserDetector.NetCore/Browsers/EdgeChromium.cs +++ b/src/BrowserDetector.NetCore/Browsers/EdgeChromium.cs @@ -1,4 +1,8 @@ -namespace Shyjus.BrowserDetection +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("BrowserDetector.Tests")] + +namespace Shyjus.BrowserDetection { using System; @@ -7,7 +11,7 @@ /// internal class EdgeChromium : Browser { - public EdgeChromium(ReadOnlySpan userAgent, string version) + private EdgeChromium(ReadOnlySpan userAgent, string version) : base(userAgent, version) { } diff --git a/src/BrowserDetector.NetCore/Browsers/InternetExplorer.cs b/src/BrowserDetector.NetCore/Browsers/InternetExplorer.cs index e730b07..a3ae4e4 100644 --- a/src/BrowserDetector.NetCore/Browsers/InternetExplorer.cs +++ b/src/BrowserDetector.NetCore/Browsers/InternetExplorer.cs @@ -7,7 +7,7 @@ /// internal class InternetExplorer : Browser { - public InternetExplorer(ReadOnlySpan userAgent, string version) + private protected InternetExplorer(ReadOnlySpan userAgent, string version) : base(userAgent, version) { } diff --git a/src/BrowserDetector.NetCore/Browsers/Opera.cs b/src/BrowserDetector.NetCore/Browsers/Opera.cs index e73ac51..e7082be 100644 --- a/src/BrowserDetector.NetCore/Browsers/Opera.cs +++ b/src/BrowserDetector.NetCore/Browsers/Opera.cs @@ -7,7 +7,7 @@ /// internal class Opera : Browser { - public Opera(ReadOnlySpan userAgent, string version) + private protected Opera(ReadOnlySpan userAgent, string version) : base(userAgent, version) { } diff --git a/src/BrowserDetector.NetCore/Browsers/Safari.cs b/src/BrowserDetector.NetCore/Browsers/Safari.cs index f905481..19d1697 100644 --- a/src/BrowserDetector.NetCore/Browsers/Safari.cs +++ b/src/BrowserDetector.NetCore/Browsers/Safari.cs @@ -4,7 +4,7 @@ internal class Safari : Browser { - public Safari(ReadOnlySpan userAgent, string version) + private Safari(ReadOnlySpan userAgent, string version) : base(userAgent, version) { } diff --git a/src/BrowserDetector.NetCore/Constants/Constants.cs b/src/BrowserDetector.NetCore/Constants/Constants.cs index c1c4dfd..c2252fb 100644 --- a/src/BrowserDetector.NetCore/Constants/Constants.cs +++ b/src/BrowserDetector.NetCore/Constants/Constants.cs @@ -1,6 +1,6 @@ namespace Shyjus.BrowserDetection { - internal class Headers + internal static class Headers { public const string UserAgent = "User-Agent"; } diff --git a/src/BrowserDetector.NetCore/Detection/BrowserDetector.cs b/src/BrowserDetector.NetCore/Detection/BrowserDetector.cs index e6e4ad6..853c3c1 100644 --- a/src/BrowserDetector.NetCore/Detection/BrowserDetector.cs +++ b/src/BrowserDetector.NetCore/Detection/BrowserDetector.cs @@ -9,9 +9,9 @@ namespace Shyjus.BrowserDetection /// public sealed class BrowserDetector : IBrowserDetector { - private readonly Lazy browser; + private readonly Lazy _browser; - private readonly IHttpContextAccessor httpContextAccessor; + private readonly IHttpContextAccessor _httpContextAccessor; /// /// Initializes a new instance of the class. @@ -19,21 +19,18 @@ public sealed class BrowserDetector : IBrowserDetector /// The IHttpContextAccessor instance. public BrowserDetector(IHttpContextAccessor httpContextAccessor) { - this.httpContextAccessor = httpContextAccessor; - this.browser = this.GetBrowserLazy(); + _httpContextAccessor = httpContextAccessor; + _browser = this.GetBrowserLazy(); } /// /// Gets the browser information. /// - public IBrowser? Browser => this.browser.Value; + public IBrowser? Browser => _browser.Value; private Lazy GetBrowserLazy() { - return new Lazy(() => - { - return GetBrowser(); - }); + return new Lazy(GetBrowser); } /// @@ -42,7 +39,7 @@ public BrowserDetector(IHttpContextAccessor httpContextAccessor) /// The IBrowser instance. private IBrowser? GetBrowser() { - if (this.httpContextAccessor.HttpContext?.Request?.Headers?.TryGetValue(Headers.UserAgent, out var uaHeader) == true) + if (_httpContextAccessor.HttpContext?.Request?.Headers?.TryGetValue(Headers.UserAgent, out var uaHeader) == true) { return Detector.GetBrowser(uaHeader[0].AsSpan()); } diff --git a/src/BrowserDetector.NetCore/Detection/PlatformDetector.cs b/src/BrowserDetector.NetCore/Detection/PlatformDetector.cs index 0746af0..578ad55 100644 --- a/src/BrowserDetector.NetCore/Detection/PlatformDetector.cs +++ b/src/BrowserDetector.NetCore/Detection/PlatformDetector.cs @@ -12,10 +12,10 @@ internal static (string Platform, string OS, bool MobileDetected) GetPlatformAnd // Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537. // Platform starts with a "(". So get it's index - var platformSearhKeyStartIndex = " (".AsSpan(); + var platformSearchKeyStartIndex = " (".AsSpan(); // The index of substring where platform part starts - var platformSubstringStartIndex = userAgentString.IndexOf(platformSearhKeyStartIndex) + platformSearhKeyStartIndex.Length; + var platformSubstringStartIndex = userAgentString.IndexOf(platformSearchKeyStartIndex) + platformSearchKeyStartIndex.Length; // Get substring which starts with platform part (Trim out anything before platform) var platformSubstring = userAgentString.Slice(platformSubstringStartIndex); @@ -42,25 +42,25 @@ internal static (string Platform, string OS, bool MobileDetected) GetPlatformAnd // Get the OS part slice var operatingSystemSlice = osSubString.Slice(0, osPartEndIndex); - // If OS part starts with "Linux", check for next segment to get android veersion //Linux; Android 9; Pixel 3 + // If OS part starts with "Linux", check for next segment to get android version //Linux; Android 9; Pixel 3 // Linux; Android 8.1.0; SM-T835 var platform = platformSlice.ToString(); var isMobileSlicePresent = userAgentString.IndexOf("Mobile".AsSpan()) > -1; - var os = GetReadableOSName(platform, operatingSystemSlice.ToString()); + var os = GetReadableOsName(platform, operatingSystemSlice.ToString()); return (Platform: platform, OS: os, MobileDetected: isMobileSlicePresent); } /// /// Gets a readable OS name from the platform & operatingSystem info. - /// For some cases, the "operatingSystem" param value is not enought and we rely on the platform param value. + /// For some cases, the "operatingSystem" param value is not enough and we rely on the platform param value. /// /// /// /// The OS name. - private static string GetReadableOSName(string platform, string operatingSystem) + private static string GetReadableOsName(string platform, string operatingSystem) { if (platform == Platforms.iPhone || platform == Platforms.iPad) { diff --git a/src/BrowserDetector.NetCore/Extensions/BrowserDetectionServiceCollectionExtensions.cs b/src/BrowserDetector.NetCore/Extensions/BrowserDetectionServiceCollectionExtensions.cs index c0c07b7..cfa7641 100644 --- a/src/BrowserDetector.NetCore/Extensions/BrowserDetectionServiceCollectionExtensions.cs +++ b/src/BrowserDetector.NetCore/Extensions/BrowserDetectionServiceCollectionExtensions.cs @@ -1,10 +1,10 @@ -namespace Microsoft.Extensions.DependencyInjection -{ - using Microsoft.AspNetCore.Http; - using Microsoft.Extensions.DependencyInjection.Extensions; - using Shyjus.BrowserDetection; - using System; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Shyjus.BrowserDetection; +using System; +namespace Microsoft.Extensions.DependencyInjection +{ /// /// Extension methods for setting up browser detection services in an . /// diff --git a/tests/BrowserDetector.Tests/BrowserDetector.Tests.csproj b/tests/BrowserDetector.Tests/BrowserDetector.Tests.csproj index dde3578..27b09b2 100644 --- a/tests/BrowserDetector.Tests/BrowserDetector.Tests.csproj +++ b/tests/BrowserDetector.Tests/BrowserDetector.Tests.csproj @@ -7,7 +7,6 @@ false - browserdetectortests.pfx