refactor(svcs): ♻🔧 config EMPTY_BLOCK_STYLE, lint all

This commit is contained in:
Collin M. Barrett 2021-11-26 15:08:59 -06:00
parent 9b60e9c72f
commit 7ae5bdfcf0
12 changed files with 87 additions and 59 deletions

View file

@ -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);

View file

@ -16,7 +16,8 @@ internal sealed class HttpContentClient : IHttpContentClient
public HttpContentClient(HttpClient httpClient, ILogger<HttpContentClient> 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;
}

View file

@ -9,7 +9,8 @@ namespace FilterLists.Directory.Application.Commands;
public static class CreateList
{
public record Command(string Name,
public record Command(
string Name,
IEnumerable<FilterListViewUrl> ViewUrls,
string? Description = default,
long? LicenseId = default,
@ -79,7 +80,5 @@ public async Task<Response> Handle(Command request, CancellationToken cancellati
}
}
public record Response
{
}
public record Response { }
}

View file

@ -13,7 +13,8 @@ public ValidatorPipelineBehavior(IEnumerable<IValidator<TRequest>> validators)
_validators = validators;
}
public async Task<TResponse> Handle(TRequest request,
public async Task<TResponse> Handle(
TRequest request,
CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
{

View file

@ -1,5 +1,3 @@
namespace FilterLists.Directory.Domain.Aggregates;
public abstract class AggregateRootCore
{
}
public abstract class AggregateRootCore { }

View file

@ -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;

View file

@ -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,

View file

@ -14,16 +14,15 @@ static CommandDbContext()
NpgsqlConnection.GlobalTypeMapper.MapEnum<AggregateType>();
}
public CommandDbContext(DbContextOptions<CommandDbContext> options) : base(options)
{
}
public CommandDbContext(DbContextOptions<CommandDbContext> options) : base(options) { }
public DbSet<FilterList> FilterLists => Set<FilterList>();
public DbSet<License> Licenses => Set<License>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly,
modelBuilder.ApplyConfigurationsFromAssembly(
GetType().Assembly,
type => type.Namespace == typeof(FilterListTypeConfiguration).Namespace);
modelBuilder.HasPostgresEnum<AggregateType>();
}

View file

@ -12,9 +12,7 @@ static QueryDbContext()
NpgsqlConnection.GlobalTypeMapper.MapEnum<AggregateType>();
}
public QueryDbContext(DbContextOptions<QueryDbContext> options) : base(options)
{
}
public QueryDbContext(DbContextOptions<QueryDbContext> options) : base(options) { }
public DbSet<Change> Changes => Set<Change>();
public DbSet<FilterList> FilterLists => Set<FilterList>();
@ -39,7 +37,8 @@ public override Task<int> SaveChangesAsync(
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly,
modelBuilder.ApplyConfigurationsFromAssembly(
GetType().Assembly,
type => type.Namespace == typeof(FilterListTypeConfiguration).Namespace);
modelBuilder.HasPostgresEnum<AggregateType>();
}

View file

@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EMPTY_BLOCK_STYLE/@EntryValue">TOGETHER_SAME_LINE</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_DECLARATION_LPAR/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_INVOCATION_LPAR/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARGUMENTS_STYLE/@EntryValue">CHOP_IF_LONG</s:String>

View file

@ -1,34 +1,40 @@
namespace FilterLists.SharedKernel.Domain.SeedWork;
/// <summary>
/// https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/Entity/Entity.cs
/// https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/Entity/Entity.cs
/// </summary>
public abstract class Entity<TId>
{
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<TId> 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<TId>? a, Entity<TId>? 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<long>
{
protected Entity()
{
}
protected Entity() { }
protected Entity(long id)
: base(id)
{
}
: base(id) { }
}

View file

@ -1,26 +1,55 @@
namespace FilterLists.SharedKernel.Domain.SeedWork;
/// <summary>
/// https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/ValueObject/ValueObject.cs
/// https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/ValueObject/ValueObject.cs
/// </summary>
[Serializable]
public abstract class ValueObject : IComparable, IComparable<ValueObject>
{
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<object?>();
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<object?> 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<object?>();
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;
}