diff --git a/src/ModVerify/ModVerify.csproj b/src/ModVerify/ModVerify.csproj index 8febcd9..bc7995d 100644 --- a/src/ModVerify/ModVerify.csproj +++ b/src/ModVerify/ModVerify.csproj @@ -20,7 +20,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/ModVerify/Steps/GameVerificationStep.cs b/src/ModVerify/Steps/GameVerificationStep.cs index 295cd70..f759843 100644 --- a/src/ModVerify/Steps/GameVerificationStep.cs +++ b/src/ModVerify/Steps/GameVerificationStep.cs @@ -8,13 +8,11 @@ using Microsoft.Extensions.Logging; using PG.StarWarsGame.Engine; using PG.StarWarsGame.Engine.FileSystem; -using PG.StarWarsGame.Engine.Pipeline; namespace AET.ModVerify.Steps; public abstract class GameVerificationStep( - CreateGameDatabaseStep createDatabaseStep, - IGameRepository repository, + GameDatabase gameDatabase, VerificationSettings settings, IServiceProvider serviceProvider) : PipelineStep(serviceProvider) @@ -28,9 +26,9 @@ public abstract class GameVerificationStep( protected VerificationSettings Settings { get; } = settings; - protected GameDatabase Database { get; private set; } = null!; + protected GameDatabase Database { get; } = gameDatabase ?? throw new ArgumentNullException(nameof(gameDatabase)); - protected IGameRepository Repository => repository; + protected IGameRepository Repository => gameDatabase.GameRepository; protected abstract string LogFileName { get; } @@ -38,9 +36,6 @@ public abstract class GameVerificationStep( protected sealed override void RunCore(CancellationToken token) { - createDatabaseStep.Wait(); - Database = createDatabaseStep.GameDatabase; - Logger?.LogInformation($"Running verifier '{Name}'..."); try { @@ -57,12 +52,11 @@ protected sealed override void RunCore(CancellationToken token) protected abstract void RunVerification(CancellationToken token); - protected void AddError(VerificationError error) { if (!OnError(error)) { - Logger?.LogTrace($"Error suppressed: '{error}'"); + Logger?.LogTrace($"Error suppressed for verifier '{Name}': '{error}'"); return; } _verifyErrors.Add(error); diff --git a/src/ModVerify/Steps/VerifyReferencedModelsStep.cs b/src/ModVerify/Steps/VerifyReferencedModelsStep.cs index 5151e5b..1494181 100644 --- a/src/ModVerify/Steps/VerifyReferencedModelsStep.cs +++ b/src/ModVerify/Steps/VerifyReferencedModelsStep.cs @@ -8,8 +8,6 @@ using PG.Commons.Files; using PG.Commons.Utilities; using PG.StarWarsGame.Engine; -using PG.StarWarsGame.Engine.FileSystem; -using PG.StarWarsGame.Engine.Pipeline; using PG.StarWarsGame.Files.ALO.Files.Models; using PG.StarWarsGame.Files.ALO.Files.Particles; using PG.StarWarsGame.Files.ALO.Services; @@ -18,11 +16,10 @@ namespace AET.ModVerify.Steps; internal sealed class VerifyReferencedModelsStep( - CreateGameDatabaseStep createDatabaseStep, - IGameRepository repository, + GameDatabase database, VerificationSettings settings, IServiceProvider serviceProvider) - : GameVerificationStep(createDatabaseStep, repository, settings, serviceProvider) + : GameVerificationStep(database, settings, serviceProvider) { public const string ModelNotFound = "ALO00"; public const string ModelBroken = "ALO01"; diff --git a/src/ModVerify/VerifyGamePipeline.cs b/src/ModVerify/VerifyGamePipeline.cs index 8b51723..e1a17ad 100644 --- a/src/ModVerify/VerifyGamePipeline.cs +++ b/src/ModVerify/VerifyGamePipeline.cs @@ -5,49 +5,42 @@ using System.Threading.Tasks; using AET.ModVerify.Steps; using AnakinRaW.CommonUtilities.SimplePipeline; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PG.StarWarsGame.Engine.FileSystem; using PG.StarWarsGame.Engine.Pipeline; namespace AET.ModVerify; -public class VerifyGamePipeline : ParallelPipeline +public abstract class VerifyGamePipeline : Pipeline { - private IList _verificationSteps = null!; - private readonly IGameRepository _repository; + private IList _verificationSteps = new List(); + private readonly GameLocations _gameLocations; private readonly VerificationSettings _settings; - public VerifyGamePipeline(IGameRepository gameRepository, VerificationSettings settings, IServiceProvider serviceProvider) - : base(serviceProvider, 4, false) + protected VerifyGamePipeline(GameLocations gameLocations, VerificationSettings settings, IServiceProvider serviceProvider) + : base(serviceProvider) { - _repository = gameRepository; - _settings = settings; + _gameLocations = gameLocations ?? throw new ArgumentNullException(nameof(gameLocations)); + _settings = settings ?? throw new ArgumentNullException(nameof(settings)); } - protected override Task> BuildSteps() - { - var buildIndexStep = new CreateGameDatabaseStep(_repository, ServiceProvider); - - _verificationSteps = new List - { - new VerifyReferencedModelsStep(buildIndexStep, _repository, _settings, ServiceProvider), - }; - - var allSteps = new List - { - buildIndexStep - }; - allSteps.AddRange(_verificationSteps); - return Task.FromResult>(allSteps); + protected override Task PrepareCoreAsync() + { + throw new NotImplementedException(); } - public override async Task RunAsync(CancellationToken token = default) + protected override async Task RunCoreAsync(CancellationToken token) { Logger?.LogInformation("Verifying game..."); try { - await base.RunAsync(token).ConfigureAwait(false); + var databaseService = ServiceProvider.GetRequiredService(); + + await databaseService.CreateDatabaseAsync() + + var stepsWithVerificationErrors = _verificationSteps.Where(x => x.VerifyErrors.Any()).ToList(); @@ -69,4 +62,26 @@ public override async Task RunAsync(CancellationToken token = default) Logger?.LogInformation("Finished game verification"); } } + + + //protected sealed override async Task> BuildSteps() + //{ + // var buildIndexStep = new CreateGameDatabaseStep(_repository, ServiceProvider); + + // _verificationSteps = new List + // { + // new VerifyReferencedModelsStep(buildIndexStep, _repository, _settings, ServiceProvider), + // }; + + // var allSteps = new List + // { + // buildIndexStep + // }; + // allSteps.AddRange(CreateVeificationSteps()); + + // return allSteps; + //} + + + protected abstract IEnumerable CreateVerificationSteps(); } \ No newline at end of file diff --git a/src/PetroglyphTools/PG.StarWarsGame.Engine/GameDatabase.cs b/src/PetroglyphTools/PG.StarWarsGame.Engine/GameDatabase.cs index 7abf073..152e811 100644 --- a/src/PetroglyphTools/PG.StarWarsGame.Engine/GameDatabase.cs +++ b/src/PetroglyphTools/PG.StarWarsGame.Engine/GameDatabase.cs @@ -1,11 +1,12 @@ using System.Collections.Generic; using PG.StarWarsGame.Engine.DataTypes; +using PG.StarWarsGame.Engine.FileSystem; namespace PG.StarWarsGame.Engine; public class GameDatabase { - public required GameEngineType EngineType { get; init; } + public required IGameRepository GameRepository { get; init; } public required GameConstants GameConstants { get; init; } diff --git a/src/PetroglyphTools/PG.StarWarsGame.Engine/PG.StarWarsGame.Engine.csproj b/src/PetroglyphTools/PG.StarWarsGame.Engine/PG.StarWarsGame.Engine.csproj index 4487bb3..ba82246 100644 --- a/src/PetroglyphTools/PG.StarWarsGame.Engine/PG.StarWarsGame.Engine.csproj +++ b/src/PetroglyphTools/PG.StarWarsGame.Engine/PG.StarWarsGame.Engine.csproj @@ -17,7 +17,7 @@ true - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/PetroglyphTools/PG.StarWarsGame.Engine/Pipeline/CreateGameDatabasePipeline.cs b/src/PetroglyphTools/PG.StarWarsGame.Engine/Pipeline/CreateGameDatabasePipeline.cs index 53fb102..d1973b7 100644 --- a/src/PetroglyphTools/PG.StarWarsGame.Engine/Pipeline/CreateGameDatabasePipeline.cs +++ b/src/PetroglyphTools/PG.StarWarsGame.Engine/Pipeline/CreateGameDatabasePipeline.cs @@ -4,13 +4,28 @@ using System.Threading; using System.Threading.Tasks; using AnakinRaW.CommonUtilities.SimplePipeline; +using Microsoft.Extensions.Logging; using PG.StarWarsGame.Engine.DataTypes; using PG.StarWarsGame.Engine.FileSystem; namespace PG.StarWarsGame.Engine.Pipeline; -internal class CreateGameDatabasePipeline(IGameRepository repository, IServiceProvider serviceProvider) - : ParallelPipeline(serviceProvider) +public interface IGameDatabaseService +{ + Task CreateDatabaseAsync(GameEngineType targetEngineType, GameLocations locations, CancellationToken cancellationToken = default); +} + +internal class GameDatabaseService(IServiceProvider serviceProvider) : IGameDatabaseService +{ + public async Task CreateDatabaseAsync(GameEngineType targetEngineType, GameLocations locations, CancellationToken cancellationToken = default) + { + var pipeline = new GameDatabaseCreationPipeline(repository, serviceProvider, cancellationToken); + await pipeline.RunAsync(cancellationToken); + return pipeline.GameDatabase; + } +} + +internal class GameDatabaseCreationPipeline(GameRepository repository, IServiceProvider serviceProvider) : ParallelPipeline(serviceProvider) { private ParseSingletonXmlStep _parseGameConstants = null!; private ParseFromContainerStep _parseGameObjects = null!; @@ -71,14 +86,22 @@ protected override Task> BuildSteps() protected override async Task RunCoreAsync(CancellationToken token) { - await base.RunCoreAsync(token); + Logger?.LogInformation("Creating Game Database..."); - GameDatabase = new GameDatabase + try { - EngineType = repository.EngineType, - GameConstants = _parseGameConstants.Database, - GameObjects = _parseGameObjects.Database - }; + await base.RunCoreAsync(token); + + GameDatabase = new GameDatabase + { + GameConstants = _parseGameConstants.Database, + GameObjects = _parseGameObjects.Database + }; + } + finally + { + Logger?.LogInformation("Finished creating game database"); + } } private sealed class ParseSingletonXmlStep(string name, string xmlFile, IGameRepository repository, IServiceProvider serviceProvider) diff --git a/src/PetroglyphTools/PG.StarWarsGame.Engine/Pipeline/CreateGameDatabaseStep.cs b/src/PetroglyphTools/PG.StarWarsGame.Engine/Pipeline/CreateGameDatabaseStep.cs deleted file mode 100644 index 361e823..0000000 --- a/src/PetroglyphTools/PG.StarWarsGame.Engine/Pipeline/CreateGameDatabaseStep.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Threading; -using AnakinRaW.CommonUtilities.SimplePipeline.Steps; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using PG.StarWarsGame.Engine.FileSystem; - -namespace PG.StarWarsGame.Engine.Pipeline; - -public class CreateGameDatabaseStep : SynchronizedStep -{ - private readonly IGameRepository _gameRepository; - private readonly ILogger? _logger; - - public GameDatabase GameDatabase { get; private set; } = null!; - - public CreateGameDatabaseStep(IGameRepository gameRepository, IServiceProvider serviceProvider) : base(serviceProvider) - { - _logger = Services.GetService()?.CreateLogger(GetType()); - _gameRepository = gameRepository; - } - - protected override void RunSynchronized(CancellationToken token) - { - _logger?.LogInformation("Creating Game Database..."); - var indexGamesPipeline = new CreateGameDatabasePipeline(_gameRepository, Services); - indexGamesPipeline.RunAsync(token).Wait(); - GameDatabase = indexGamesPipeline.GameDatabase; - _logger?.LogInformation("Finished creating game database"); - } -} \ No newline at end of file