Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add init #1

Merged
merged 36 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f8e0d22
add init
BenjaminAbt May 15, 2021
de35be3
add bot tests
BenjaminAbt May 15, 2021
f5fd2ad
add regex map
BenjaminAbt May 15, 2021
0f313b9
Apply suggestions from code review
BenjaminAbt May 16, 2021
98cdb64
add memory cache implementation
BenjaminAbt May 16, 2021
7e597e1
add regex
BenjaminAbt May 16, 2021
398e922
remove custom
BenjaminAbt May 16, 2021
e2612ce
add factories
BenjaminAbt May 16, 2021
530468f
remove redirect
BenjaminAbt May 16, 2021
7c5146a
fix naming
BenjaminAbt May 16, 2021
1079944
add cache feedback
BenjaminAbt May 16, 2021
e9016f8
add feedback
BenjaminAbt May 16, 2021
98d6883
remove doubled ctor
BenjaminAbt May 16, 2021
50ec686
add feedback
BenjaminAbt May 16, 2021
76cb8bd
add docs
BenjaminAbt May 16, 2021
6506c43
add feedback
BenjaminAbt May 16, 2021
bfd72a4
add code cleanup
BenjaminAbt May 16, 2021
8da5e86
add docs
BenjaminAbt May 16, 2021
b46a8c8
add docs
BenjaminAbt May 16, 2021
fd79a9f
add feedback
BenjaminAbt May 16, 2021
32f99f4
add docs
BenjaminAbt May 16, 2021
d5c5760
add auto cleanup editconfig
BenjaminAbt May 16, 2021
7401c0e
add feedback
BenjaminAbt May 16, 2021
ed4f6be
add tests
BenjaminAbt May 16, 2021
b268088
add tests
BenjaminAbt May 16, 2021
59a9a5c
add tests
BenjaminAbt May 16, 2021
c412b2d
add tests
BenjaminAbt May 16, 2021
9dfc771
add tests
BenjaminAbt May 16, 2021
59700e3
add cicd
BenjaminAbt May 17, 2021
40fb27e
add feedback
BenjaminAbt May 17, 2021
eaa8a22
add nuget stuff
BenjaminAbt May 17, 2021
06e50e4
add docs
BenjaminAbt May 17, 2021
95593cb
add benchmark
BenjaminAbt May 17, 2021
e0da0a3
add benchmark
BenjaminAbt May 17, 2021
c5ab071
add benchmarks
BenjaminAbt May 17, 2021
8ab6364
fix doc
BenjaminAbt May 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions MyCSharp.HttpUserAgentParser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyCSharp.HttpUserAgentParse
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F54C9296-4EF7-40F0-9F20-F23A2270ABC9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyCSharp.HttpUserAgentParser.MemoryCache", "src\MyCSharp.HttpUserAgentParser.MemoryCache\MyCSharp.HttpUserAgentParser.MemoryCache.csproj", "{3C8CCD44-F47C-4624-8997-54C42F02E376}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -37,6 +39,10 @@ Global
{75960783-8BF9-479C-9ECF-E9653B74C9A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75960783-8BF9-479C-9ECF-E9653B74C9A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75960783-8BF9-479C-9ECF-E9653B74C9A2}.Release|Any CPU.Build.0 = Release|Any CPU
{3C8CCD44-F47C-4624-8997-54C42F02E376}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C8CCD44-F47C-4624-8997-54C42F02E376}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C8CCD44-F47C-4624-8997-54C42F02E376}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C8CCD44-F47C-4624-8997-54C42F02E376}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -46,6 +52,7 @@ Global
{3357BEC0-8216-409E-A539-F9A71DBACB81} = {008A2BAB-78B4-42EB-A5D4-DE434438CEF0}
{F16697F7-74B4-441D-A0C0-1A0572AC3AB0} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9}
{75960783-8BF9-479C-9ECF-E9653B74C9A2} = {F54C9296-4EF7-40F0-9F20-F23A2270ABC9}
{3C8CCD44-F47C-4624-8997-54C42F02E376} = {008A2BAB-78B4-42EB-A5D4-DE434438CEF0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E8B0C994-0BF2-4692-9E22-E48B265B2804}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using MyCSharp.HttpUserAgentParser.DependencyInjection;
using MyCSharp.HttpUserAgentParser.Providers;

