Skip to content

Commit d533854

Browse files
authored
Merge pull request #14 from mycsharp/feature/summary
add summaries
2 parents db43e69 + b72fba9 commit d533854

16 files changed

+289
-22
lines changed

src/MyCSharp.HttpUserAgentParser.AspNetCore/DependencyInjection/HttpUserAgentParserDependencyInjectionOptionsExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
// Copyright © myCSharp 2020-2021, all rights reserved
1+
// Copyright © myCSharp 2020-2021, all rights reserved
22

33
using Microsoft.Extensions.DependencyInjection;
44
using MyCSharp.HttpUserAgentParser.DependencyInjection;
55
using MyCSharp.HttpUserAgentParser.Providers;
66

77
namespace MyCSharp.HttpUserAgentParser.AspNetCore.DependencyInjection
88
{
9+
/// <summary>
10+
/// Dependency injection extensions for ASP.NET Core environments
11+
/// </summary>
912
public static class HttpUserAgentParserDependencyInjectionOptionsExtensions
1013
{
1114
/// <summary>
@@ -19,4 +22,4 @@ public static HttpUserAgentParserDependencyInjectionOptions AddHttpUserAgentPars
1922
return options;
2023
}
2124
}
22-
}
25+
}

src/MyCSharp.HttpUserAgentParser.AspNetCore/HttpUserAgentParserAccessor.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,48 @@
55

