# Detection **Repository Path**: leeolevis/Detection ## Basic Information - **Project Name**: Detection - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-31 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ASP.NET Core Detection [![Financial Contributors on Open Collective](https://opencollective.com/wangkanai/all/badge.svg?label=financial+contributors)](https://opencollective.com/wangkanai) [![Build status](https://ci.appveyor.com/api/projects/status/033qv4nqv8g4altq?svg=true&retina=true)](https://ci.appveyor.com/project/wangkanai/detection) - **Wangkanai.Detection** [![NuGet Badge](https://buildstats.info/nuget/wangkanai.detection)](https://www.nuget.org/packages/wangkanai.detection) [![NuGet Badge](https://buildstats.info/nuget/wangkanai.detection?includePreReleases=true)](https://www.nuget.org/packages/wangkanai.detection) [![MyGet Badge](https://buildstats.info/myget/wangkanai/Wangkanai.detection)](https://www.myget.org/feed/wangkanai/package/nuget/Wangkanai.detection) - **Wangkanai.Responsive** [![NuGet Badge](https://buildstats.info/nuget/wangkanai.Responsive)](https://www.nuget.org/packages/wangkanai.detection) [![NuGet Badge](https://buildstats.info/nuget/wangkanai.Responsive?includePreReleases=true)](https://www.nuget.org/packages/wangkanai.Responsive) [![MyGet Badge](https://buildstats.info/myget/wangkanai/Wangkanai.Responsive)](https://www.myget.org/feed/wangkanai/package/nuget/Wangkanai.Responsive) [![Build history](https://buildstats.info/appveyor/chart/wangkanai/detection)](https://ci.appveyor.com/project/wangkanai/detection/history) ASP.NET Core client web browser detection extension to resolve devices, platforms, engine of the client. ASP.NET Core Responsive middleware for routing base upon request client device detection to specific view ![ASP.NET Core Responsive](https://raw.githubusercontent.com/wangkanai/Detection/dev/asset/aspnet-core-detection-2.svg?sanitize=true) ## Installation Installation of detection library is now done with a single package reference point. ```powershell PM> install-package Wangkanai.Detection ``` Installation of Responsive library will bring in all dependency packages (This will include `Wangkanai.Detection.Device). ```powershell PM> install-package Wangkanai.Responsive ``` ## Configuration This library host the component to resolve the access client device type. Implement of the library into your web application is done by configuring the `Startup.cs` by adding the detection service in the `ConfigureServices` method. ```csharp public void ConfigureServices(IServiceCollection services) { // Add detection services container and device resolver service. services.AddDetection(); // Add framework services. services.AddMvc(); } ``` * `AddDetection()` Adds the detection services to the services container. If you would like to add Responsive is configured in the `ConfigureServices` method also: ```csharp public void ConfigureServices(IServiceCollection services) { // Add responsive services. services.AddResponsive(); // Add framework services. services.AddMvc(); } ``` Or you can customize the responsive ```csharp public void ConfigureServices(IServiceCollection services) { // Add responsive services. services.AddResponsive(options => { options.View.DefaultTablet = DeviceType.Desktop; options.View.DefaultMobile = DeviceType.Desktop; options.View.DefaultDesktop = DeviceType.Desktop; }); // Add framework services. services.AddMvc(); } ``` * `AddResponsive()` Adds the Responsive services to the services container. * **Suffix** Ex `*views/[controller]/[action]/index.mobile.cshtml*` * **SubFoler** Ex `*views/[controller]/[action]/mobile/index.cshtml*` The current device on a request is set in the Responsive middleware. The Responsive middleware is enabled in the `Configure` method of *Startup.cs* file. ```csharp public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseResponsive(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); } ``` ## Global Resolver This library host the component to resolve all the access client related resolver that could resolve. Example of calling the detection service in the `Controller` using dependency injection. ```csharp public class HomeController : Controller { private readonly IDetection _detection; public HomeController(IDetection detection) { _detection = detection; } public IActionResult Index() { return View(_detection); } } ``` * `IDetection` is main service for you to access detection service. When the `Detection` is pass to the view you can render results like the following example. ```html @model Wangkanai.Detection.Detection

UserAgent

@Model.UserAgent

Results

Resolver Type Version
Device @Model.Device?.Type.ToString()
Browser @Model.Browser?.Type.ToString() @Model.Browser?.Version
Platform @Model.Platform?.Type.ToString() @Model.Platform?.Version
Engine @Model.Engine?.Type.ToString() @Model.Engine?.Version
Crawler @Model.Crawler?.Type.ToString() @Model.Crawler?.Version
``` ## Device Resolver This library host the component to resolve the access client device type. Example of calling the detection service in the `Controller` using dependency injection. ```csharp public class HomeController : Controller { private readonly IUserAgent _useragent; private readonly IDevice _device; public HomeController(IDeviceResolver deviceResolver) { _useragent = deviceResolver.UserAgent; _device = deviceResolver.Device; } public IActionResult Index() { return View(); } } ``` ## Browser Resolver This library host the component to resolve the access client browser type and version. Example of calling the detection service in the `Controller` using dependency injection. ```csharp public class HomeController : Controller { private readonly IUserAgent _useragent; private readonly IBrowser _browser; public HomeController(IBrowserResolver browserResolver) { _useragent = browserResolver.UserAgent; _browser = browserResolver.Browser; } public IActionResult Index() { return View(); } } ``` ## Crawler Resolver This library host the component to resolve the access client crawler type and version. Example of calling the detection service in the `Controller` using dependency injection. ```csharp public class HomeController : Controller { private readonly IUserAgent _useragent; private readonly ICrawler _crawler; public HomeController(ICrawlerResolver crawlerResolver) { _useragent = crawlerResolver.UserAgent; _crawler = crawlerResolver.Crawler; } public IActionResult Index() { return View(); } } ``` ### Directory Structure * `src` - The source code of this project lives here * `test` - The test code of this project lives here * `collection` - Collection of sample user agents for lab testing * `sample` - Contains sample web application of usage * `doc` - Contains the documentation on how utilized this library ### Contributing All contribution are welcome, please contact the author. ## Contributors ### Code Contributors This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. ### Financial Contributors Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/wangkanai/contribute)] #### Individuals #### Organizations Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/wangkanai/contribute)] ### See the [LICENSE](https://github.com/wangkanai/Browser/blob/master/LICENSE) file.