namespace MyCSharp.HttpUserAgentParser.MemoryCache.DependencyInjection
{
public static class HttpUserAgentParserMemoryCacheServiceCollectionExtensions
{
/// <summary>
/// Registers <see cref="CachedHttpUserAgentParserProvider"/> as singleton to <see cref="IHttpUserAgentParserProvider"/>
/// </summary>
public static HttpUserAgentParserDependencyInjectionOptions AddMemoryCachedHttpUserAgentParser(
this IServiceCollection services, Action<HttpUserAgentParserMemoryCachedProviderOptions>? options = null)
{
HttpUserAgentParserMemoryCachedProviderOptions providerOptions = new();
options?.Invoke(providerOptions);

// register options
services.AddSingleton(providerOptions);

// register cache provider
return services.AddHttpUserAgentParser<HttpUserAgentParserMemoryCachedProvider>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.Extensions.Caching.Memory;
using MyCSharp.HttpUserAgentParser.Providers;

namespace MyCSharp.HttpUserAgentParser.MemoryCache
{
public class HttpUserAgentParserMemoryCachedProvider : IHttpUserAgentParserProvider
{
private readonly IMemoryCache _memoryCache;
private readonly HttpUserAgentParserMemoryCachedProviderOptions _options;

public HttpUserAgentParserMemoryCachedProvider(IMemoryCache memoryCache, HttpUserAgentParserMemoryCachedProviderOptions options)
{
_memoryCache = memoryCache;
_options = options;
}

private static string Cleanup(string userAgent)
=> userAgent.Trim();


public HttpUserAgentInformation Parse(string userAgent)
{
return _memoryCache.GetOrCreate(Cleanup(userAgent), entry =>
BenjaminAbt marked this conversation as resolved.
Show resolved Hide resolved
{
entry.SlidingExpiration = _options.CacheEntryOptions.SlidingExpiration;
BenjaminAbt marked this conversation as resolved.
Show resolved Hide resolved
return HttpUserAgentInformation.Parse(userAgent);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Microsoft.Extensions.Caching.Memory;

namespace MyCSharp.HttpUserAgentParser.MemoryCache
{
public class HttpUserAgentParserMemoryCachedProviderOptions
{
/// <summary>
/// Default of <seealso cref="MemoryCacheOptions.SizeLimit"/> is 256.
/// Default of <seealso cref="MemoryCacheEntryOptions.SlidingExpiration"/> is 1 day
/// </summary>
public MemoryCacheOptions CacheOptions { get; }
public MemoryCacheEntryOptions CacheEntryOptions { get; }

public HttpUserAgentParserMemoryCachedProviderOptions()
: this(null, null) { }

public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheOptions cacheOptions)
: this(cacheOptions, null) { }


public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheEntryOptions cacheEntryOptions)
: this(null, cacheEntryOptions) { }

public HttpUserAgentParserMemoryCachedProviderOptions(MemoryCacheOptions? cacheOptions = null, MemoryCacheEntryOptions? cacheEntryOptions = null)
{
CacheEntryOptions = cacheEntryOptions ?? new MemoryCacheEntryOptions
{
// defaults
SlidingExpiration = TimeSpan.FromDays(1)
};
CacheOptions = cacheOptions ?? new MemoryCacheOptions
{
SizeLimit = 256
BenjaminAbt marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MyCSharp.HttpUserAgentParser.AspNetCore\MyCSharp.HttpUserAgentParser.AspNetCore.csproj" />
<ProjectReference Include="..\MyCSharp.HttpUserAgentParser\MyCSharp.HttpUserAgentParser.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class DefaultHttpUserAgentParserProvider : IHttpUserAgentParserProvider
{
public HttpUserAgentInformation Parse(string userAgent)
=> HttpUserAgentParser.Parse(userAgent);
=> HttpUserAgentInformation.Parse(userAgent);
BenjaminAbt marked this conversation as resolved.
Show resolved Hide resolved
}
}