Skip to content

Commit

Permalink
Fixing the composite filter conflict. Bumps to Wolverine 1.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Sep 10, 2023
1 parent 2e8e6d5 commit abd1fd8
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<NoWarn>1570;1571;1572;1573;1574;1587;1591;1701;1702;1711;1735;0618</NoWarn>
<ImplicitUsings>true</ImplicitUsings>
<Version>1.6.1</Version>
<Version>1.6.2</Version>
<RepositoryUrl>$(PackageProjectUrl)</RepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down
41 changes: 41 additions & 0 deletions src/Http/Wolverine.Http/HttpChainSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,47 @@ private IEnumerable<MethodCall> actionsFromType(Type type)
}
}

internal class CompositePredicate<T>
{
private readonly List<Func<T, bool>> _list = new List<Func<T, bool>>();
private Func<T, bool> _matchesAll = (Func<T, bool>) (_ => true);
private Func<T, bool> _matchesAny = (Func<T, bool>) (_ => true);
private Func<T, bool> _matchesNone = (Func<T, bool>) (_ => false);

public void Add(Func<T, bool> filter)
{
this._matchesAll = (Func<T, bool>) (x => this._list.All<Func<T, bool>>((Func<Func<T, bool>, bool>) (predicate => predicate(x))));
this._matchesAny = (Func<T, bool>) (x => this._list.Any<Func<T, bool>>((Func<Func<T, bool>, bool>) (predicate => predicate(x))));
this._matchesNone = (Func<T, bool>) (x => !this.MatchesAny(x));
this._list.Add(filter);
}

public static CompositePredicate<T> operator +(
CompositePredicate<T> invokes,
Func<T, bool> filter)
{
invokes.Add(filter);
return invokes;
}

public bool MatchesAll(T target) => this._matchesAll(target);

public bool MatchesAny(T target) => this._matchesAny(target);

public bool MatchesNone(T target) => this._matchesNone(target);

public bool DoesNotMatchAny(T target) => this._list.Count == 0 || !this.MatchesAny(target);
}

internal class CompositeFilter<T>
{
public CompositePredicate<T> Includes { get; set; } = new CompositePredicate<T>();

public CompositePredicate<T> Excludes { get; set; } = new CompositePredicate<T>();

public bool Matches(T target) => this.Includes.MatchesAny(target) && this.Excludes.DoesNotMatchAny(target);
}

internal class ActionMethodFilter : CompositeFilter<MethodInfo>
{
public ActionMethodFilter()
Expand Down
6 changes: 5 additions & 1 deletion src/Wolverine/Transports/MessageRoutingConvention.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using JasperFx.Core;
using JasperFx.Core.Filters;
using JasperFx.Core.Reflection;
using Wolverine.Configuration;
using Wolverine.Runtime;
Expand All @@ -15,7 +16,7 @@ public abstract class MessageRoutingConvention<TTransport, TListener, TSubscribe
/// <summary>
/// Optionally include (allow list) or exclude (deny list) types. By default, this will apply to all message types
/// </summary>
private readonly JasperFx.Core.CompositeFilter<Type> _typeFilters = new();
private readonly Util.CompositeFilter<Type> _typeFilters = new();

private Action<TListener, MessageRoutingContext> _configureListener = (_, _) => { };
private Action<TSubscriber, MessageRoutingContext> _configureSending = (_, _) => { };
Expand Down Expand Up @@ -200,4 +201,7 @@ public TSelf ConfigureSending(Action<TSubscriber, MessageRoutingContext> configu
_configureSending = configure ?? throw new ArgumentNullException(nameof(configure));
return this.As<TSelf>();
}



}
43 changes: 43 additions & 0 deletions src/Wolverine/Util/CompositeFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Wolverine.Util;

[Obsolete("Try to eliminate this, or put back in Jasperfx.core, or add excludes to type filter ")]
internal class CompositePredicate<T>
{
private readonly List<Func<T, bool>> _list = new List<Func<T, bool>>();
private Func<T, bool> _matchesAll = (Func<T, bool>) (_ => true);
private Func<T, bool> _matchesAny = (Func<T, bool>) (_ => true);
private Func<T, bool> _matchesNone = (Func<T, bool>) (_ => false);

public void Add(Func<T, bool> filter)
{
this._matchesAll = (Func<T, bool>) (x => this._list.All<Func<T, bool>>((Func<Func<T, bool>, bool>) (predicate => predicate(x))));
this._matchesAny = (Func<T, bool>) (x => this._list.Any<Func<T, bool>>((Func<Func<T, bool>, bool>) (predicate => predicate(x))));
this._matchesNone = (Func<T, bool>) (x => !this.MatchesAny(x));
this._list.Add(filter);
}

public static CompositePredicate<T> operator +(
CompositePredicate<T> invokes,
Func<T, bool> filter)
{
invokes.Add(filter);
return invokes;
}

public bool MatchesAll(T target) => this._matchesAll(target);

public bool MatchesAny(T target) => this._matchesAny(target);

public bool MatchesNone(T target) => this._matchesNone(target);

public bool DoesNotMatchAny(T target) => this._list.Count == 0 || !this.MatchesAny(target);
}

internal class CompositeFilter<T>
{
public CompositePredicate<T> Includes { get; set; } = new CompositePredicate<T>();

public CompositePredicate<T> Excludes { get; set; } = new CompositePredicate<T>();

public bool Matches(T target) => this.Includes.MatchesAny(target) && this.Excludes.DoesNotMatchAny(target);
}
2 changes: 1 addition & 1 deletion src/Wolverine/Wolverine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PackageReference Include="System.ComponentModel" Version="4.3.0" />
<PackageReference Include="JasperFx.CodeGeneration.Commands" Version="3.0.2" />
<PackageReference Include="JasperFx.RuntimeCompiler" Version="3.0.2" />
<PackageReference Include="JasperFx.Core" Version="1.4.0" />
<PackageReference Include="JasperFx.Core" Version="1.4.2" />
</ItemGroup>

<Import Project="../../Analysis.Build.props" />
Expand Down

0 comments on commit abd1fd8

Please sign in to comment.