Skip to content

Commit

Permalink
Many changes
Browse files Browse the repository at this point in the history
Fixed readonly access
Migrated to release .NET 8
Split Vogen into separate project
Added TransparentValueObjects as an alternative - WIP
Fixed ServiceProvider Too Many warning, thanks Npgsql
  • Loading branch information
Aragas committed Nov 24, 2023
1 parent 21b184d commit d048fa8
Show file tree
Hide file tree
Showing 152 changed files with 1,164 additions and 757 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PropertyGroup>
<!--SorceLink-->
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0" PrivateAssets="all" />
</ItemGroup>

Expand Down
32 changes: 16 additions & 16 deletions src/BUTR.Site.NexusMods.Client/BUTR.Site.NexusMods.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.4.0" />
<PackageReference Include="Blazored.SessionStorage" Version="2.4.0" />
<PackageReference Include="Blazorise.Bootstrap5" Version="1.3.2" />
<PackageReference Include="Blazorise.Charts" Version="1.3.2" />
<PackageReference Include="Blazorise.Components" Version="1.3.2" />
<PackageReference Include="Blazorise.DataGrid" Version="1.3.2" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.3.2" />
<PackageReference Include="Blazorise.LoadingIndicator" Version="1.3.2" />
<PackageReference Include="Blazorise.QRCode" Version="1.3.2" />
<PackageReference Include="Blazorise.Snackbar" Version="1.3.2" />
<PackageReference Include="Blazorise.TreeView" Version="1.3.2" />
<PackageReference Include="Blazorise.Bootstrap5" Version="1.3.3" />
<PackageReference Include="Blazorise.Charts" Version="1.3.3" />
<PackageReference Include="Blazorise.Components" Version="1.3.3" />
<PackageReference Include="Blazorise.DataGrid" Version="1.3.3" />
<PackageReference Include="Blazorise.Icons.FontAwesome" Version="1.3.3" />
<PackageReference Include="Blazorise.LoadingIndicator" Version="1.3.3" />
<PackageReference Include="Blazorise.QRCode" Version="1.3.3" />
<PackageReference Include="Blazorise.Snackbar" Version="1.3.3" />
<PackageReference Include="Blazorise.TreeView" Version="1.3.3" />
<PackageReference Include="BUTR.CrashReport.Models" Version="13.0.0.32" />
<PackageReference Include="BUTR.CrashReport.Bannerlord.Parser" Version="13.0.0.32" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0-rc.2.23480.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="8.0.0-rc.2.23480.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
<PackageReference Include="System.Text.Encodings.Web" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="System.Text.Encodings.Web" Version="8.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>BUTR.Site.NexusMods.Server.Models</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="TransparentValueObjects" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BUTR.Site.NexusMods.Shared\BUTR.Site.NexusMods.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<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:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utils/@EntryIndexedValue">False</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace BUTR.Site.NexusMods.Server.Models;

public static class OpenApiExtensions
{
public static void ValueObjectFilter(this SwaggerGenOptions opt)
{
opt.SchemaFilter<TransparentValueObjectSchemaFilter>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = ApplicationRole;
using TValueType = String;

[ValueObject<TValueType>]
public readonly partial struct ApplicationRole : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static readonly TType Anonymous = From(ApplicationRoles.Anonymous);
public static readonly TType User = From(ApplicationRoles.User);
public static readonly TType Moderator = From(ApplicationRoles.Moderator);
public static readonly TType Administrator = From(ApplicationRoles.Administrator);

public static TType DefaultValue => Anonymous;
}

public static class ApplicationRoleExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = CrashReportFileId;
using TValueType = String;

[ValueObject<TValueType>]
public readonly partial struct CrashReportFileId : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static TType DefaultValue => From(string.Empty);
}

public static class CrashReportFileIdExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = CrashReportId;
using TValueType = Guid;

[ValueObject<TValueType>]
public readonly partial struct CrashReportId : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static TType DefaultValue => From(Guid.Empty);

