diff --git a/Directory.Packages.props b/Directory.Packages.props
index e08352f..ea3fdaf 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -1,41 +1,55 @@
-
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
- all
- runtime; build; native; contentfiles; analyzers
-
-
-
\ No newline at end of file
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
diff --git a/src/MyCSharp.HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs b/src/MyCSharp.HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs
index c4fe5a2..4209560 100644
--- a/src/MyCSharp.HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs
+++ b/src/MyCSharp.HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs
@@ -4,22 +4,21 @@
using MyCSharp.HttpUserAgentParser.DependencyInjection;
using MyCSharp.HttpUserAgentParser.Providers;
-namespace MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection
+namespace MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection;
+
+///
+/// Dependency injection extensions for ASP.NET Core environments
+///
+public static class HttpUserAgentParserDependencyInjectionOptionsExtensions
{
///
- /// Dependency injection extensions for ASP.NET Core environments
+ /// Registers as .
+ /// Requires a registered
///
- public static class HttpUserAgentParserDependencyInjectionOptionsExtensions
+ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParserAccessor(
+ this HttpUserAgentParserDependencyInjectionOptions options)
{
- ///
- /// Registers as .
- /// Requires a registered
- ///
- public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParserAccessor(
- this HttpUserAgentParserDependencyInjectionOptions options)
- {
- options.Services.AddSingleton();
- return options;
- }
+ options.Services.AddSingleton();
+ return options;
}
}
diff --git a/src/MyCSharp.HttpUserAgentParser/HttpContextExtensions.cs b/src/MyCSharp.HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs
similarity index 90%
rename from src/MyCSharp.HttpUserAgentParser/HttpContextExtensions.cs
rename to src/MyCSharp.HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs
index 2a79ffe..a8c50fb 100644
--- a/src/MyCSharp.HttpUserAgentParser/HttpContextExtensions.cs
+++ b/src/MyCSharp.HttpUserAgentParser.AspNetCore/HttpContextExtensions.cs
@@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
-namespace MyCSharp.HttpUserAgentParser;
+namespace MyCSharp.HttpUserAgentParser.AspNetCore;
///
/// Static extensions for
@@ -16,9 +16,7 @@ public static class HttpContextExtensions
public static string? GetUserAgentString(this HttpContext httpContext)
{
if (httpContext.Request.Headers.TryGetValue("User-Agent", out StringValues value))
- {
return value;
- }
return null;
}
diff --git a/src/MyCSharp.HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs b/src/MyCSharp.HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs
index 4634418..30e7f86 100644
--- a/src/MyCSharp.HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs
+++ b/src/MyCSharp.HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs
@@ -3,57 +3,36 @@
using Microsoft.AspNetCore.Http;
using MyCSharp.HttpUserAgentParser.Providers;
-namespace MyCSharp.HttpUserAgentParser.AspNetCore
+namespace MyCSharp.HttpUserAgentParser.AspNetCore;
+
+///
+/// User Agent parser accessor. Implements
+///
+///
+/// Creates a new instance of
+///
+public class HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAgentParser)
+ : IHttpUserAgentParserAccessor
{
+ private readonly IHttpUserAgentParserProvider _httpUserAgentParser = httpUserAgentParser;
+
///
- /// User Agent parser accessor
+ /// User agent of current
///
- public interface IHttpUserAgentParserAccessor
- {
- ///
- /// User agent value
- ///
- string? GetHttpContextUserAgent(HttpContext httpContext);
-
- ///
- /// Returns current
- ///
- HttpUserAgentInformation? Get(HttpContext httpContext);
- }
+ public string? GetHttpContextUserAgent(HttpContext httpContext)
+ => httpContext.GetUserAgentString();
///
- /// User Agent parser accessor. Implements
+ /// Returns current of current
///
- public class HttpUserAgentParserAccessor : IHttpUserAgentParserAccessor
+ public HttpUserAgentInformation? Get(HttpContext httpContext)
{
- private readonly IHttpUserAgentParserProvider _httpUserAgentParser;
-
- ///
- /// Creates a new instance of
- ///
- public HttpUserAgentParserAccessor(IHttpUserAgentParserProvider httpUserAgentParser)
+ string? httpUserAgent = GetHttpContextUserAgent(httpContext);
+ if (string.IsNullOrEmpty(httpUserAgent))
{
- _httpUserAgentParser = httpUserAgentParser;
+ return null;
}
- ///
- /// User agent of current
- ///
- public string? GetHttpContextUserAgent(HttpContext httpContext)
- => httpContext.GetUserAgentString();
-
- ///
- /// Returns current of current
- ///
- public HttpUserAgentInformation? Get(HttpContext httpContext)
- {
- string? httpUserAgent = GetHttpContextUserAgent(httpContext);
- if (string.IsNullOrEmpty(httpUserAgent))
- {
- return null;
- }
-
- return _httpUserAgentParser.Parse(httpUserAgent);
- }
+ return _httpUserAgentParser.Parse(httpUserAgent);
}
}
diff --git a/src/MyCSharp.HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs b/src/MyCSharp.HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs
new file mode 100644
index 0000000..f0f737c
--- /dev/null
+++ b/src/MyCSharp.HttpUserAgentParser.AspNetCore/IHttpUserAgentParserAccessor.cs
@@ -0,0 +1,21 @@
+// Copyright © myCSharp.de - all rights reserved
+
+using Microsoft.AspNetCore.Http;
+
+namespace MyCSharp.HttpUserAgentParser.AspNetCore;
+
+///
+/// User Agent parser accessor
+///
+public interface IHttpUserAgentParserAccessor
+{
+ ///
+ /// User agent value
+ ///
+ string? GetHttpContextUserAgent(HttpContext httpContext);
+
+ ///
+ /// Returns current
+ ///
+ HttpUserAgentInformation? Get(HttpContext httpContext);
+}
diff --git a/src/MyCSharp.HttpUserAgentParser.AspNetCore/MyCSharp.HttpUserAgentParser.AspNetCore.csproj b/src/MyCSharp.HttpUserAgentParser.AspNetCore/MyCSharp.HttpUserAgentParser.AspNetCore.csproj
index 33de36b..c09b52c 100644
--- a/src/MyCSharp.HttpUserAgentParser.AspNetCore/MyCSharp.HttpUserAgentParser.AspNetCore.csproj
+++ b/src/MyCSharp.HttpUserAgentParser.AspNetCore/MyCSharp.HttpUserAgentParser.AspNetCore.csproj
@@ -16,11 +16,26 @@
-
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
diff --git a/src/MyCSharp.HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs b/src/MyCSharp.HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs
index 5237b05..b4d4d3b 100644
--- a/src/MyCSharp.HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs
+++ b/src/MyCSharp.HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProvider.cs
@@ -1,65 +1,58 @@
// Copyright © myCSharp.de - all rights reserved
-using System;
using Microsoft.Extensions.Caching.Memory;
using MyCSharp.HttpUserAgentParser.Providers;
-namespace MyCSharp.HttpUserAgentParser.MemoryCache
+namespace MyCSharp.HttpUserAgentParser.MemoryCache;
+
+///
+///
+/// Creates a new instance of .
+///
+/// The options used to set expiration and size limit
+public class HttpUserAgentParserMemoryCachedProvider(
+ HttpUserAgentParserMemoryCachedProviderOptions options) : IHttpUserAgentParserProvider
{
+ private readonly Microsoft.Extensions.Caching.Memory.MemoryCache _memoryCache = new(options.CacheOptions);
+ private readonly HttpUserAgentParserMemoryCachedProviderOptions _options = options;
+
///
- public class HttpUserAgentParserMemoryCachedProvider : IHttpUserAgentParserProvider
+ public HttpUserAgentInformation Parse(string userAgent)
{
- private readonly Microsoft.Extensions.Caching.Memory.MemoryCache _memoryCache;
- private readonly HttpUserAgentParserMemoryCachedProviderOptions _options;
-
- ///
- /// Creates a new instance of .
- ///
- /// The options used to set expiration and size limit
- public HttpUserAgentParserMemoryCachedProvider(HttpUserAgentParserMemoryCachedProviderOptions options)
- {
- _memoryCache = new Microsoft.Extensions.Caching.Memory.MemoryCache(options.CacheOptions);
- _options = options;
- }
+ CacheKey key = this.GetKey(userAgent);
- ///
- public HttpUserAgentInformation Parse(string userAgent)
+ return _memoryCache.GetOrCreate(key, static entry =>
{
- CacheKey key = this.GetKey(userAgent);
-
- return _memoryCache.GetOrCreate(key, static entry =>
- {
- CacheKey key = (entry.Key as CacheKey)!;
- entry.SlidingExpiration = key.Options.CacheEntryOptions.SlidingExpiration;
- entry.SetSize(1);
+ CacheKey key = (entry.Key as CacheKey)!;
+ entry.SlidingExpiration = key.Options.CacheEntryOptions.SlidingExpiration;
+ entry.SetSize(1);
- return HttpUserAgentParser.Parse(key.UserAgent);
- });
- }
+ return HttpUserAgentParser.Parse(key.UserAgent);
+ });
+ }
- [ThreadStatic]
- private static CacheKey? s_tKey;
+ [ThreadStatic]
+ private static CacheKey? s_tKey;
- private CacheKey GetKey(string userAgent)
- {
- CacheKey key = s_tKey ??= new CacheKey();
+ private CacheKey GetKey(string userAgent)
+ {
+ CacheKey key = s_tKey ??= new CacheKey();
- key.UserAgent = userAgent;
- key.Options = _options;
+ key.UserAgent = userAgent;
+ key.Options = _options;
- return key;
- }
+ return key;
+ }
- private class CacheKey : IEquatable // required for IMemoryCache
- {
- public string UserAgent { get; set; } = null!;
+ private class CacheKey : IEquatable // required for IMemoryCache
+ {
+ public string UserAgent { get; set; } = null!;
- public HttpUserAgentParserMemoryCachedProviderOptions Options { get; set; } = null!;
+ public HttpUserAgentParserMemoryCachedProviderOptions Options { get; set; } = null!;
- public bool Equals(CacheKey? other) => this.UserAgent == other?.UserAgent;
- public override bool Equals(object? obj) => this.Equals(obj as CacheKey);
+ public bool Equals(CacheKey? other) => this.UserAgent == other?.UserAgent;
+ public override bool Equals(object? obj) => this.Equals(obj as CacheKey);
- public override int GetHashCode() => this.UserAgent.GetHashCode();
- }
+ public override int GetHashCode() => this.UserAgent.GetHashCode();
}
}
diff --git a/src/MyCSharp.HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProviderOptions.cs b/src/MyCSharp.HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProviderOptions.cs
index 3ad52cf..9baf223 100644
--- a/src/MyCSharp.HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProviderOptions.cs
+++ b/src/MyCSharp.HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProviderOptions.cs
@@ -1,56 +1,56 @@
// Copyright © myCSharp.de - all rights reserved
-using System;
using Microsoft.Extensions.Caching.Memory;
-namespace MyCSharp.HttpUserAgentParser.MemoryCache
+namespace MyCSharp.HttpUserAgentParser.MemoryCache;
+
+///
+/// Provider options for
+///
+/// Default of is 256.
+/// Default of is 1 day
+///
+///
+public class HttpUserAgentParserMemoryCachedProviderOptions
{
///
- /// Provider options for
- ///
- /// Default of is 256.
- /// Default of is 1 day
- ///
+ /// Cache options
+ ///
+ public MemoryCacheOptions CacheOptions { get; }
+
+ ///
+ /// Cache entry options
///
- public class HttpUserAgentParserMemoryCachedProviderOptions
+ public MemoryCacheEntryOptions CacheEntryOptions { get; }
+
+ ///
+ /// Creates a new instance of
+ ///
+ public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheOptions cacheOptions)
+ : this(cacheOptions, null) { }
+
+ ///
+ /// Creates a new instance of
+ ///
+ public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheEntryOptions cacheEntryOptions)
+ : this(null, cacheEntryOptions) { }
+
+ ///
+ /// Creates a new instance of
+ ///
+ public HttpUserAgentParserMemoryCachedProviderOptions(
+ MemoryCacheOptions? cacheOptions = null, MemoryCacheEntryOptions? cacheEntryOptions = null)
{
- ///
- /// Cache options
- ///
- public MemoryCacheOptions CacheOptions { get; }
-
- ///
- /// Cache entry options
- ///
- public MemoryCacheEntryOptions CacheEntryOptions { get; }
-
- ///
- /// Creates a new instance of
- ///
- public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheOptions cacheOptions)
- : this(cacheOptions, null) { }
-
- ///
- /// Creates a new instance of
- ///
- public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheEntryOptions cacheEntryOptions)
- : this(null, cacheEntryOptions) { }
-
- ///
- /// Creates a new instance of
- ///
- public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheOptions? cacheOptions = null, MemoryCacheEntryOptions? cacheEntryOptions = null)
+ this.CacheEntryOptions = cacheEntryOptions ?? new MemoryCacheEntryOptions
+ {
+ // defaults
+ SlidingExpiration = TimeSpan.FromDays(1)
+ };
+
+ this.CacheOptions = cacheOptions ?? new MemoryCacheOptions
{
- this.CacheEntryOptions = cacheEntryOptions ?? new MemoryCacheEntryOptions
- {
- // defaults
- SlidingExpiration = TimeSpan.FromDays(1)
- };
- this.CacheOptions = cacheOptions ?? new MemoryCacheOptions
- {
- // defaults
- SizeLimit = 256
- };
- }
+ // defaults
+ SizeLimit = 256
+ };
}
}
diff --git a/src/MyCSharp.HttpUserAgentParser.MemoryCache/MyCSharp.HttpUserAgentParser.MemoryCache.csproj b/src/MyCSharp.HttpUserAgentParser.MemoryCache/MyCSharp.HttpUserAgentParser.MemoryCache.csproj
index 49b2866..c5e54a4 100644
--- a/src/MyCSharp.HttpUserAgentParser.MemoryCache/MyCSharp.HttpUserAgentParser.MemoryCache.csproj
+++ b/src/MyCSharp.HttpUserAgentParser.MemoryCache/MyCSharp.HttpUserAgentParser.MemoryCache.csproj
@@ -5,7 +5,7 @@
HTTP User Agent Parser Extensions for IMemoryCache
net7.0;net8.0
-
+
true
readme.md
@@ -17,11 +17,26 @@
-
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
diff --git a/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs b/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs
index ca12480..8fb66d3 100644
--- a/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs
+++ b/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs
@@ -2,25 +2,19 @@
using Microsoft.Extensions.DependencyInjection;
-namespace MyCSharp.HttpUserAgentParser.DependencyInjection
+namespace MyCSharp.HttpUserAgentParser.DependencyInjection;
+
+///
+/// Options for dependency injection
+///
+///
+/// Creates a new instance of
+///
+///
+public class HttpUserAgentParserDependencyInjectionOptions(IServiceCollection services)
{
///
- /// Options for dependency injection
+ /// Services container
///
- public class HttpUserAgentParserDependencyInjectionOptions
- {
- ///
- /// Services container
- ///
- public IServiceCollection Services { get; }
-
- ///
- /// Creates a new instance of
- ///
- ///
- public HttpUserAgentParserDependencyInjectionOptions(IServiceCollection services)
- {
- Services = services;
- }
- }
+ public IServiceCollection Services { get; } = services;
}
diff --git a/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs b/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs
index f94e2b2..29da355 100644
--- a/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs
+++ b/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs
@@ -3,44 +3,43 @@
using Microsoft.Extensions.DependencyInjection;
using MyCSharp.HttpUserAgentParser.Providers;
-namespace MyCSharp.HttpUserAgentParser.DependencyInjection
+namespace MyCSharp.HttpUserAgentParser.DependencyInjection;
+
+///
+/// Dependency injection extensions
+///
+public static class HttpUserAgentParserServiceCollectionExtensions
{
///
- /// Dependency injection extensions
+ /// Registers as singleton to
///
- public static class HttpUserAgentParserServiceCollectionExtensions
+ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParser(
+ this IServiceCollection services)
{
- ///
- /// Registers as singleton to
- ///
- public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParser(
- this IServiceCollection services)
- {
- return AddHttpUserAgentParser(services);
- }
+ return AddHttpUserAgentParser(services);
+ }
- ///
- /// Registers as singleton to
- ///
- public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentCachedParser(
- this IServiceCollection services)
- {
- return AddHttpUserAgentParser(services);
- }
+ ///
+ /// Registers as singleton to
+ ///
+ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentCachedParser(
+ this IServiceCollection services)
+ {
+ return AddHttpUserAgentParser(services);
+ }
- ///
- /// Registers as singleton to
- ///
- public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParser(
- this IServiceCollection services) where TProvider : class, IHttpUserAgentParserProvider
- {
- // create options
- HttpUserAgentParserDependencyInjectionOptions options = new(services);
+ ///
+ /// Registers as singleton to
+ ///
+ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentParser(
+ this IServiceCollection services) where TProvider : class, IHttpUserAgentParserProvider
+ {
+ // create options
+ HttpUserAgentParserDependencyInjectionOptions options = new(services);
- // add provider
- services.AddSingleton();
+ // add provider
+ services.AddSingleton();
- return options;
- }
+ return options;
}
}
diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformation.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformation.cs
index eea1751..1319154 100644
--- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformation.cs
+++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformation.cs
@@ -1,78 +1,75 @@
// Copyright © myCSharp.de - all rights reserved
-namespace MyCSharp.HttpUserAgentParser
+namespace MyCSharp.HttpUserAgentParser;
+
+///
+/// Analyzed user agent
+///
+public readonly struct HttpUserAgentInformation
{
///
- /// Analyzed user agent
+ /// Full User Agent string
///
- public readonly struct HttpUserAgentInformation
- {
- ///
- /// Full User Agent string
- ///
- public string UserAgent { get; }
-
- ///
- /// Type of user agent, see
- ///
- public HttpUserAgentType Type { get; }
-
- ///
- /// Platform of user agent, see
- ///
- public HttpUserAgentPlatformInformation? Platform { get; }
+ public string UserAgent { get; }
- ///
- /// Browser or Bot Name of user agent e.g. "Chrome", "Edge"..
- ///
- public string? Name { get; }
+ ///
+ /// Type of user agent, see
+ ///
+ public HttpUserAgentType Type { get; }
+ ///
+ /// Platform of user agent, see
+ ///
+ public HttpUserAgentPlatformInformation? Platform { get; }
- ///
- /// Version of Browser or Bot Name of user agent e.g. "79.0", "83.0.125.4"
- ///
- public string? Version { get; }
+ ///
+ /// Browser or Bot Name of user agent e.g. "Chrome", "Edge"..
+ ///
+ public string? Name { get; }
+ ///
+ /// Version of Browser or Bot Name of user agent e.g. "79.0", "83.0.125.4"
+ ///
+ public string? Version { get; }
- ///
- /// Device Type of user agent, e.g. "Android", "Apple iPhone"
- ///
- public string? MobileDeviceType { get; }
+ ///
+ /// Device Type of user agent, e.g. "Android", "Apple iPhone"
+ ///
+ public string? MobileDeviceType { get; }
- ///
- /// Creates a new instance of
- ///
- private HttpUserAgentInformation(string userAgent, HttpUserAgentPlatformInformation? platform, HttpUserAgentType type, string? name, string? version, string? deviceName)
- {
- UserAgent = userAgent;
- Type = type;
- Name = name;
- Platform = platform;
- Version = version;
- MobileDeviceType = deviceName;
- }
+ ///
+ /// Creates a new instance of
+ ///
+ private HttpUserAgentInformation(string userAgent, HttpUserAgentPlatformInformation? platform, HttpUserAgentType type, string? name, string? version, string? deviceName)
+ {
+ UserAgent = userAgent;
+ Type = type;
+ Name = name;
+ Platform = platform;
+ Version = version;
+ MobileDeviceType = deviceName;
+ }
- ///
- /// Parses given User Agent
- ///
- public static HttpUserAgentInformation Parse(string userAgent) => HttpUserAgentParser.Parse(userAgent);
+ ///
+ /// Parses given User Agent
+ ///
+ public static HttpUserAgentInformation Parse(string userAgent) => HttpUserAgentParser.Parse(userAgent);
- ///
- /// Creates for a robot
- ///
- internal static HttpUserAgentInformation CreateForRobot(string userAgent, string robotName)
- => new(userAgent, null, HttpUserAgentType.Robot, robotName, null, null);
+ ///
+ /// Creates for a robot
+ ///
+ internal static HttpUserAgentInformation CreateForRobot(string userAgent, string robotName)
+ => new(userAgent, null, HttpUserAgentType.Robot, robotName, null, null);
- ///
- /// Creates for a browser
- ///
- internal static HttpUserAgentInformation CreateForBrowser(string userAgent, HttpUserAgentPlatformInformation? platform, string? browserName, string? browserVersion, string? deviceName)
- => new(userAgent, platform, HttpUserAgentType.Browser, browserName, browserVersion, deviceName);
+ ///
+ /// Creates for a browser
+ ///
+ internal static HttpUserAgentInformation CreateForBrowser(string userAgent, HttpUserAgentPlatformInformation? platform, string? browserName, string? browserVersion, string? deviceName)
+ => new(userAgent, platform, HttpUserAgentType.Browser, browserName, browserVersion, deviceName);
- ///
- /// Creates for an unknown agent type
- ///
- internal static HttpUserAgentInformation CreateForUnknown(string userAgent, HttpUserAgentPlatformInformation? platform, string? deviceName)
- => new(userAgent, platform, HttpUserAgentType.Unknown, null, null, deviceName);
- }
+ ///
+ /// Creates for an unknown agent type
+ ///
+ internal static HttpUserAgentInformation CreateForUnknown(string userAgent, HttpUserAgentPlatformInformation? platform, string? deviceName)
+ => new(userAgent, platform, HttpUserAgentType.Unknown, null, null, deviceName);
}
diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformationExtensions.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformationExtensions.cs
index 5f1225f..1edc608 100644
--- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformationExtensions.cs
+++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformationExtensions.cs
@@ -1,31 +1,30 @@
// Copyright © myCSharp.de - all rights reserved
-namespace MyCSharp.HttpUserAgentParser
+namespace MyCSharp.HttpUserAgentParser;
+
+///
+/// Extensions for
+///
+public static class HttpUserAgentInformationExtensions
{
///
- /// Extensions for
+ /// Tests if is of
///
- public static class HttpUserAgentInformationExtensions
- {
- ///
- /// Tests if is of
- ///
- public static bool IsType(this in HttpUserAgentInformation userAgent, HttpUserAgentType type) => userAgent.Type == type;
+ public static bool IsType(this in HttpUserAgentInformation userAgent, HttpUserAgentType type) => userAgent.Type == type;
- ///
- /// Tests if is of type
- ///
- public static bool IsRobot(this in HttpUserAgentInformation userAgent) => IsType(userAgent, HttpUserAgentType.Robot);
+ ///
+ /// Tests if is of type
+ ///
+ public static bool IsRobot(this in HttpUserAgentInformation userAgent) => IsType(userAgent, HttpUserAgentType.Robot);
- ///
- /// Tests if is of type
- ///
- public static bool IsBrowser(this in HttpUserAgentInformation userAgent) => IsType(userAgent, HttpUserAgentType.Browser);
+ ///
+ /// Tests if is of type
+ ///
+ public static bool IsBrowser(this in HttpUserAgentInformation userAgent) => IsType(userAgent, HttpUserAgentType.Browser);
- ///
- /// returns true if agent is a mobile device
- ///
- /// checks if is null
- public static bool IsMobile(this in HttpUserAgentInformation userAgent) => userAgent.MobileDeviceType is not null;
- }
+ ///
+ /// returns true if agent is a mobile device
+ ///
+ /// checks if is null
+ public static bool IsMobile(this in HttpUserAgentInformation userAgent) => userAgent.MobileDeviceType is not null;
}
diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentParser.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentParser.cs
index c4a8ab4..04eb1ab 100644
--- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentParser.cs
+++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentParser.cs
@@ -1,145 +1,143 @@
// Copyright © myCSharp.de - all rights reserved
-using System;
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
-namespace MyCSharp.HttpUserAgentParser
+namespace MyCSharp.HttpUserAgentParser;
+
+///
+/// Parser logic for user agents
+///
+public static class HttpUserAgentParser
{
///
- /// Parser logic for user agents
+ /// Parses given user agent
///
- public static class HttpUserAgentParser
+ public static HttpUserAgentInformation Parse(string userAgent)
{
- ///
- /// Parses given user agent
- ///
- public static HttpUserAgentInformation Parse(string userAgent)
- {
- // prepare
- userAgent = Cleanup(userAgent);
-
- // analyze
- if (TryGetRobot(userAgent, out string? robotName))
- {
- return HttpUserAgentInformation.CreateForRobot(userAgent, robotName);
- }
+ // prepare
+ userAgent = Cleanup(userAgent);
- HttpUserAgentPlatformInformation? platform = GetPlatform(userAgent);
- string? mobileDeviceType = GetMobileDevice(userAgent);
+ // analyze
+ if (TryGetRobot(userAgent, out string? robotName))
+ {
+ return HttpUserAgentInformation.CreateForRobot(userAgent, robotName);
+ }
- if (TryGetBrowser(userAgent, out (string Name, string? Version)? browser))
- {
- return HttpUserAgentInformation.CreateForBrowser(userAgent, platform, browser?.Name, browser?.Version, mobileDeviceType);
- }
+ HttpUserAgentPlatformInformation? platform = GetPlatform(userAgent);
+ string? mobileDeviceType = GetMobileDevice(userAgent);
- return HttpUserAgentInformation.CreateForUnknown(userAgent, platform, mobileDeviceType);
+ if (TryGetBrowser(userAgent, out (string Name, string? Version)? browser))
+ {
+ return HttpUserAgentInformation.CreateForBrowser(userAgent, platform, browser?.Name, browser?.Version, mobileDeviceType);
}
- ///
- /// pre-cleanup of user agent
- ///
- public static string Cleanup(string userAgent) => userAgent.Trim();
+ return HttpUserAgentInformation.CreateForUnknown(userAgent, platform, mobileDeviceType);
+ }
+
+ ///
+ /// pre-cleanup of user agent
+ ///
+ public static string Cleanup(string userAgent) => userAgent.Trim();
- ///
- /// returns the platform or null
- ///
- public static HttpUserAgentPlatformInformation? GetPlatform(string userAgent)
+ ///
+ /// returns the platform or null
+ ///
+ public static HttpUserAgentPlatformInformation? GetPlatform(string userAgent)
+ {
+ foreach (HttpUserAgentPlatformInformation item in HttpUserAgentStatics.Platforms)
{
- foreach (HttpUserAgentPlatformInformation item in HttpUserAgentStatics.Platforms)
+ if (item.Regex.IsMatch(userAgent))
{
- if (item.Regex.IsMatch(userAgent))
- {
- return item;
- }
+ return item;
}
-
- return null;
}
- ///
- /// returns true if platform was found
- ///
- public static bool TryGetPlatform(string userAgent, [NotNullWhen(true)] out HttpUserAgentPlatformInformation? platform)
- {
- platform = GetPlatform(userAgent);
- return platform is not null;
- }
+ return null;
+ }
- ///
- /// returns the browser or null
- ///
- public static (string Name, string? Version)? GetBrowser(string userAgent)
+ ///
+ /// returns true if platform was found
+ ///
+ public static bool TryGetPlatform(string userAgent, [NotNullWhen(true)] out HttpUserAgentPlatformInformation? platform)
+ {
+ platform = GetPlatform(userAgent);
+ return platform is not null;
+ }
+
+ ///
+ /// returns the browser or null
+ ///
+ public static (string Name, string? Version)? GetBrowser(string userAgent)
+ {
+ foreach ((Regex key, string? value) in HttpUserAgentStatics.Browsers)
{
- foreach ((Regex key, string? value) in HttpUserAgentStatics.Browsers)
+ Match match = key.Match(userAgent);
+ if (match.Success)
{
- Match match = key.Match(userAgent);
- if (match.Success)
- {
- return (value, match.Groups[1].Value);
- }
+ return (value, match.Groups[1].Value);
}
-
- return null;
}
- ///
- /// returns true if browser was found
- ///
- public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (string Name, string? Version)? browser)
- {
- browser = GetBrowser(userAgent);
- return browser is not null;
- }
+ return null;
+ }
+
+ ///
+ /// returns true if browser was found
+ ///
+ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (string Name, string? Version)? browser)
+ {
+ browser = GetBrowser(userAgent);
+ return browser is not null;
+ }
- ///
- /// returns the robot or null
- ///
- public static string? GetRobot(string userAgent)
+ ///
+ /// returns the robot or null
+ ///
+ public static string? GetRobot(string userAgent)
+ {
+ foreach ((string key, string value) in HttpUserAgentStatics.Robots)
{
- foreach ((string key, string value) in HttpUserAgentStatics.Robots)
+ if (userAgent.Contains(key, StringComparison.OrdinalIgnoreCase))
{
- if (userAgent.Contains(key, StringComparison.OrdinalIgnoreCase))
- {
- return value;
- }
+ return value;
}
-
- return null;
}
- ///
- /// returns true if robot was found
- ///
- public static bool TryGetRobot(string userAgent, [NotNullWhen(true)] out string? robotName)
- {
- robotName = GetRobot(userAgent);
- return robotName is not null;
- }
+ return null;
+ }
+
+ ///
+ /// returns true if robot was found
+ ///
+ public static bool TryGetRobot(string userAgent, [NotNullWhen(true)] out string? robotName)
+ {
+ robotName = GetRobot(userAgent);
+ return robotName is not null;
+ }
- ///
- /// returns the device or null
- ///
- public static string? GetMobileDevice(string userAgent)
+ ///
+ /// returns the device or null
+ ///
+ public static string? GetMobileDevice(string userAgent)
+ {
+ foreach ((string key, string value) in HttpUserAgentStatics.Mobiles)
{
- foreach ((string key, string value) in HttpUserAgentStatics.Mobiles)
+ if (userAgent.Contains(key, StringComparison.OrdinalIgnoreCase))
{
- if (userAgent.Contains(key, StringComparison.OrdinalIgnoreCase))
- {
- return value;
- }
+ return value;
}
-
- return null;
}
- ///
- /// returns true if device was found
- ///
- public static bool TryGetMobileDevice(string userAgent, [NotNullWhen(true)] out string? device)
- {
- device = GetMobileDevice(userAgent);
- return device is not null;
- }
+ return null;
+ }
+
+ ///
+ /// returns true if device was found
+ ///
+ public static bool TryGetMobileDevice(string userAgent, [NotNullWhen(true)] out string? device)
+ {
+ device = GetMobileDevice(userAgent);
+ return device is not null;
}
}
diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformInformation.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformInformation.cs
index 252ea7c..fef830a 100644
--- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformInformation.cs
+++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformInformation.cs
@@ -2,36 +2,28 @@
using System.Text.RegularExpressions;
-namespace MyCSharp.HttpUserAgentParser
+namespace MyCSharp.HttpUserAgentParser;
+
+///
+/// Information about the user agent platform
+///
+///
+/// Creates a new instance of
+///
+public readonly struct HttpUserAgentPlatformInformation(Regex regex, string name, HttpUserAgentPlatformType platformType)
{
///
- /// Information about the user agent platform
+ /// Regex-pattern that matches this user agent string
///
- public readonly struct HttpUserAgentPlatformInformation
- {
- ///
- /// Regex-pattern that matches this user agent string
- ///
- public Regex Regex { get; }
-
- ///
- /// Name of the platform
- ///
- public string Name { get; }
+ public Regex Regex { get; } = regex;
- ///
- /// Specific platform type aka family
- ///
- public HttpUserAgentPlatformType PlatformType { get; }
+ ///
+ /// Name of the platform
+ ///
+ public string Name { get; } = name;
- ///
- /// Creates a new instance of
- ///
- public HttpUserAgentPlatformInformation(Regex regex, string name, HttpUserAgentPlatformType platformType)
- {
- Regex = regex;
- Name = name;
- PlatformType = platformType;
- }
- }
+ ///
+ /// Specific platform type aka family
+ ///
+ public HttpUserAgentPlatformType PlatformType { get; } = platformType;
}
diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformType.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformType.cs
index 879a169..42deba8 100644
--- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformType.cs
+++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformType.cs
@@ -1,51 +1,50 @@
// Copyright © myCSharp.de - all rights reserved
-namespace MyCSharp.HttpUserAgentParser
+namespace MyCSharp.HttpUserAgentParser;
+
+///
+/// Platform types
+///
+public enum HttpUserAgentPlatformType : byte
{
///
- /// Platform types
- ///
- public enum HttpUserAgentPlatformType : byte
- {
- ///
- /// Unknown / not mapped
- ///
- Unknown = 0,
- ///
- /// Generic
- ///
- Generic,
- ///
- /// Windows
- ///
- Windows,
- ///
- /// Linux
- ///
- Linux,
- ///
- /// Unix
- ///
- Unix,
- ///
- /// Apple iOS
- ///
- IOS,
- ///
- /// MacOS
- ///
- MacOS,
- ///
- /// BlackBerry
- ///
- BlackBerry,
- ///
- /// Android
- ///
- Android,
- ///
- /// Symbian
- ///
- Symbian
- }
+ /// Unknown / not mapped
+ ///
+ Unknown = 0,
+ ///
+ /// Generic
+ ///
+ Generic,
+ ///
+ /// Windows
+ ///
+ Windows,
+ ///
+ /// Linux
+ ///
+ Linux,
+ ///
+ /// Unix
+ ///
+ Unix,
+ ///
+ /// Apple iOS
+ ///
+ IOS,
+ ///
+ /// MacOS
+ ///
+ MacOS,
+ ///
+ /// BlackBerry
+ ///
+ BlackBerry,
+ ///
+ /// Android
+ ///
+ Android,
+ ///
+ /// Symbian
+ ///
+ Symbian
}
diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs
index 1fd6eb5..7b6d456 100644
--- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs
+++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs
@@ -1,268 +1,266 @@
// Copyright © myCSharp.de - all rights reserved
-using System.Collections.Generic;
using System.Text.RegularExpressions;
-namespace MyCSharp.HttpUserAgentParser
+namespace MyCSharp.HttpUserAgentParser;
+
+///
+/// Parser settings
+///
+public static class HttpUserAgentStatics
{
///
- /// Parser settings
+ /// Regex defauls for platform mappings
///
- public static class HttpUserAgentStatics
- {
- ///
- /// Regex defauls for platform mappings
- ///
- private const RegexOptions DefaultPlatformsRegexFlags = RegexOptions.IgnoreCase | RegexOptions.Compiled;
+ private const RegexOptions DefaultPlatformsRegexFlags = RegexOptions.IgnoreCase | RegexOptions.Compiled;
- ///
- /// Creates default platform mapping regex
- ///
- private static Regex CreateDefaultPlatformRegex(string key) => new(Regex.Escape($"{key}"), DefaultPlatformsRegexFlags);
+ ///
+ /// Creates default platform mapping regex
+ ///
+ private static Regex CreateDefaultPlatformRegex(string key) => new(Regex.Escape($"{key}"), DefaultPlatformsRegexFlags);
- ///
- /// Platforms
- ///
- public static readonly HashSet Platforms = new()
- {
- new(CreateDefaultPlatformRegex("windows nt 10.0"), "Windows 10", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows nt 6.3"), "Windows 8.1", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows nt 6.2"), "Windows 8", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows nt 6.1"), "Windows 7", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows nt 6.0"), "Windows Vista", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows nt 5.2"), "Windows 2003", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows nt 5.1"), "Windows XP", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows nt 5.0"), "Windows 2000", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows nt 4.0"), "Windows NT 4.0", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("winnt4.0"), "Windows NT 4.0", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("winnt 4.0"), "Windows NT", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("winnt"), "Windows NT", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows 98"), "Windows 98", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("win98"), "Windows 98", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows 95"), "Windows 95", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("win95"), "Windows 95", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows phone"), "Windows Phone", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("windows"), "Unknown Windows OS", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("android"), "Android", HttpUserAgentPlatformType.Android),
- new(CreateDefaultPlatformRegex("blackberry"), "BlackBerry", HttpUserAgentPlatformType.BlackBerry),
- new(CreateDefaultPlatformRegex("iphone"), "iOS", HttpUserAgentPlatformType.IOS),
- new(CreateDefaultPlatformRegex("ipad"), "iOS", HttpUserAgentPlatformType.IOS),
- new(CreateDefaultPlatformRegex("ipod"), "iOS", HttpUserAgentPlatformType.IOS),
- new(CreateDefaultPlatformRegex("os x"), "Mac OS X", HttpUserAgentPlatformType.MacOS),
- new(CreateDefaultPlatformRegex("ppc mac"), "Power PC Mac", HttpUserAgentPlatformType.MacOS),
- new(CreateDefaultPlatformRegex("freebsd"), "FreeBSD", HttpUserAgentPlatformType.Linux),
- new(CreateDefaultPlatformRegex("ppc"), "Macintosh", HttpUserAgentPlatformType.Linux),
- new(CreateDefaultPlatformRegex("linux"), "Linux", HttpUserAgentPlatformType.Linux),
- new(CreateDefaultPlatformRegex("debian"), "Debian", HttpUserAgentPlatformType.Linux),
- new(CreateDefaultPlatformRegex("sunos"), "Sun Solaris", HttpUserAgentPlatformType.Generic),
- new(CreateDefaultPlatformRegex("beos"), "BeOS", HttpUserAgentPlatformType.Generic),
- new(CreateDefaultPlatformRegex("apachebench"), "ApacheBench", HttpUserAgentPlatformType.Generic),
- new(CreateDefaultPlatformRegex("aix"), "AIX", HttpUserAgentPlatformType.Generic),
- new(CreateDefaultPlatformRegex("irix"), "Irix", HttpUserAgentPlatformType.Generic),
- new(CreateDefaultPlatformRegex("osf"), "DEC OSF", HttpUserAgentPlatformType.Generic),
- new(CreateDefaultPlatformRegex("hp-ux"), "HP-UX", HttpUserAgentPlatformType.Windows),
- new(CreateDefaultPlatformRegex("netbsd"), "NetBSD", HttpUserAgentPlatformType.Generic),
- new(CreateDefaultPlatformRegex("bsdi"), "BSDi", HttpUserAgentPlatformType.Generic),
- new(CreateDefaultPlatformRegex("openbsd"), "OpenBSD", HttpUserAgentPlatformType.Unix),
- new(CreateDefaultPlatformRegex("gnu"), "GNU/Linux", HttpUserAgentPlatformType.Linux),
- new(CreateDefaultPlatformRegex("unix"), "Unknown Unix OS", HttpUserAgentPlatformType.Unix),
- new(CreateDefaultPlatformRegex("symbian"), "Symbian OS", HttpUserAgentPlatformType.Symbian),
- };
+ ///
+ /// Platforms
+ ///
+ public static readonly HashSet Platforms =
+ [
+ new(CreateDefaultPlatformRegex("windows nt 10.0"), "Windows 10", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows nt 6.3"), "Windows 8.1", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows nt 6.2"), "Windows 8", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows nt 6.1"), "Windows 7", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows nt 6.0"), "Windows Vista", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows nt 5.2"), "Windows 2003", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows nt 5.1"), "Windows XP", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows nt 5.0"), "Windows 2000", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows nt 4.0"), "Windows NT 4.0", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("winnt4.0"), "Windows NT 4.0", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("winnt 4.0"), "Windows NT", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("winnt"), "Windows NT", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows 98"), "Windows 98", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("win98"), "Windows 98", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows 95"), "Windows 95", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("win95"), "Windows 95", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows phone"), "Windows Phone", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("windows"), "Unknown Windows OS", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("android"), "Android", HttpUserAgentPlatformType.Android),
+ new(CreateDefaultPlatformRegex("blackberry"), "BlackBerry", HttpUserAgentPlatformType.BlackBerry),
+ new(CreateDefaultPlatformRegex("iphone"), "iOS", HttpUserAgentPlatformType.IOS),
+ new(CreateDefaultPlatformRegex("ipad"), "iOS", HttpUserAgentPlatformType.IOS),
+ new(CreateDefaultPlatformRegex("ipod"), "iOS", HttpUserAgentPlatformType.IOS),
+ new(CreateDefaultPlatformRegex("os x"), "Mac OS X", HttpUserAgentPlatformType.MacOS),
+ new(CreateDefaultPlatformRegex("ppc mac"), "Power PC Mac", HttpUserAgentPlatformType.MacOS),
+ new(CreateDefaultPlatformRegex("freebsd"), "FreeBSD", HttpUserAgentPlatformType.Linux),
+ new(CreateDefaultPlatformRegex("ppc"), "Macintosh", HttpUserAgentPlatformType.Linux),
+ new(CreateDefaultPlatformRegex("linux"), "Linux", HttpUserAgentPlatformType.Linux),
+ new(CreateDefaultPlatformRegex("debian"), "Debian", HttpUserAgentPlatformType.Linux),
+ new(CreateDefaultPlatformRegex("sunos"), "Sun Solaris", HttpUserAgentPlatformType.Generic),
+ new(CreateDefaultPlatformRegex("beos"), "BeOS", HttpUserAgentPlatformType.Generic),
+ new(CreateDefaultPlatformRegex("apachebench"), "ApacheBench", HttpUserAgentPlatformType.Generic),
+ new(CreateDefaultPlatformRegex("aix"), "AIX", HttpUserAgentPlatformType.Generic),
+ new(CreateDefaultPlatformRegex("irix"), "Irix", HttpUserAgentPlatformType.Generic),
+ new(CreateDefaultPlatformRegex("osf"), "DEC OSF", HttpUserAgentPlatformType.Generic),
+ new(CreateDefaultPlatformRegex("hp-ux"), "HP-UX", HttpUserAgentPlatformType.Windows),
+ new(CreateDefaultPlatformRegex("netbsd"), "NetBSD", HttpUserAgentPlatformType.Generic),
+ new(CreateDefaultPlatformRegex("bsdi"), "BSDi", HttpUserAgentPlatformType.Generic),
+ new(CreateDefaultPlatformRegex("openbsd"), "OpenBSD", HttpUserAgentPlatformType.Unix),
+ new(CreateDefaultPlatformRegex("gnu"), "GNU/Linux", HttpUserAgentPlatformType.Linux),
+ new(CreateDefaultPlatformRegex("unix"), "Unknown Unix OS", HttpUserAgentPlatformType.Unix),
+ new(CreateDefaultPlatformRegex("symbian"), "Symbian OS", HttpUserAgentPlatformType.Symbian),
+ ];
- ///
- /// Regex defauls for browser mappings
- ///
- private const RegexOptions DefaultBrowserRegexFlags = RegexOptions.IgnoreCase | RegexOptions.Compiled;
- ///
- /// Creates default browser mapping regex
- ///
- private static Regex CreateDefaultBrowserRegex(string key) => new($@"{key}.*?([0-9\.]+)", DefaultBrowserRegexFlags);
+ ///
+ /// Regex defauls for browser mappings
+ ///
+ private const RegexOptions DefaultBrowserRegexFlags = RegexOptions.IgnoreCase | RegexOptions.Compiled;
+ ///
+ /// Creates default browser mapping regex
+ ///
+ private static Regex CreateDefaultBrowserRegex(string key) => new($@"{key}.*?([0-9\.]+)", DefaultBrowserRegexFlags);
- ///
- /// Browsers
- ///
- public static Dictionary Browsers = new()
- {
- { CreateDefaultBrowserRegex("OPR"), "Opera" },
- { CreateDefaultBrowserRegex("Flock"), "Flock" },
- { CreateDefaultBrowserRegex("Edge"), "Edge" },
- { CreateDefaultBrowserRegex("EdgA"), "Edge" },
- { CreateDefaultBrowserRegex("Edg"), "Edge" },
- { CreateDefaultBrowserRegex("Vivaldi"), "Vivaldi" },
- { CreateDefaultBrowserRegex("Brave Chrome"), "Brave" },
- { CreateDefaultBrowserRegex("Chrome"), "Chrome" },
- { CreateDefaultBrowserRegex("CriOS"), "Chrome" },
- { CreateDefaultBrowserRegex("Opera.*?Version"), "Opera" },
- { CreateDefaultBrowserRegex("Opera"), "Opera" },
- { CreateDefaultBrowserRegex("MSIE"), "Internet Explorer" },
- { CreateDefaultBrowserRegex("Internet Explorer"), "Internet Explorer" },
- { CreateDefaultBrowserRegex("Trident.* rv"), "Internet Explorer" },
- { CreateDefaultBrowserRegex("Shiira"), "Shiira" },
- { CreateDefaultBrowserRegex("Firefox"), "Firefox" },
- { CreateDefaultBrowserRegex("FxiOS"), "Firefox" },
- { CreateDefaultBrowserRegex("Chimera"), "Chimera" },
- { CreateDefaultBrowserRegex("Phoenix"), "Phoenix" },
- { CreateDefaultBrowserRegex("Firebird"), "Firebird" },
- { CreateDefaultBrowserRegex("Camino"), "Camino" },
- { CreateDefaultBrowserRegex("Netscape"), "Netscape" },
- { CreateDefaultBrowserRegex("OmniWeb"), "OmniWeb" },
- { CreateDefaultBrowserRegex("Version"), "Safari" }, // https://github.com/mycsharp/HttpUserAgentParser/issues/34
- { CreateDefaultBrowserRegex("Mozilla"), "Mozilla" },
- { CreateDefaultBrowserRegex("Konqueror"), "Konqueror" },
- { CreateDefaultBrowserRegex("icab"), "iCab" },
- { CreateDefaultBrowserRegex("Lynx"), "Lynx" },
- { CreateDefaultBrowserRegex("Links"), "Links" },
- { CreateDefaultBrowserRegex("hotjava"), "HotJava" },
- { CreateDefaultBrowserRegex("amaya"), "Amaya" },
- { CreateDefaultBrowserRegex("IBrowse"), "IBrowse" },
- { CreateDefaultBrowserRegex("Maxthon"), "Maxthon" },
- { CreateDefaultBrowserRegex("ipod touch"), "Apple iPod" },
- { CreateDefaultBrowserRegex("Ubuntu"), "Ubuntu Web Browser" },
- };
+ ///
+ /// Browsers
+ ///
+ public static Dictionary Browsers = new()
+ {
+ { CreateDefaultBrowserRegex("OPR"), "Opera" },
+ { CreateDefaultBrowserRegex("Flock"), "Flock" },
+ { CreateDefaultBrowserRegex("Edge"), "Edge" },
+ { CreateDefaultBrowserRegex("EdgA"), "Edge" },
+ { CreateDefaultBrowserRegex("Edg"), "Edge" },
+ { CreateDefaultBrowserRegex("Vivaldi"), "Vivaldi" },
+ { CreateDefaultBrowserRegex("Brave Chrome"), "Brave" },
+ { CreateDefaultBrowserRegex("Chrome"), "Chrome" },
+ { CreateDefaultBrowserRegex("CriOS"), "Chrome" },
+ { CreateDefaultBrowserRegex("Opera.*?Version"), "Opera" },
+ { CreateDefaultBrowserRegex("Opera"), "Opera" },
+ { CreateDefaultBrowserRegex("MSIE"), "Internet Explorer" },
+ { CreateDefaultBrowserRegex("Internet Explorer"), "Internet Explorer" },
+ { CreateDefaultBrowserRegex("Trident.* rv"), "Internet Explorer" },
+ { CreateDefaultBrowserRegex("Shiira"), "Shiira" },
+ { CreateDefaultBrowserRegex("Firefox"), "Firefox" },
+ { CreateDefaultBrowserRegex("FxiOS"), "Firefox" },
+ { CreateDefaultBrowserRegex("Chimera"), "Chimera" },
+ { CreateDefaultBrowserRegex("Phoenix"), "Phoenix" },
+ { CreateDefaultBrowserRegex("Firebird"), "Firebird" },
+ { CreateDefaultBrowserRegex("Camino"), "Camino" },
+ { CreateDefaultBrowserRegex("Netscape"), "Netscape" },
+ { CreateDefaultBrowserRegex("OmniWeb"), "OmniWeb" },
+ { CreateDefaultBrowserRegex("Version"), "Safari" }, // https://github.com/mycsharp/HttpUserAgentParser/issues/34
+ { CreateDefaultBrowserRegex("Mozilla"), "Mozilla" },
+ { CreateDefaultBrowserRegex("Konqueror"), "Konqueror" },
+ { CreateDefaultBrowserRegex("icab"), "iCab" },
+ { CreateDefaultBrowserRegex("Lynx"), "Lynx" },
+ { CreateDefaultBrowserRegex("Links"), "Links" },
+ { CreateDefaultBrowserRegex("hotjava"), "HotJava" },
+ { CreateDefaultBrowserRegex("amaya"), "Amaya" },
+ { CreateDefaultBrowserRegex("IBrowse"), "IBrowse" },
+ { CreateDefaultBrowserRegex("Maxthon"), "Maxthon" },
+ { CreateDefaultBrowserRegex("ipod touch"), "Apple iPod" },
+ { CreateDefaultBrowserRegex("Ubuntu"), "Ubuntu Web Browser" },
+ };
- ///
- /// Mobiles
- ///
- public static readonly Dictionary Mobiles = new()
- {
- // Legacy
- { "mobileexplorer", "Mobile Explorer" },
- { "palmsource", "Palm" },
- { "palmscape", "Palmscape" },
- // Phones and Manufacturers
- { "motorola", "Motorola" },
- { "nokia", "Nokia" },
- { "palm", "Palm" },
- { "ipad", "Apple iPad" },
- { "ipod", "Apple iPod" },
- { "iphone", "Apple iPhone" },
- { "sony", "Sony Ericsson" },
- { "ericsson", "Sony Ericsson" },
- { "blackberry", "BlackBerry" },
- { "cocoon", "O2 Cocoon" },
- { "blazer", "Treo" },
- { "lg", "LG" },
- { "amoi", "Amoi" },
- { "xda", "XDA" },
- { "mda", "MDA" },
- { "vario", "Vario" },
- { "htc", "HTC" },
- { "samsung", "Samsung" },
- { "sharp", "Sharp" },
- { "sie-", "Siemens" },
- { "alcatel", "Alcatel" },
- { "benq", "BenQ" },
- { "ipaq", "HP iPaq" },
- { "mot-", "Motorola" },
- { "playstation portable", "PlayStation Portable" },
- { "playstation 3", "PlayStation 3" },
- { "playstation vita", "PlayStation Vita" },
- { "hiptop", "Danger Hiptop" },
- { "nec-", "NEC" },
- { "panasonic", "Panasonic" },
- { "philips", "Philips" },
- { "sagem", "Sagem" },
- { "sanyo", "Sanyo" },
- { "spv", "SPV" },
- { "zte", "ZTE" },
- { "sendo", "Sendo" },
- { "nintendo dsi", "Nintendo DSi" },
- { "nintendo ds", "Nintendo DS" },
- { "nintendo 3ds", "Nintendo 3DS" },
- { "wii", "Nintendo Wii" },
- { "open web", "Open Web" },
- { "openweb", "OpenWeb" },
- // Operating Systems
- { "android", "Android" },
- { "symbian", "Symbian" },
- { "SymbianOS", "SymbianOS" },
- { "elaine", "Palm" },
- { "series60", "Symbian S60" },
- { "windows ce", "Windows CE" },
- // Browsers
- { "obigo", "Obigo" },
- { "netfront", "Netfront Browser" },
- { "openwave", "Openwave Browser" },
- { "mobilexplorer", "Mobile Explorer" },
- { "operamini", "Opera Mini" },
- { "opera mini", "Opera Mini" },
- { "opera mobi", "Opera Mobile" },
- { "fennec", "Firefox Mobile" },
- // Other
- { "digital paths", "Digital Paths" },
- { "avantgo", "AvantGo" },
- { "xiino", "Xiino" },
- { "novarra", "Novarra Transcoder" },
- { "vodafone", "Vodafone" },
- { "docomo", "NTT DoCoMo" },
- { "o2", "O2" },
- // Fallback
- { "mobile", "Generic Mobile" },
- { "wireless", "Generic Mobile" },
- { "j2me", "Generic Mobile" },
- { "midp", "Generic Mobile" },
- { "cldc", "Generic Mobile" },
- { "up.link", "Generic Mobile" },
- { "up.browser", "Generic Mobile" },
- { "smartphone", "Generic Mobile" },
- { "cellphone", "Generic Mobile" },
- };
+ ///
+ /// Mobiles
+ ///
+ public static readonly Dictionary Mobiles = new()
+ {
+ // Legacy
+ { "mobileexplorer", "Mobile Explorer" },
+ { "palmsource", "Palm" },
+ { "palmscape", "Palmscape" },
+ // Phones and Manufacturers
+ { "motorola", "Motorola" },
+ { "nokia", "Nokia" },
+ { "palm", "Palm" },
+ { "ipad", "Apple iPad" },
+ { "ipod", "Apple iPod" },
+ { "iphone", "Apple iPhone" },
+ { "sony", "Sony Ericsson" },
+ { "ericsson", "Sony Ericsson" },
+ { "blackberry", "BlackBerry" },
+ { "cocoon", "O2 Cocoon" },
+ { "blazer", "Treo" },
+ { "lg", "LG" },
+ { "amoi", "Amoi" },
+ { "xda", "XDA" },
+ { "mda", "MDA" },
+ { "vario", "Vario" },
+ { "htc", "HTC" },
+ { "samsung", "Samsung" },
+ { "sharp", "Sharp" },
+ { "sie-", "Siemens" },
+ { "alcatel", "Alcatel" },
+ { "benq", "BenQ" },
+ { "ipaq", "HP iPaq" },
+ { "mot-", "Motorola" },
+ { "playstation portable", "PlayStation Portable" },
+ { "playstation 3", "PlayStation 3" },
+ { "playstation vita", "PlayStation Vita" },
+ { "hiptop", "Danger Hiptop" },
+ { "nec-", "NEC" },
+ { "panasonic", "Panasonic" },
+ { "philips", "Philips" },
+ { "sagem", "Sagem" },
+ { "sanyo", "Sanyo" },
+ { "spv", "SPV" },
+ { "zte", "ZTE" },
+ { "sendo", "Sendo" },
+ { "nintendo dsi", "Nintendo DSi" },
+ { "nintendo ds", "Nintendo DS" },
+ { "nintendo 3ds", "Nintendo 3DS" },
+ { "wii", "Nintendo Wii" },
+ { "open web", "Open Web" },
+ { "openweb", "OpenWeb" },
+ // Operating Systems
+ { "android", "Android" },
+ { "symbian", "Symbian" },
+ { "SymbianOS", "SymbianOS" },
+ { "elaine", "Palm" },
+ { "series60", "Symbian S60" },
+ { "windows ce", "Windows CE" },
+ // Browsers
+ { "obigo", "Obigo" },
+ { "netfront", "Netfront Browser" },
+ { "openwave", "Openwave Browser" },
+ { "mobilexplorer", "Mobile Explorer" },
+ { "operamini", "Opera Mini" },
+ { "opera mini", "Opera Mini" },
+ { "opera mobi", "Opera Mobile" },
+ { "fennec", "Firefox Mobile" },
+ // Other
+ { "digital paths", "Digital Paths" },
+ { "avantgo", "AvantGo" },
+ { "xiino", "Xiino" },
+ { "novarra", "Novarra Transcoder" },
+ { "vodafone", "Vodafone" },
+ { "docomo", "NTT DoCoMo" },
+ { "o2", "O2" },
+ // Fallback
+ { "mobile", "Generic Mobile" },
+ { "wireless", "Generic Mobile" },
+ { "j2me", "Generic Mobile" },
+ { "midp", "Generic Mobile" },
+ { "cldc", "Generic Mobile" },
+ { "up.link", "Generic Mobile" },
+ { "up.browser", "Generic Mobile" },
+ { "smartphone", "Generic Mobile" },
+ { "cellphone", "Generic Mobile" },
+ };
- ///
- /// Robots
- ///
- public static readonly (string Key, string Value)[] Robots =
- {
- ( "googlebot", "Googlebot" ),
- ( "googleweblight", "Google Web Light" ),
- ( "PetalBot", "PetalBot"),
- ( "DuplexWeb-Google", "DuplexWeb-Google"),
- ( "Storebot-Google", "Storebot-Google"),
- ( "msnbot", "MSNBot"),
- ( "baiduspider", "Baiduspider"),
- ( "Google Favicon", "Google Favicon"),
- ( "Jobboerse", "Jobboerse"),
- ( "bingbot", "BingBot"),
- ( "BingPreview", "Bing Preview"),
- ( "slurp", "Slurp"),
- ( "yahoo", "Yahoo"),
- ( "ask jeeves", "Ask Jeeves"),
- ( "fastcrawler", "FastCrawler"),
- ( "infoseek", "InfoSeek Robot 1.0"),
- ( "lycos", "Lycos"),
- ( "YandexBot", "YandexBot"),
- ( "YandexImages", "YandexImages"),
- ( "mediapartners-google", "Mediapartners Google"),
- ( "apis-google", "APIs Google"),
- ( "CRAZYWEBCRAWLER", "Crazy Webcrawler"),
- ( "AdsBot-Google-Mobile", "AdsBot Google Mobile"),
- ( "adsbot-google", "AdsBot Google"),
- ( "feedfetcher-google", "FeedFetcher-Google"),
- ( "google-read-aloud", "Google-Read-Aloud"),
- ( "curious george", "Curious George"),
- ( "ia_archiver", "Alexa Crawler"),
- ( "MJ12bot", "Majestic"),
- ( "Uptimebot", "Uptimebot"),
- ( "CheckMarkNetwork", "CheckMark"),
- ( "facebookexternalhit", "Facebook"),
- ( "adscanner", "AdScanner"),
- ( "AhrefsBot", "Ahrefs"),
- ( "BLEXBot", "BLEXBot"),
- ( "DotBot", "OpenSite"),
- ( "Mail.RU_Bot", "Mail.ru"),
- ( "MegaIndex", "MegaIndex"),
- ( "SemrushBot", "SEMRush"),
- ( "SEOkicks", "SEOkicks"),
- ( "seoscanners.net", "SEO Scanners"),
- ( "Sistrix", "Sistrix" )
- };
+ ///
+ /// Robots
+ ///
+ public static readonly (string Key, string Value)[] Robots =
+ [
+ ( "googlebot", "Googlebot" ),
+ ( "googleweblight", "Google Web Light" ),
+ ( "PetalBot", "PetalBot"),
+ ( "DuplexWeb-Google", "DuplexWeb-Google"),
+ ( "Storebot-Google", "Storebot-Google"),
+ ( "msnbot", "MSNBot"),
+ ( "baiduspider", "Baiduspider"),
+ ( "Google Favicon", "Google Favicon"),
+ ( "Jobboerse", "Jobboerse"),
+ ( "bingbot", "BingBot"),
+ ( "BingPreview", "Bing Preview"),
+ ( "slurp", "Slurp"),
+ ( "yahoo", "Yahoo"),
+ ( "ask jeeves", "Ask Jeeves"),
+ ( "fastcrawler", "FastCrawler"),
+ ( "infoseek", "InfoSeek Robot 1.0"),
+ ( "lycos", "Lycos"),
+ ( "YandexBot", "YandexBot"),
+ ( "YandexImages", "YandexImages"),
+ ( "mediapartners-google", "Mediapartners Google"),
+ ( "apis-google", "APIs Google"),
+ ( "CRAZYWEBCRAWLER", "Crazy Webcrawler"),
+ ( "AdsBot-Google-Mobile", "AdsBot Google Mobile"),
+ ( "adsbot-google", "AdsBot Google"),
+ ( "feedfetcher-google", "FeedFetcher-Google"),
+ ( "google-read-aloud", "Google-Read-Aloud"),
+ ( "curious george", "Curious George"),
+ ( "ia_archiver", "Alexa Crawler"),
+ ( "MJ12bot", "Majestic"),
+ ( "Uptimebot", "Uptimebot"),
+ ( "CheckMarkNetwork", "CheckMark"),
+ ( "facebookexternalhit", "Facebook"),
+ ( "adscanner", "AdScanner"),
+ ( "AhrefsBot", "Ahrefs"),
+ ( "BLEXBot", "BLEXBot"),
+ ( "DotBot", "OpenSite"),
+ ( "Mail.RU_Bot", "Mail.ru"),
+ ( "MegaIndex", "MegaIndex"),
+ ( "SemrushBot", "SEMRush"),
+ ( "SEOkicks", "SEOkicks"),
+ ( "seoscanners.net", "SEO Scanners"),
+ ( "Sistrix", "Sistrix" )
+ ];
- ///
- /// Tools
- ///
- public static readonly Dictionary Tools = new()
- {
- { "curl", "curl" }
- };
- }
+ ///
+ /// Tools
+ ///
+ public static readonly Dictionary Tools = new()
+ {
+ { "curl", "curl" }
+ };
}
diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs
index c446baf..f0fe8f9 100644
--- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs
+++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs
@@ -1,23 +1,22 @@
// Copyright © myCSharp.de - all rights reserved
-namespace MyCSharp.HttpUserAgentParser
+namespace MyCSharp.HttpUserAgentParser;
+
+///
+/// HTTP User Agent Types
+///
+public enum HttpUserAgentType : byte
{
///
- /// HTTP User Agent Types
+ /// Unkown / not mapped
+ ///
+ Unknown,
+ ///
+ /// Browser
+ ///
+ Browser,
+ ///
+ /// Robot
///
- public enum HttpUserAgentType : byte
- {
- ///
- /// Unkown / not mapped
- ///
- Unknown,
- ///
- /// Browser
- ///
- Browser,
- ///
- /// Robot
- ///
- Robot,
- }
+ Robot,
}
diff --git a/src/MyCSharp.HttpUserAgentParser/MyCSharp.HttpUserAgentParser.csproj b/src/MyCSharp.HttpUserAgentParser/MyCSharp.HttpUserAgentParser.csproj
index ca4bc1c..43add95 100644
--- a/src/MyCSharp.HttpUserAgentParser/MyCSharp.HttpUserAgentParser.csproj
+++ b/src/MyCSharp.HttpUserAgentParser/MyCSharp.HttpUserAgentParser.csproj
@@ -18,10 +18,24 @@
-
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
diff --git a/src/MyCSharp.HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs b/src/MyCSharp.HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs
index 0a31abd..3f776bf 100644
--- a/src/MyCSharp.HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs
+++ b/src/MyCSharp.HttpUserAgentParser/Providers/HttpUserAgentParserCachedProvider.cs
@@ -2,32 +2,31 @@
using System.Collections.Concurrent;
-namespace MyCSharp.HttpUserAgentParser.Providers
+namespace MyCSharp.HttpUserAgentParser.Providers;
+
+///
+/// In process cache provider for
+///
+public class HttpUserAgentParserCachedProvider : IHttpUserAgentParserProvider
{
///
- /// In process cache provider for
+ /// internal cache
///
- public class HttpUserAgentParserCachedProvider : IHttpUserAgentParserProvider
- {
- ///
- /// internal cache
- ///
- private readonly ConcurrentDictionary _cache = new();
+ private readonly ConcurrentDictionary _cache = new();
- ///
- /// Parses the user agent or uses the internal cached information
- ///
- public HttpUserAgentInformation Parse(string userAgent)
- => _cache.GetOrAdd(userAgent, static ua => HttpUserAgentParser.Parse(ua));
+ ///
+ /// Parses the user agent or uses the internal cached information
+ ///
+ public HttpUserAgentInformation Parse(string userAgent)
+ => _cache.GetOrAdd(userAgent, static ua => HttpUserAgentParser.Parse(ua));
- ///
- /// Total count of entries in cache
- ///
- public int CacheEntryCount => _cache.Count;
+ ///
+ /// Total count of entries in cache
+ ///
+ public int CacheEntryCount => _cache.Count;
- ///
- /// returns true if given user agent is in cache
- ///
- public bool HasCacheEntry(string userAgent) => _cache.ContainsKey(userAgent);
- }
+ ///
+ /// returns true if given user agent is in cache
+ ///
+ public bool HasCacheEntry(string userAgent) => _cache.ContainsKey(userAgent);
}
diff --git a/src/MyCSharp.HttpUserAgentParser/Providers/HttpUserAgentParserDefaultProvider.cs b/src/MyCSharp.HttpUserAgentParser/Providers/HttpUserAgentParserDefaultProvider.cs
index 73e59df..7c0421b 100644
--- a/src/MyCSharp.HttpUserAgentParser/Providers/HttpUserAgentParserDefaultProvider.cs
+++ b/src/MyCSharp.HttpUserAgentParser/Providers/HttpUserAgentParserDefaultProvider.cs
@@ -1,16 +1,15 @@
// Copyright © myCSharp.de - all rights reserved
-namespace MyCSharp.HttpUserAgentParser.Providers
+namespace MyCSharp.HttpUserAgentParser.Providers;
+
+///
+/// Simple parse provider
+///
+public class HttpUserAgentParserDefaultProvider : IHttpUserAgentParserProvider
{
///
- /// Simple parse provider
+ /// returns the result of
///
- public class HttpUserAgentParserDefaultProvider : IHttpUserAgentParserProvider
- {
- ///
- /// returns the result of
- ///
- public HttpUserAgentInformation Parse(string userAgent)
- => HttpUserAgentParser.Parse(userAgent);
- }
+ public HttpUserAgentInformation Parse(string userAgent)
+ => HttpUserAgentParser.Parse(userAgent);
}
diff --git a/src/MyCSharp.HttpUserAgentParser/Providers/IHttpUserAgentParserProvider.cs b/src/MyCSharp.HttpUserAgentParser/Providers/IHttpUserAgentParserProvider.cs
index 4e3ad8a..e745240 100644
--- a/src/MyCSharp.HttpUserAgentParser/Providers/IHttpUserAgentParserProvider.cs
+++ b/src/MyCSharp.HttpUserAgentParser/Providers/IHttpUserAgentParserProvider.cs
@@ -1,17 +1,16 @@
// Copyright © myCSharp.de - all rights reserved
-namespace MyCSharp.HttpUserAgentParser.Providers
+namespace MyCSharp.HttpUserAgentParser.Providers;
+
+///
+/// Provides the basic parsing of user agent strings.
+///
+public interface IHttpUserAgentParserProvider
{
///
- /// Provides the basic parsing of user agent strings.
+ /// Parsed the -string.
///
- public interface IHttpUserAgentParserProvider
- {
- ///
- /// Parsed the -string.
- ///
- /// The user agent to parse.
- /// The parsed user agent information
- HttpUserAgentInformation Parse(string userAgent);
- }
+ /// The user agent to parse.
+ /// The parsed user agent information
+ HttpUserAgentInformation Parse(string userAgent);
}
diff --git a/tests/MyCSharp.HttpUserAgentParser.TestHelpers/HttpContextTestHelpers.cs b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpContextTestHelpers.cs
similarity index 84%
rename from tests/MyCSharp.HttpUserAgentParser.TestHelpers/HttpContextTestHelpers.cs
rename to tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpContextTestHelpers.cs
index 768ffa0..e8615d2 100644
--- a/tests/MyCSharp.HttpUserAgentParser.TestHelpers/HttpContextTestHelpers.cs
+++ b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpContextTestHelpers.cs
@@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Http;
-namespace MyCSharp.HttpUserAgentParser.TestHelpers;
+namespace MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests;
public static class HttpContextTestHelpers
{
diff --git a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs
index ccaf46b..ba7dd00 100644
--- a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs
+++ b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/HttpUserAgentParserAccessorTests.cs
@@ -3,7 +3,6 @@
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using MyCSharp.HttpUserAgentParser.Providers;
-using MyCSharp.HttpUserAgentParser.TestHelpers;
using NSubstitute;
using Xunit;
diff --git a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj
index f979669..7831f35 100644
--- a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj
+++ b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj
@@ -5,9 +5,24 @@
net7.0;net8.0
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
-
+
diff --git a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj
index ebbb18b..65fa6e2 100644
--- a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj
+++ b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj
@@ -5,7 +5,22 @@
net7.0;net8.0
-
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
+
diff --git a/tests/MyCSharp.HttpUserAgentParser.TestHelpers/MyCSharp.HttpUserAgentParser.TestHelpers.csproj b/tests/MyCSharp.HttpUserAgentParser.TestHelpers/MyCSharp.HttpUserAgentParser.TestHelpers.csproj
index b075017..8429490 100644
--- a/tests/MyCSharp.HttpUserAgentParser.TestHelpers/MyCSharp.HttpUserAgentParser.TestHelpers.csproj
+++ b/tests/MyCSharp.HttpUserAgentParser.TestHelpers/MyCSharp.HttpUserAgentParser.TestHelpers.csproj
@@ -10,8 +10,21 @@
-
-
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs
index ffb6699..ae03ea3 100644
--- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs
+++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs
@@ -10,13 +10,13 @@ namespace MyCSharp.HttpUserAgentParser.UnitTests.DependencyInjection;
public class UserAgentParserDependencyInjectionOptionsTests
{
- private readonly IServiceCollection scMock = Substitute.For();
+ private readonly IServiceCollection _scMock = Substitute.For();
[Fact]
public void Ctor_Should_Set_Property()
{
- HttpUserAgentParserDependencyInjectionOptions options = new(scMock);
+ HttpUserAgentParserDependencyInjectionOptions options = new(_scMock);
- options.Services.Should().BeEquivalentTo(scMock);
+ options.Services.Should().BeEquivalentTo(_scMock);
}
}
diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs
index 3c11fa3..675294a 100644
--- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs
+++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs
@@ -22,7 +22,6 @@ public void Parse(string userAgent)
[InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")]
public void CreateForRobot(string userAgent)
{
-
HttpUserAgentInformation ua = HttpUserAgentInformation.CreateForRobot(userAgent, "Chrome");
ua.UserAgent.Should().Be(userAgent);
diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj b/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj
index 8162c30..ce2a835 100644
--- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj
+++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj
@@ -5,9 +5,9 @@
net7.0;net8.0
-
+
-
+
@@ -22,6 +22,21 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+ all
+ runtime; build; native; contentfiles; analyzers
+
+
+
diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs
index ab6ef7d..6ee544b 100644
--- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs
+++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserCachedProviderTests.cs
@@ -4,50 +4,49 @@
using MyCSharp.HttpUserAgentParser.Providers;
using Xunit;
-namespace MyCSharp.HttpUserAgentParser.UnitTests.Providers
+namespace MyCSharp.HttpUserAgentParser.UnitTests.Providers;
+
+public class HttpUserAgentParserCachedProviderTests
{
- public class HttpUserAgentParserCachedProviderTests
+ [Fact]
+ public void Parse()
{
- [Fact]
- public void Parse()
- {
- HttpUserAgentParserCachedProvider provider = new HttpUserAgentParserCachedProvider();
+ HttpUserAgentParserCachedProvider provider = new HttpUserAgentParserCachedProvider();
- provider.CacheEntryCount.Should().Be(0);
+ provider.CacheEntryCount.Should().Be(0);
- // create first
- string userAgentOne =
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62";
+ // create first
+ string userAgentOne =
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62";
- HttpUserAgentInformation infoOne = provider.Parse(userAgentOne);
+ HttpUserAgentInformation infoOne = provider.Parse(userAgentOne);
- infoOne.Name.Should().Be("Edge");
- infoOne.Version.Should().Be("90.0.818.62");
+ infoOne.Name.Should().Be("Edge");
+ infoOne.Version.Should().Be("90.0.818.62");
- provider.CacheEntryCount.Should().Be(1);
- provider.HasCacheEntry(userAgentOne).Should().Be(true);
+ provider.CacheEntryCount.Should().Be(1);
+ provider.HasCacheEntry(userAgentOne).Should().Be(true);
- // check duplicate
+ // check duplicate
- HttpUserAgentInformation infoDuplicate = provider.Parse(userAgentOne);
+ HttpUserAgentInformation infoDuplicate = provider.Parse(userAgentOne);
- infoDuplicate.Name.Should().Be("Edge");
- infoDuplicate.Version.Should().Be("90.0.818.62");
+ infoDuplicate.Name.Should().Be("Edge");
+ infoDuplicate.Version.Should().Be("90.0.818.62");
- provider.CacheEntryCount.Should().Be(1);
- provider.HasCacheEntry(userAgentOne).Should().Be(true);
+ provider.CacheEntryCount.Should().Be(1);
+ provider.HasCacheEntry(userAgentOne).Should().Be(true);
- // create second
+ // create second
- string userAgentTwo = "Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0";
+ string userAgentTwo = "Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0";
- HttpUserAgentInformation infoTwo = provider.Parse(userAgentTwo);
+ HttpUserAgentInformation infoTwo = provider.Parse(userAgentTwo);
- infoTwo.Name.Should().Be("Firefox");
- infoTwo.Version.Should().Be("41.0");
+ infoTwo.Name.Should().Be("Firefox");
+ infoTwo.Version.Should().Be("41.0");
- provider.CacheEntryCount.Should().Be(2);
- provider.HasCacheEntry(userAgentTwo).Should().Be(true);
- }
+ provider.CacheEntryCount.Should().Be(2);
+ provider.HasCacheEntry(userAgentTwo).Should().Be(true);
}
}
diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserDefaultProviderTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserDefaultProviderTests.cs
index 04f59e8..134e6cb 100644
--- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserDefaultProviderTests.cs
+++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/Providers/HttpUserAgentParserDefaultProviderTests.cs
@@ -1,23 +1,22 @@
-// Copyright © myCSharp.de - all rights reserved
+// Copyright © myCSharp.de - all rights reserved
using FluentAssertions;
using MyCSharp.HttpUserAgentParser.Providers;
using Xunit;
-namespace MyCSharp.HttpUserAgentParser.UnitTests.Providers
+namespace MyCSharp.HttpUserAgentParser.UnitTests.Providers;
+
+public class HttpUserAgentParserDefaultProviderTests
{
- public class HttpUserAgentParserDefaultProviderTests
+ [Theory]
+ [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")]
+ public void Parse(string userAgent)
{
- [Theory]
- [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")]
- public void Parse(string userAgent)
- {
- HttpUserAgentParserDefaultProvider provider = new();
+ HttpUserAgentParserDefaultProvider provider = new();
- HttpUserAgentInformation providerUserAgentInfo = provider.Parse(userAgent);
- HttpUserAgentInformation userAgentInfo = HttpUserAgentInformation.Parse(userAgent);
+ HttpUserAgentInformation providerUserAgentInfo = provider.Parse(userAgent);
+ HttpUserAgentInformation userAgentInfo = HttpUserAgentInformation.Parse(userAgent);
- providerUserAgentInfo.Should().BeEquivalentTo(userAgentInfo);
- }
+ providerUserAgentInfo.Should().BeEquivalentTo(userAgentInfo);
}
}
diff --git a/version.json b/version.json
index 8c23c13..8417f92 100644
--- a/version.json
+++ b/version.json
@@ -2,18 +2,18 @@
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "3.0",
"nugetPackageVersion": {
- "semVer": 1 // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1.
+ "semVer": 1 // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1.
},
"publicReleaseRefSpec": [
- "^refs/heads/main$", // we release out of main
+ "^refs/heads/main$" // we release out of main
],
"cloudBuild": {
- "buildNumber": {
- "enabled": true
- }
+ "buildNumber": {
+ "enabled": true
+ }
},
"release": {
- "versionIncrement" : "build",
- "firstUnstableTag": "preview"
+ "versionIncrement": "build",
+ "firstUnstableTag": "preview"
}
- }
+}