Skip to content

Commit 798efad

Browse files
committed
Refactoring generator
1 parent d87f1e7 commit 798efad

File tree

4 files changed

+10
-26
lines changed

4 files changed

+10
-26
lines changed

src/ImageWizard.Core/Middlewares/ImageWizardExtensions.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ public static class ImageWizardExtensions
1717
/// <summary>
1818
/// Maps ImageWizard endpoint with specified base path.
1919
/// </summary>
20-
/// <param name="endpoints"></param>
21-
/// <param name="path"></param>
22-
/// <returns></returns>
2320
public static IEndpointConventionBuilder MapImageWizard(this IEndpointRouteBuilder endpoints, string path = ImageWizardDefaults.BasePath)
2421
{
2522
return endpoints
@@ -30,9 +27,6 @@ public static IEndpointConventionBuilder MapImageWizard(this IEndpointRouteBuild
3027
/// <summary>
3128
/// Use ImageWizard middleware with default base path. ("/image")
3229
/// </summary>
33-
/// <param name="builder"></param>
34-
/// <param name="endpointsHandler"></param>
35-
/// <returns></returns>
3630
public static IApplicationBuilder UseImageWizard(this IApplicationBuilder builder, Action<IImageWizardEndpointBuilder>? endpointsHandler = null)
3731
{
3832
return UseImageWizard(builder, ImageWizardDefaults.BasePath, endpointsHandler);
@@ -41,10 +35,6 @@ public static IApplicationBuilder UseImageWizard(this IApplicationBuilder builde
4135
/// <summary>
4236
/// Use ImageWizard middleware with specified base path.
4337
/// </summary>
44-
/// <param name="builder"></param>
45-
/// <param name="path"></param>
46-
/// <param name="endpointsHandler"></param>
47-
/// <returns></returns>
4838
public static IApplicationBuilder UseImageWizard(this IApplicationBuilder builder, string path, Action<IImageWizardEndpointBuilder>? endpointsHandler = null)
4939
{
5040
builder.Map(path, x =>
@@ -72,9 +62,6 @@ public static IApplicationBuilder UseImageWizard(this IApplicationBuilder builde
7262
/// <see cref="IUrlSignature"/> -> <see cref="HMACSHA256UrlSignature"/><br/>
7363
/// <see cref="IStreamPool"/> -> <see cref="RecyclableMemoryStreamPool"/><br/>
7464
/// </summary>
75-
/// <param name="services"></param>
76-
/// <param name="options"></param>
77-
/// <returns></returns>
7865
public static IImageWizardBuilder AddImageWizard(this IServiceCollection services, Action<ImageWizardOptions>? options = null)
7966
{
8067
if (options != null)

src/ImageWizard.Core/Pipelines/Factory/FilterAction.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
// MIT License
44

55
using Microsoft.Extensions.DependencyInjection;
6-
using System.Diagnostics.CodeAnalysis;
76
using System.Text.RegularExpressions;
87

98
namespace ImageWizard.Processing;
109

1110
public class FilterAction<TFilter> : IFilterAction
1211
where TFilter : IFilter
1312
{
14-
public delegate void FilterItemHandler(TFilter filer, GroupCollection groups);
13+
public delegate void FilterActionHandler(TFilter filer, GroupCollection groups);
1514

16-
public FilterAction(string name, [StringSyntax(StringSyntaxAttribute.Regex)]string pattern, FilterItemHandler handler)
15+
public FilterAction(string name, Regex pattern, FilterActionHandler handler)
1716
{
1817
Name = name;
19-
Regex = new Regex(pattern);
18+
Regex = pattern;
2019
Handler = handler;
2120
}
2221

@@ -33,7 +32,7 @@ public FilterAction(string name, [StringSyntax(StringSyntaxAttribute.Regex)]stri
3332
/// <summary>
3433
/// Handler
3534
/// </summary>
36-
public FilterItemHandler Handler { get; }
35+
public FilterActionHandler Handler { get; }
3736

3837
public bool TryExecute(IServiceProvider serviceProvider, string input, FilterContext filterContext)
3938
{

src/ImageWizard.Core/Pipelines/Pipeline.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,8 @@ public async Task<DataResult> StartAsync(PipelineContext context)
166166
preProcessing?.Invoke(filterContext);
167167

168168
//execute filters
169-
while (context.UrlFilters.Count > 0)
169+
while (context.UrlFilters.TryPeek(out FilterSegment segment))
170170
{
171-
FilterSegment segment = context.UrlFilters.Peek();
172-
173171
if (FilterFactories.TryGetValue(segment.Name, out var filters))
174172
{
175173
//find and execute filter

src/ImageWizard.Generators/FilterGenerator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private void Generate(SourceProductionContext context, ImmutableArray<GeneratorA
4747
string pattern = CreateParameterRegex(methodSymbol);
4848
string parser = CreateParameterParser(methodSymbol);
4949

50-
x.AppendLine($"new FilterAction<{group.Key.Identifier.Text}>(\"{method.TargetSymbol.Name.ToLower()}\", \"{pattern}\", (filter, group) => {{ {parser} }}),");
50+
x.AppendLine($"new FilterAction<{group.Key.Identifier.Text}>(\"{method.TargetSymbol.Name.ToLower()}\", new Regex(@\"{pattern}\"), (filter, group) => {{ {parser} }}),");
5151
}
5252
x.AppendLine("];");
5353
});
@@ -99,15 +99,15 @@ private string CreateParameterRegex(IMethodSymbol methodSymbol)
9999
or SpecialType.System_Int16
100100
or SpecialType.System_Int32
101101
or SpecialType.System_Int64
102-
=> @"-?\\d+",
102+
=> @"-?\d+",
103103

104104
SpecialType.System_Single
105105
or SpecialType.System_Double
106106
or SpecialType.System_Decimal
107-
=> @"-?\\d+\\.\\d+",
107+
=> @"-?\d+\.\d+",
108108

109109
SpecialType.System_Boolean => "True|False",
110-
SpecialType.System_String => @"(('[^']*')|([A-Za-z0-9-_\\s]+))",
110+
SpecialType.System_String => @"(('[^']*')|([A-Za-z0-9-_\s]+))",
111111

112112
_ => throw new Exception()
113113
};
@@ -120,7 +120,7 @@ or SpecialType.System_Decimal
120120
});
121121
}
122122

123-
return $@"^\\({string.Join(",", parameterItems.Select(x => x.Pattern).ToArray())}\\)$";
123+
return $@"^\({string.Join(",", parameterItems.Select(x => x.Pattern).ToArray())}\)$";
124124
}
125125

126126
private string CreateParameterParser(IMethodSymbol methodSymbol)

0 commit comments

Comments
 (0)