public static TType NewRandomValue(Random? random) => From(Guid.NewGuid());
}

public static class CrashReportIdExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = CrashReportUrl;
using TValueType = String;

[ValueObject<TValueType>]
public readonly partial struct CrashReportUrl : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static TType DefaultValue => From(string.Empty);

public static TType From(Uri uri) => From(uri.ToString());
}

public static class CrashReportUrlExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = CrashReportVersion;
using TValueType = Byte;

[ValueObject<TValueType>]
public readonly partial struct CrashReportVersion : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static TType DefaultValue => From(0);
}

public static class CrashReportVersionExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = ExceptionTypeId;
using TValueType = String;

[ValueObject<TValueType>]
public readonly partial struct ExceptionTypeId : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static TType DefaultValue => From(string.Empty);
}

public static class ExceptionTypeIdExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = GameVersion;
using TValueType = String;

[ValueObject<TValueType>]
public readonly partial struct GameVersion : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static TType DefaultValue => From(string.Empty);
}

public static class GameVersionExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace BUTR.Site.NexusMods.Server.Models;

internal interface IValueObjectFrom<TValueType, TInnerValue>
where TValueType : IValueObjectFrom<TValueType, TInnerValue>
{
static abstract explicit operator TValueType(TInnerValue value);
static abstract explicit operator TInnerValue(TValueType value);
static abstract TValueType From(TInnerValue value);
}
16 changes: 16 additions & 0 deletions src/BUTR.Site.NexusMods.Server.ValueObjects.TVO/Models/ModuleId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = ModuleId;
using TValueType = String;

[ValueObject<TValueType>]
public readonly partial struct ModuleId : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static TType DefaultValue => From(string.Empty);
}

public static class ModuleIdExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = ModuleVersion;
using TValueType = String;

[ValueObject<TValueType>]
public readonly partial struct ModuleVersion : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static TType DefaultValue => From(string.Empty);
}

public static class ModuleVersionExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = NexusModsApiKey;
using TValueType = String;

[TypeConverter(type: typeof(TransparentValueObjectTypeConverter<TType, TValueType>))]
[ValueObject<TValueType>]
public readonly partial struct NexusModsApiKey : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>, IValueObjectFrom<TType, TValueType>
{
public static readonly TType None = From(string.Empty);

public static TType DefaultValue => None;
}

public static class NexusModsApiKeyExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = NexusModsArticleId;
using TValueType = Int32;

[ValueObject<TValueType>]
public readonly partial struct NexusModsArticleId : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static readonly TType None = From(0);

public static TType DefaultValue => None;

public static bool TryParse(string articleIdRaw, out TType articleId)
{
var result = TValueType.TryParse(articleIdRaw, out var articleIdVal);
articleId = result ? From(articleIdVal) : DefaultValue;
return result;
}

public static bool TryParseUrl(string? urlRaw, out TType articleId)
{
articleId = From(0);

if (!Uri.TryCreate(urlRaw, UriKind.Absolute, out var url))
return false;

if (!url.Host.EndsWith("nexusmods.com"))
return false;

if (url.LocalPath.Split('/', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) is not [_, _, var articleIdRaw, ..])
return false;

return TryParse(articleIdRaw, out articleId);
}
}

public static class NexusModsArticleIdExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace BUTR.Site.NexusMods.Server.Models;

using TType = NexusModsFileId;
using TValueType = Int32;

[ValueObject<TValueType>]
public readonly partial struct NexusModsFileId : IAugmentWith<DefaultValueAugment, JsonAugment, EfCoreAugment>
{
public static TType DefaultValue => From(0);
}

public static class NexusModsFileIdExtension
{
public static PropertyBuilder<TType> HasValueObjectConversion(this PropertyBuilder<TType> propertyBuilder) => propertyBuilder
.HasConversion<TType.EfCoreValueConverter, TType.EfCoreValueComparer>();
}
Loading

0 comments on commit d048fa8

Please sign in to comment.