Skip to content

Commit

Permalink
Looks like the new Vogen broke on ARM64
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed May 26, 2024
1 parent 3db0a86 commit ec19326
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="BUTR.CrashReport.Models" Version="13.0.0.81" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Vogen" Version="4.0.5" />
<PackageReference Include="Vogen" Version="4.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/BUTR.Site.NexusMods.Server.ValueObjects.Vogen/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

global using Vogen;

/*
[assembly: VogenDefaults(
isInitializedMethodGeneration: IsInitializedMethodGeneration.Generate,
systemTextJsonConverterFactoryGeneration: SystemTextJsonConverterFactoryGeneration.Generate,
Expand All @@ -18,4 +19,5 @@
StaticAbstractsGeneration.EqualsOperators |
StaticAbstractsGeneration.FactoryMethods |
StaticAbstractsGeneration.InstanceMethodsAndProperties,
openApiSchemaCustomizations: OpenApiSchemaCustomizations.GenerateSwashbuckleSchemaFilter)]
openApiSchemaCustomizations: OpenApiSchemaCustomizations.GenerateSwashbuckleSchemaFilter)]
*/
31 changes: 31 additions & 0 deletions src/BUTR.Site.NexusMods.Server.ValueObjects.Vogen/Utils/IVogen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace BUTR.Site.NexusMods.Server.ValueObjects.Utils;

public interface IVogen<TVogen, TValueObject>
where TVogen : IVogen<TVogen, TValueObject>
where TValueObject : notnull
{
static abstract explicit operator TVogen(TValueObject value);
static abstract explicit operator TValueObject(TVogen value);

static abstract bool operator ==(TVogen left, TVogen right);
static abstract bool operator !=(TVogen left, TVogen right);

static abstract bool operator ==(TVogen left, TValueObject right);
static abstract bool operator !=(TVogen left, TValueObject right);

static abstract bool operator ==(TValueObject left, TVogen right);
static abstract bool operator !=(TValueObject left, TVogen right);

static abstract TVogen From(TValueObject value);

static abstract int GetHashCode(TVogen value);

static abstract bool Equals(TVogen left, TVogen right);
static abstract bool Equals(TVogen left, TVogen right, IEqualityComparer<TVogen> comparer);

static abstract int CompareTo(TVogen left, TVogen right);

TValueObject Value { get; }

bool IsInitialized();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace BUTR.Site.NexusMods.Server.ValueObjects.Utils;

public sealed class VogenSchemaFilter : ISchemaFilter
{
private static T CopyPublicProperties<T>(T oldObject, T newObject) where T : class
{
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;

if (ReferenceEquals(oldObject, newObject)) return newObject;

var type = typeof(T);
var propertyList = type.GetProperties(flags);
if (propertyList.Length <= 0) return newObject;

foreach (var newObjProp in propertyList)
{
var oldProp = type.GetProperty(newObjProp.Name, flags)!;
if (!oldProp.CanRead || !newObjProp.CanWrite) continue;

var value = oldProp.GetValue(oldObject);
newObjProp.SetValue(newObject, value);
}

return newObject;
}

public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
if (context.Type.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IVogen<,>)) is not { } vogen)
return;

if (vogen.GetGenericArguments() is not [_, { } valueObject])
return;

var schemaValueObject = context.SchemaGenerator.GenerateSchema(valueObject, context.SchemaRepository, context.MemberInfo, context.ParameterInfo);
CopyPublicProperties(schemaValueObject, schema);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ public async Task Execute(IJobExecutionContext context)

