From 7ae5bdfcf088f680c408cc967497f2a740f17bea Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Fri, 26 Nov 2021 15:08:59 -0600 Subject: [PATCH] =?UTF-8?q?refactor(svcs):=20=E2=99=BB=F0=9F=94=A7=20confi?= =?UTF-8?q?g=20EMPTY=5FBLOCK=5FSTYLE,=20lint=20all?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FilterLists.Archival.Api/Program.cs | 2 +- .../Clients/IHttpContentClient.cs | 3 +- .../Commands/CreateList.cs | 7 +- .../ValidatorPipelineBahavior.cs | 3 +- .../Aggregates/AggregateRootCore.cs | 4 +- .../FilterLists/FilterListValueObject.cs | 3 +- .../Aggregates/Licenses/License.cs | 3 +- .../Commands/Context/CommandDbContext.cs | 7 +- .../Queries/Context/QueryDbContext.cs | 7 +- services/FilterLists.sln.DotSettings | 1 + .../Entity.cs | 30 +++++--- .../ValueObject.cs | 76 ++++++++++++------- 12 files changed, 87 insertions(+), 59 deletions(-) diff --git a/services/Archival/FilterLists.Archival.Api/Program.cs b/services/Archival/FilterLists.Archival.Api/Program.cs index 5f82a16af..1717ba104 100644 --- a/services/Archival/FilterLists.Archival.Api/Program.cs +++ b/services/Archival/FilterLists.Archival.Api/Program.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; +using FilterLists.Archival.Api; using FilterLists.Archival.Application; using FilterLists.SharedKernel.Logging; -using FilterLists.Archival.Api; var builder = WebApplication.CreateBuilder(args); diff --git a/services/Archival/FilterLists.Archival.Infrastructure/Clients/IHttpContentClient.cs b/services/Archival/FilterLists.Archival.Infrastructure/Clients/IHttpContentClient.cs index e56ba7f5d..9340ea7dd 100644 --- a/services/Archival/FilterLists.Archival.Infrastructure/Clients/IHttpContentClient.cs +++ b/services/Archival/FilterLists.Archival.Infrastructure/Clients/IHttpContentClient.cs @@ -16,7 +16,8 @@ internal sealed class HttpContentClient : IHttpContentClient public HttpContentClient(HttpClient httpClient, ILogger logger) { _httpClient = httpClient; - _httpClient.DefaultRequestHeaders.Add("User-Agent", + _httpClient.DefaultRequestHeaders.Add( + "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36"); _logger = logger; } diff --git a/services/Directory/FilterLists.Directory.Application/Commands/CreateList.cs b/services/Directory/FilterLists.Directory.Application/Commands/CreateList.cs index b3837812d..012ee7bc4 100644 --- a/services/Directory/FilterLists.Directory.Application/Commands/CreateList.cs +++ b/services/Directory/FilterLists.Directory.Application/Commands/CreateList.cs @@ -9,7 +9,8 @@ namespace FilterLists.Directory.Application.Commands; public static class CreateList { - public record Command(string Name, + public record Command( + string Name, IEnumerable ViewUrls, string? Description = default, long? LicenseId = default, @@ -79,7 +80,5 @@ public async Task Handle(Command request, CancellationToken cancellati } } - public record Response - { - } + public record Response { } } diff --git a/services/Directory/FilterLists.Directory.Application/ValidatorPipelineBahavior.cs b/services/Directory/FilterLists.Directory.Application/ValidatorPipelineBahavior.cs index 3afb1cf4e..74a3bccae 100644 --- a/services/Directory/FilterLists.Directory.Application/ValidatorPipelineBahavior.cs +++ b/services/Directory/FilterLists.Directory.Application/ValidatorPipelineBahavior.cs @@ -13,7 +13,8 @@ public ValidatorPipelineBehavior(IEnumerable> validators) _validators = validators; } - public async Task Handle(TRequest request, + public async Task Handle( + TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate next) { diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRootCore.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRootCore.cs index 8d934f14c..9ffdf8fbb 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRootCore.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/AggregateRootCore.cs @@ -1,5 +1,3 @@ namespace FilterLists.Directory.Domain.Aggregates; -public abstract class AggregateRootCore -{ -} +public abstract class AggregateRootCore { } diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListValueObject.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListValueObject.cs index ca529771b..138c351fe 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListValueObject.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/FilterLists/FilterListValueObject.cs @@ -43,10 +43,11 @@ public static FilterListValueObject FromFilterList(FilterList filterList) yield return Name; yield return Description; yield return LicenseId; - foreach (long viewUrlId in ViewUrlIds) + foreach (var viewUrlId in ViewUrlIds) { yield return viewUrlId; } + yield return HomeUrl; yield return OnionUrl; yield return PolicyUrl; diff --git a/services/Directory/FilterLists.Directory.Domain/Aggregates/Licenses/License.cs b/services/Directory/FilterLists.Directory.Domain/Aggregates/Licenses/License.cs index c50f51b22..316df6bbb 100644 --- a/services/Directory/FilterLists.Directory.Domain/Aggregates/Licenses/License.cs +++ b/services/Directory/FilterLists.Directory.Domain/Aggregates/Licenses/License.cs @@ -12,7 +12,8 @@ protected License() { } public bool PermitsDistribution { get; private init; } public bool PermitsCommercialUse { get; private init; } - public static License Create(string name, + public static License Create( + string name, Uri? url, bool permitsModification, bool permitsDistribution, diff --git a/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/Context/CommandDbContext.cs b/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/Context/CommandDbContext.cs index 55720239d..e473f3367 100644 --- a/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/Context/CommandDbContext.cs +++ b/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Commands/Context/CommandDbContext.cs @@ -14,16 +14,15 @@ static CommandDbContext() NpgsqlConnection.GlobalTypeMapper.MapEnum(); } - public CommandDbContext(DbContextOptions options) : base(options) - { - } + public CommandDbContext(DbContextOptions options) : base(options) { } public DbSet FilterLists => Set(); public DbSet Licenses => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly, + modelBuilder.ApplyConfigurationsFromAssembly( + GetType().Assembly, type => type.Namespace == typeof(FilterListTypeConfiguration).Namespace); modelBuilder.HasPostgresEnum(); } diff --git a/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Queries/Context/QueryDbContext.cs b/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Queries/Context/QueryDbContext.cs index 1714787e5..30dee42db 100644 --- a/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Queries/Context/QueryDbContext.cs +++ b/services/Directory/FilterLists.Directory.Infrastructure/Persistence/Queries/Context/QueryDbContext.cs @@ -12,9 +12,7 @@ static QueryDbContext() NpgsqlConnection.GlobalTypeMapper.MapEnum(); } - public QueryDbContext(DbContextOptions options) : base(options) - { - } + public QueryDbContext(DbContextOptions options) : base(options) { } public DbSet Changes => Set(); public DbSet FilterLists => Set(); @@ -39,7 +37,8 @@ public override Task SaveChangesAsync( protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly, + modelBuilder.ApplyConfigurationsFromAssembly( + GetType().Assembly, type => type.Namespace == typeof(FilterListTypeConfiguration).Namespace); modelBuilder.HasPostgresEnum(); } diff --git a/services/FilterLists.sln.DotSettings b/services/FilterLists.sln.DotSettings index 5b25572da..f84cbee11 100644 --- a/services/FilterLists.sln.DotSettings +++ b/services/FilterLists.sln.DotSettings @@ -1,4 +1,5 @@  + TOGETHER_SAME_LINE True True CHOP_IF_LONG diff --git a/services/SharedKernel/FilterLists.SharedKernel.Domain.SeedWork/Entity.cs b/services/SharedKernel/FilterLists.SharedKernel.Domain.SeedWork/Entity.cs index be5d5c066..61357e42f 100644 --- a/services/SharedKernel/FilterLists.SharedKernel.Domain.SeedWork/Entity.cs +++ b/services/SharedKernel/FilterLists.SharedKernel.Domain.SeedWork/Entity.cs @@ -1,34 +1,40 @@ namespace FilterLists.SharedKernel.Domain.SeedWork; /// -/// https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/Entity/Entity.cs +/// https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/Entity/Entity.cs /// public abstract class Entity { - public virtual TId Id { get; protected set; } = default!; - - protected Entity() - { - } + protected Entity() { } protected Entity(TId id) { Id = id; } + public virtual TId Id { get; protected set; } = default!; + public override bool Equals(object? obj) { if (obj is not Entity other) + { return false; + } if (ReferenceEquals(this, other)) + { return true; + } if (ValueObject.GetUnproxiedType(this) != ValueObject.GetUnproxiedType(other)) + { return false; + } if (IsTransient() || other.IsTransient()) + { return false; + } return Id is not null && Id.Equals(other.Id); } @@ -41,10 +47,14 @@ private bool IsTransient() public static bool operator ==(Entity? a, Entity? b) { if (a is null && b is null) + { return true; + } if (a is null || b is null) + { return false; + } return a.Equals(b); } @@ -62,12 +72,8 @@ public override int GetHashCode() public abstract class Entity : Entity { - protected Entity() - { - } + protected Entity() { } protected Entity(long id) - : base(id) - { - } + : base(id) { } } diff --git a/services/SharedKernel/FilterLists.SharedKernel.Domain.SeedWork/ValueObject.cs b/services/SharedKernel/FilterLists.SharedKernel.Domain.SeedWork/ValueObject.cs index a94d98be2..97f64cdca 100644 --- a/services/SharedKernel/FilterLists.SharedKernel.Domain.SeedWork/ValueObject.cs +++ b/services/SharedKernel/FilterLists.SharedKernel.Domain.SeedWork/ValueObject.cs @@ -1,26 +1,55 @@ namespace FilterLists.SharedKernel.Domain.SeedWork; /// -/// https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/ValueObject/ValueObject.cs +/// https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/ValueObject/ValueObject.cs /// [Serializable] public abstract class ValueObject : IComparable, IComparable { private int? _cachedHashCode; + public virtual int CompareTo(object? obj) + { + var thisType = GetUnproxiedType(this); + var otherType = GetUnproxiedType(obj); + + if (thisType != otherType) + { + return string.CompareOrdinal(thisType?.ToString(), otherType?.ToString()); + } + + var other = (ValueObject?)obj; + + var components = GetEqualityComponents().ToArray(); + var otherComponents = other?.GetEqualityComponents().ToArray() ?? Array.Empty(); + + return components.Select((t, i) => CompareComponents(t, otherComponents[i])) + .FirstOrDefault(comparison => comparison != 0); + } + + public virtual int CompareTo(ValueObject? other) + { + return CompareTo(other as object); + } + protected abstract IEnumerable GetEqualityComponents(); public override bool Equals(object? obj) { if (obj == null) + { return false; + } if (GetUnproxiedType(this) != GetUnproxiedType(obj)) + { return false; + } var valueObject = (ValueObject)obj; - return GetEqualityComponents().SequenceEqual(valueObject.GetEqualityComponents()); + return GetEqualityComponents() + .SequenceEqual(valueObject.GetEqualityComponents()); } public override int GetHashCode() @@ -32,59 +61,49 @@ public override int GetHashCode() { unchecked { - return current * 23 + (obj?.GetHashCode() ?? 0); + return (current * 23) + (obj?.GetHashCode() ?? 0); } }); return _cachedHashCode.Value; } - public virtual int CompareTo(object? obj) - { - var thisType = GetUnproxiedType(this); - var otherType = GetUnproxiedType(obj); - - if (thisType != otherType) - return string.CompareOrdinal(thisType?.ToString(), otherType?.ToString()); - - var other = (ValueObject?)obj; - - var components = GetEqualityComponents().ToArray(); - var otherComponents = other?.GetEqualityComponents().ToArray() ?? Array.Empty(); - - return components.Select((t, i) => CompareComponents(t, otherComponents[i])) - .FirstOrDefault(comparison => comparison != 0); - } - private static int CompareComponents(object? object1, object? object2) { if (object1 is null && object2 is null) + { return 0; + } if (object1 is null) + { return -1; + } if (object2 is null) + { return 1; + } if (object1 is IComparable comparable1 && object2 is IComparable comparable2) + { return comparable1.CompareTo(comparable2); + } return object1.Equals(object2) ? 0 : -1; } - public virtual int CompareTo(ValueObject? other) - { - return CompareTo(other as object); - } - public static bool operator ==(ValueObject? a, ValueObject? b) { if (a is null && b is null) + { return true; + } if (a is null || b is null) + { return false; + } return a.Equals(b); } @@ -100,10 +119,13 @@ public virtual int CompareTo(ValueObject? other) const string NHibernateProxyPostfix = "Proxy"; var type = obj?.GetType(); - string? typeString = type?.ToString(); + var typeString = type?.ToString(); - if (typeString is not null && (typeString.Contains(EFCoreProxyPrefix) || typeString.EndsWith(NHibernateProxyPostfix))) + if (typeString is not null && + (typeString.Contains(EFCoreProxyPrefix) || typeString.EndsWith(NHibernateProxyPostfix))) + { return type?.BaseType; + } return type; }