66
namespace MyCSharp.HttpUserAgentParser.AspNetCore
77
{
8+
/// <summary>
9+
/// User Agent parser accessor
10+
/// </summary>
811
public interface IHttpUserAgentParserAccessor
912
{
13+
/// <summary>
14+
/// User agent value
15+
/// </summary>
1016
string HttpContextUserAgent { get; }
17+
18+
/// <summary>
19+
/// Returns current <see cref="HttpUserAgentInformation"/>
20+
/// </summary>
1121
HttpUserAgentInformation Get();
1222
}
1323

24+
/// <summary>
25+
/// User Agent parser accessor. Implements <see cref="IHttpContextAccessor.HttpContext"/>
26+
/// </summary>
1427
public class HttpUserAgentParserAccessor : IHttpUserAgentParserAccessor
1528
{
1629
private readonly IHttpContextAccessor _httpContextAccessor;
1730
private readonly IHttpUserAgentParserProvider _httpUserAgentParser;
1831

32+
/// <summary>
33+
/// Creates a new instance of <see cref="HttpUserAgentParserAccessor"/>
34+
/// </summary>
1935
public HttpUserAgentParserAccessor(IHttpContextAccessor httpContextAccessor, IHttpUserAgentParserProvider httpUserAgentParser)
2036
{
2137
_httpContextAccessor = httpContextAccessor;
2238
_httpUserAgentParser = httpUserAgentParser;
2339
}
2440

41+
/// <summary>
42+
/// User agent of current <see cref="IHttpContextAccessor"/>
43+
/// </summary>
2544
public string HttpContextUserAgent =>
2645
_httpContextAccessor.HttpContext?.Request?.Headers["User-Agent"].ToString()!;
2746

47+
/// <summary>
48+
/// Returns current <see cref="HttpUserAgentInformation"/> of current <see cref="IHttpContextAccessor"/>
49+
/// </summary>
2850
public HttpUserAgentInformation Get()
2951
=> _httpUserAgentParser.Parse(this.HttpContextUserAgent);
3052
}

src/MyCSharp.HttpUserAgentParser.MemoryCache/DependencyInjection/HttpUserAgentParserMemoryCacheServiceCollectionExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © myCSharp 2020-2021, all rights reserved
1+
// Copyright © myCSharp 2020-2021, all rights reserved
22

33
using System;
44
using Microsoft.Extensions.DependencyInjection;
@@ -7,6 +7,9 @@
77

88
namespace MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection
99
{
10+
/// <summary>
11+
/// Dependency injection extensions for IMemoryCache
12+
/// </summary>
1013
public static class HttpUserAgentParserMemoryCacheServiceCollectionExtensions
1114
{
1215
/// <summary>

src/MyCSharp.HttpUserAgentParser.MemoryCache/HttpUserAgentParserMemoryCachedProviderOptions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,31 @@ namespace MyCSharp.HttpUserAgentParser.MemoryCache
1414
/// </summary>
1515
public class HttpUserAgentParserMemoryCachedProviderOptions
1616
{
17+
/// <summary>
18+
/// Cache options
19+
/// </summary>
1720
public MemoryCacheOptions CacheOptions { get; }
21+
22+
/// <summary>
23+
/// Cache entry options
24+
/// </summary>
1825
public MemoryCacheEntryOptions CacheEntryOptions { get; }
1926

27+
/// <summary>
28+
/// Creates a new instance of <see cref="HttpUserAgentParserMemoryCachedProviderOptions"/>
29+
/// </summary>
2030
public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheOptions cacheOptions)
2131
: this(cacheOptions, null) { }
2232

33+
/// <summary>
34+
/// Creates a new instance of <see cref="HttpUserAgentParserMemoryCachedProviderOptions"/>
35+
/// </summary>
2336
public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheEntryOptions cacheEntryOptions)
2437
: this(null, cacheEntryOptions) { }
2538

39+
/// <summary>
40+
/// Creates a new instance of <see cref="HttpUserAgentParserMemoryCachedProviderOptions"/>
41+
/// </summary>
2642
public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheOptions? cacheOptions = null, MemoryCacheEntryOptions? cacheEntryOptions = null)
2743
{
2844
this.CacheEntryOptions = cacheEntryOptions ?? new MemoryCacheEntryOptions
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
// Copyright © myCSharp 2020-2021, all rights reserved
1+
// Copyright © myCSharp 2020-2021, all rights reserved
22

33
using Microsoft.Extensions.DependencyInjection;
44

55
namespace MyCSharp.HttpUserAgentParser.DependencyInjection
66
{
7+
/// <summary>
8+
/// Options for dependency injection
9+
/// </summary>
710
public class HttpUserAgentParserDependencyInjectionOptions
811
{
12+
/// <summary>
13+
/// Services container
14+
/// </summary>
915
public IServiceCollection Services { get; }
1016

17+
/// <summary>
18+
/// Creates a new instance of <see cref="HttpUserAgentParserDependencyInjectionOptions"/>
19+
/// </summary>
20+
/// <param name="services"></param>
1121
public HttpUserAgentParserDependencyInjectionOptions(IServiceCollection services)
1222
{
1323
Services = services;
1424
}
1525
}
16-
}
26+
}

src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserServiceCollectionExtensions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
// Copyright © myCSharp 2020-2021, all rights reserved
1+
// Copyright © myCSharp 2020-2021, all rights reserved
22

33
using Microsoft.Extensions.DependencyInjection;
44
using MyCSharp.HttpUserAgentParser.Providers;
55

66
namespace MyCSharp.HttpUserAgentParser.DependencyInjection
77
{
8+
/// <summary>
9+
/// Dependency injection extensions
10+
/// </summary>
811
public static class HttpUserAgentParserServiceCollectionExtensions
912
{
1013
/// <summary>

src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformation.cs

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,46 @@
22

33
namespace MyCSharp.HttpUserAgentParser
44
{
5+
/// <summary>
6+
/// Analyzed user agent
7+
/// </summary>
58
public readonly struct HttpUserAgentInformation
69
{
10+
/// <summary>
11+
/// Full User Agent string
12+
/// </summary>
713
public string UserAgent { get; }
14+
15+
/// <summary>
16+
/// Type of user agent, see <see cref="HttpUserAgentType"/>
17+
/// </summary>
818
public HttpUserAgentType Type { get; }
919

20+
/// <summary>
21+
/// Platform of user agent, see <see cref="HttpUserAgentPlatformInformation"/>
22+
/// </summary>
1023
public HttpUserAgentPlatformInformation? Platform { get; }
24+
25+
/// <summary>
26+
/// Browser or Bot Name of user agent e.g. "Chrome", "Edge"..
27+
/// </summary>
1128
public string? Name { get; }
29+
30+
31+
/// <summary>
32+
/// Version of Browser or Bot Name of user agent e.g. "79.0", "83.0.125.4"
33+
/// </summary>
1234
public string? Version { get; }
35+
36+
37+
/// <summary>
38+
/// Device Type of user agent, e.g. "Android", "Apple iPhone"
39+
/// </summary>
1340
public string? MobileDeviceType { get; }
1441

42+
/// <summary>
43+
/// Creates a new instance of <see cref="HttpUserAgentInformation"/>
44+
/// </summary>
1545
private HttpUserAgentInformation(string userAgent, HttpUserAgentPlatformInformation? platform, HttpUserAgentType type, string? name, string? version, string? deviceName)
1646
{
1747
UserAgent = userAgent;
@@ -22,19 +52,27 @@ private HttpUserAgentInformation(string userAgent, HttpUserAgentPlatformInformat
2252
MobileDeviceType = deviceName;
2353
}
2454

25-
// parse
26-
55+
/// <summary>
56+
/// Parses given <param name="userAgent">User Agent</param>
57+
/// </summary>
2758
public static HttpUserAgentInformation Parse(string userAgent) => HttpUserAgentParser.Parse(userAgent);
2859

29-
// create factories
30-
31-
public static HttpUserAgentInformation CreateForRobot(string userAgent, string robotName)
60+
/// <summary>
61+
/// Creates <see cref="HttpUserAgentInformation"/> for a robot
62+
/// </summary>
63+
internal static HttpUserAgentInformation CreateForRobot(string userAgent, string robotName)
3264
=> new(userAgent, null, HttpUserAgentType.Robot, robotName, null, null);
3365

34-
public static HttpUserAgentInformation CreateForBrowser(string userAgent, HttpUserAgentPlatformInformation? platform, string? browserName, string? browserVersion, string? deviceName)
66+
/// <summary>
67+
/// Creates <see cref="HttpUserAgentInformation"/> for a browser
68+
/// </summary>
69+
internal static HttpUserAgentInformation CreateForBrowser(string userAgent, HttpUserAgentPlatformInformation? platform, string? browserName, string? browserVersion, string? deviceName)
3570
=> new(userAgent, platform, HttpUserAgentType.Browser, browserName, browserVersion, deviceName);
3671

37-
public static HttpUserAgentInformation CreateForUnknown(string userAgent, HttpUserAgentPlatformInformation? platform, string? deviceName)
72+
/// <summary>
73+
/// Creates <see cref="HttpUserAgentInformation"/> for an unknown agent type
74+
/// </summary>
75+
internal static HttpUserAgentInformation CreateForUnknown(string userAgent, HttpUserAgentPlatformInformation? platform, string? deviceName)
3876
=> new(userAgent, platform, HttpUserAgentType.Unknown, null, null, deviceName);
3977
}
4078
}
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
1-
// Copyright © myCSharp 2020-2021, all rights reserved
1+
// Copyright © myCSharp 2020-2021, all rights reserved
22

33
namespace MyCSharp.HttpUserAgentParser
44
{
5+
/// <summary>
6+
/// Extensions for <see cref="HttpUserAgentInformation"/>
7+
/// </summary>
58
public static class HttpUserAgentInformationExtensions
69
{
10+
/// <summary>
11+
/// Tests if <paramref name="userAgent"/> is of <paramref name="type" />
12+
/// </summary>
713
public static bool IsType(this in HttpUserAgentInformation userAgent, HttpUserAgentType type) => userAgent.Type == type;
14+
15+
/// <summary>
16+
/// Tests if <paramref name="userAgent"/> is of type <see cref="HttpUserAgentType.Robot"/>
17+
/// </summary>
818
public static bool IsRobot(this in HttpUserAgentInformation userAgent) => IsType(userAgent, HttpUserAgentType.Robot);
19+
20+
/// <summary>
21+
/// Tests if <paramref name="userAgent"/> is of type <see cref="HttpUserAgentType.Browser"/>
22+
/// </summary>
923
public static bool IsBrowser(this in HttpUserAgentInformation userAgent) => IsType(userAgent, HttpUserAgentType.Browser);
24+
25+
/// <summary>
26+
/// returns <c>true</c> if agent is a mobile device
27+
/// </summary>
28+
/// <remarks>checks if <see cref="HttpUserAgentInformation.MobileDeviceType"/> is null</remarks>
1029
public static bool IsMobile(this in HttpUserAgentInformation userAgent) => userAgent.MobileDeviceType is not null;
1130
}
1231
}

src/MyCSharp.HttpUserAgentParser/HttpUserAgentParser.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
// Copyright © myCSharp 2020-2021, all rights reserved
1+
// Copyright © myCSharp 2020-2021, all rights reserved
22

33
using System;
44
using System.Diagnostics.CodeAnalysis;
55
using System.Text.RegularExpressions;
66

77
namespace MyCSharp.HttpUserAgentParser
88
{
9+
/// <summary>
10+
/// Parser logic for user agents
11+
/// </summary>
912
public static class HttpUserAgentParser
1013
{
14+
/// <summary>
15+
/// Parses given <param name="userAgent">user agent</param>
16+
/// </summary>
1117
public static HttpUserAgentInformation Parse(string userAgent)
1218
{
1319
// prepare
@@ -30,8 +36,14 @@ public static HttpUserAgentInformation Parse(string userAgent)
3036
return HttpUserAgentInformation.CreateForUnknown(userAgent, platform, mobileDeviceType);
3137
}
3238

39+
/// <summary>
40+
/// pre-cleanup of <param name="userAgent">user agent</param>
41+
/// </summary>
3342
public static string Cleanup(string userAgent) => userAgent.Trim();
3443

44+
/// <summary>
45+
/// returns the platform or null
46+
/// </summary>
3547
public static HttpUserAgentPlatformInformation? GetPlatform(string userAgent)
3648
{
3749
foreach (HttpUserAgentPlatformInformation item in HttpUserAgentStatics.Platforms)
@@ -45,12 +57,18 @@ public static HttpUserAgentInformation Parse(string userAgent)
4557
return null;
4658
}
4759

60+
/// <summary>
61+
/// returns true if platform was found
62+
/// </summary>
4863
public static bool TryGetPlatform(string userAgent, [NotNullWhen(true)] out HttpUserAgentPlatformInformation? platform)
4964
{
5065
platform = GetPlatform(userAgent);
5166
return platform is not null;
5267
}
5368

69+
/// <summary>
70+
/// returns the browser or null
71+
/// </summary>
5472
public static (string Name, string? Version)? GetBrowser(string userAgent)
5573
{
5674
foreach ((Regex key, string? value) in HttpUserAgentStatics.Browsers)
@@ -65,12 +83,18 @@ public static (string Name, string? Version)? GetBrowser(string userAgent)
6583
return null;
6684
}
6785

86+
/// <summary>
87+
/// returns true if browser was found
88+
/// </summary>
6889
public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (string Name, string? Version)? browser)
6990
{
7091
browser = GetBrowser(userAgent);
7192
return browser is not null;
7293
}
7394

95+
/// <summary>
96+
/// returns the robot or null
97+
/// </summary>
7498
public static string? GetRobot(string userAgent)
7599
{
76100
foreach ((string key, string value) in HttpUserAgentStatics.Robots)
@@ -84,12 +108,18 @@ public static bool TryGetBrowser(string userAgent, [NotNullWhen(true)] out (stri
84108
return null;
85109
}
86110

111+
/// <summary>
112+
/// returns true if robot was found
113+
/// </summary>
87114
public static bool TryGetRobot(string userAgent, [NotNullWhen(true)] out string? robotName)
88115
{
89116
robotName = GetRobot(userAgent);
90117
return robotName is not null;
91118
}
92119

120+
/// <summary>
121+
/// returns the device or null
122+
/// </summary>
93123
public static string? GetMobileDevice(string userAgent)
94124
{
95125
foreach ((string key, string value) in HttpUserAgentStatics.Mobiles)
@@ -103,6 +133,9 @@ public static bool TryGetRobot(string userAgent, [NotNullWhen(true)] out string?
103133
return null;
104134
}
105135

136+
/// <summary>
137+
/// returns true if device was found
138+
/// </summary>
106139
public static bool TryGetMobileDevice(string userAgent, [NotNullWhen(true)] out string? device)
107140
{
108141
device = GetMobileDevice(userAgent);

0 commit comments

Comments
 (0)