try
{
var apiKey = NexusModsApiKey.From(_nexusModsOptions.ApiKey);
var response = await _nexusModsAPIClient
.GetModFileInfosFullAsync(gameDomain, modId, apiKey, ct);
.GetModFileInfosFullAsync(gameDomain, modId, _nexusModsOptions.ApiKey, ct);
if (response is null)
{
notFoundMods++;
Expand All @@ -98,7 +97,7 @@ public async Task Execute(IJobExecutionContext context)
continue;
}

var infos = await _nexusModsModFileParser.GetModuleInfosAsync(gameDomain, modId, response.Files, apiKey, ct).ToArrayAsync(ct);
var infos = await _nexusModsModFileParser.GetModuleInfosAsync(gameDomain, modId, response.Files, _nexusModsOptions.ApiKey, ct).ToArrayAsync(ct);
var latestFileUpdate = DateTimeOffset.FromUnixTimeSeconds(response.Files.Select(x => x.UploadedTimestamp).Where(x => x is not null).Max() ?? 0).ToUniversalTime();

nexusModsModModuleEntities.AddRange(infos.Select(x => x.ModuleInfo).DistinctBy(x => x.Id).Select(x => new NexusModsModToModuleEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ public async Task Execute(IJobExecutionContext context)
await using var unitOfWrite = unitOfWorkFactory.CreateUnitOfWrite();

var gameDomain = tenant.ToGameDomain();
var apiKey = NexusModsApiKey.From(_nexusModsOptions.ApiKey);


var dateOneWeekAgo = DateTime.UtcNow.AddDays(-30);
var updatesStoredWithinWeek = await unitOfRead.NexusModsModToFileUpdates.GetAllAsync(x => x.LastCheckedDate > dateOneWeekAgo, null, ct);
var updatedWithinWeek = await _nexusModsAPIClient.GetAllModUpdatesWeekAsync(gameDomain, apiKey, ct) ?? Array.Empty<NexusModsUpdatedModsResponse>();
var updatedWithinWeek = await _nexusModsAPIClient.GetAllModUpdatesWeekAsync(gameDomain, _nexusModsOptions.ApiKey, ct) ?? Array.Empty<NexusModsUpdatedModsResponse>();
var newUpdates = updatedWithinWeek.Where(x =>
{
var latestFileUpdateDate = DateTimeOffset.FromUnixTimeSeconds(x.LatestFileUpdateTimestamp).ToUniversalTime();
Expand All @@ -100,12 +99,12 @@ public async Task Execute(IJobExecutionContext context)
{
if (ct.IsCancellationRequested) break;

if (await _nexusModsAPIClient.GetModFileInfosFullAsync(gameDomain, modUpdate.Id, apiKey, ct) is not { } response) continue;
if (await _nexusModsAPIClient.GetModFileInfosFullAsync(gameDomain, modUpdate.Id, _nexusModsOptions.ApiKey, ct) is not { } response) continue;

var updates = response.FileUpdates.Where(x => DateTimeOffset.FromUnixTimeSeconds(x.UploadedTimestamp) > dateOneWeekAgo).ToArray();
if (updates.Length == 0) continue;

var infos = await _nexusModsModFileParser.GetModuleInfosAsync(gameDomain, modUpdate.Id, response.Files.Where(x => updates.Any(y => y.NewId == x.FileId)), apiKey, ct).ToArrayAsync(ct);
var infos = await _nexusModsModFileParser.GetModuleInfosAsync(gameDomain, modUpdate.Id, response.Files.Where(x => updates.Any(y => y.NewId == x.FileId)), _nexusModsOptions.ApiKey, ct).ToArrayAsync(ct);
var lastUpdateTime = DateTimeOffset.FromUnixTimeSeconds(modUpdate.LatestFileUpdateTimestamp).ToUniversalTime();

unitOfWrite.NexusModsModModules.UpsertRange(infos.Select(x => x.ModuleInfo).DistinctBy(x => x.Id).Select(x => new NexusModsModToModuleEntity
Expand Down
3 changes: 1 addition & 2 deletions src/BUTR.Site.NexusMods.Server/Options/NexusModsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ public NexusModsOptionsValidator(HttpClient client)

public sealed record NexusModsOptions
{
// TODO:
public required string ApiKey { get; init; }
public required NexusModsApiKey ApiKey { get; init; } = NexusModsApiKey.None;
}
1 change: 1 addition & 0 deletions src/BUTR.Site.NexusMods.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Unicode;
using BUTR.Site.NexusMods.Server.ValueObjects.Utils;

namespace BUTR.Site.NexusMods.Server;

Expand Down

0 comments on commit ec19326

Please sign in to comment.