public async Task Run(RunSynthesisPatcher settings, CancellationToken cancel) { if (cancel.IsCancellationRequested) { return; } var internalSettings = RunSynthesisMutagenPatcher.Factory(settings); internalSettings.ExtraDataFolder = PathToExtraData; var args = Parser.Default.FormatCommandLine(internalSettings); try { using ProcessWrapper process = ProcessWrapper.Create( new ProcessStartInfo(PathToExecutable, args) { WorkingDirectory = Path.GetDirectoryName(PathToExecutable) ! }, cancel); using var outputSub = process.Output.Subscribe(_output); using var errSub = process.Error.Subscribe(_error); var result = await process.Run(); if (result != 0) { throw new CliUnsuccessfulRunException( result, $"Process exited in failure: {process.StartInfo.FileName} {internalSettings}"); } }
public async Task Run(RunSynthesisPatcher settings, CancellationToken?cancel = null) { var repoPath = Path.GetDirectoryName(PathToSolution); if (Repository.IsValid(repoPath)) { using var repo = new Repository(repoPath); _output.OnNext($"Sha {repo.Head.Tip.Sha}"); } var internalSettings = new RunSynthesisMutagenPatcher() { DataFolderPath = settings.DataFolderPath, ExtraDataFolder = Path.Combine(PathToExtraDataBaseFolder, Name), GameRelease = settings.GameRelease, LoadOrderFilePath = settings.LoadOrderFilePath, OutputPath = settings.OutputPath, SourcePath = settings.SourcePath }; var args = Parser.Default.FormatCommandLine(internalSettings); using var process = ProcessWrapper.Start( new ProcessStartInfo("dotnet", $"run --project \"{PathToProject}\" --runtime win-x64 --no-build {args}"), cancel: cancel); using var outputSub = process.Output.Subscribe(_output); using var errSub = process.Error.Subscribe(_error); var result = await process.Start().ConfigureAwait(false); if (result != 0) { throw new CliUnsuccessfulRunException(result, "Error running solution patcher"); } }
public async Task PassesSettingsToRunner( RunSynthesisPatcher settings, CancellationToken cancel, SolutionPatcherRun sut) { await sut.Run(settings, cancel); await sut.SolutionPatcherRunner.Received(1).Run(settings, cancel); }
public void SetsExtraDataFolder( RunSynthesisPatcher settings, Language language, GenericSettingsToMutagenSettings sut) { settings.TargetLanguage = language.ToString(); sut.Convert(settings) .ExtraDataFolder.Should().Be(sut.ExtraDataPathProvider.Path); }
public async Task PrintsSha( RunSynthesisPatcher settings, CancellationToken cancel, SolutionPatcherRun sut) { await sut.Run(settings, cancel); sut.PrintShaIfApplicable.Received(1).Print(); }
public async Task RetrievesArgs( IGroupRun groupRun, IPatcherRun patcher, CancellationToken cancellation, FilePath?sourcePath, RunParameters runParameters, RunSynthesisPatcher args, RunAPatcher sut) { sut.GetRunArgs.GetArgs(default !, default !, default, default !)
public async Task Run(RunSynthesisPatcher settings, CancellationToken?cancel = null) { if (SolutionRun == null) { throw new SynthesisBuildFailure("Expected Solution Run object did not exist."); } using var outputSub = SolutionRun.Output.Subscribe(this._output); using var errSub = SolutionRun.Error.Subscribe(this._error); await SolutionRun.Run(settings, cancel).ConfigureAwait(false); }
public void SetsExtraDataToProviderResult( DirectoryPath dir, Language language, RunSynthesisPatcher settings, ConstructSolutionPatcherRunArgs sut) { settings.TargetLanguage = language.ToString(); sut.PatcherExtraDataPathProvider.Path.Returns(dir); sut.Construct(settings) .ExtraDataFolder.Should().Be(dir); }
public void DefaultDataFolderPathSetByProviderIfExists( DirectoryPath existingDirectory, Language language, RunSynthesisPatcher settings, ConstructSolutionPatcherRunArgs sut) { settings.TargetLanguage = language.ToString(); sut.DefaultDataPathProvider.Path.Returns(existingDirectory); sut.Construct(settings) .DefaultDataFolderPath.Should().Be(existingDirectory); }
public static RunSynthesisMutagenPatcher Factory(RunSynthesisPatcher settings) { return(new RunSynthesisMutagenPatcher() { DataFolderPath = settings.DataFolderPath, GameRelease = settings.GameRelease, LoadOrderFilePath = settings.LoadOrderFilePath, OutputPath = settings.OutputPath, SourcePath = settings.SourcePath }); }
public async Task MissingTarget() { var runSettings = new RunSynthesisPatcher(); var run = new CliPatcherRun("Missing", "Missing.exe", pathToExtra: null); await run.Prep(Mutagen.Bethesda.GameRelease.Oblivion, CancellationToken.None); await Assert.ThrowsAsync <FileNotFoundException>(async() => { await run.Run(runSettings, CancellationToken.None); }); }
public void DefaultDataFolderPathNullIfDoesNotExist( DirectoryPath missingDirectory, Language language, RunSynthesisPatcher settings, ConstructSolutionPatcherRunArgs sut) { settings.TargetLanguage = language.ToString(); sut.DefaultDataPathProvider.Path.Returns(missingDirectory); sut.Construct(settings) .DefaultDataFolderPath.Should().BeNull(); }
public async Task Run(RunSynthesisPatcher settings, CancellationToken cancel) { if (DoWork) { File.WriteAllText(settings.OutputPath, "Hello"); } WasRun = true; if (ThrowInRun) { throw new NotImplementedException(); } }
public async Task Run(RunSynthesisPatcher settings, CancellationToken cancel) { var repoPath = Path.GetDirectoryName(PathToSolution); if (Repository.IsValid(repoPath)) { using var repo = new Repository(repoPath); _output.OnNext($"Sha {repo.Head.Tip.Sha}"); } var runnability = await Synthesis.Bethesda.Execution.CLI.Commands.CheckRunnability( PathToProject, directExe : false, release : settings.GameRelease, dataFolder : settings.DataFolderPath, loadOrderPath : settings.LoadOrderFilePath, cancel : cancel); if (runnability.Failed) { throw new CliUnsuccessfulRunException((int)Codes.NotRunnable, runnability.Reason); } var internalSettings = new RunSynthesisMutagenPatcher() { DataFolderPath = settings.DataFolderPath, ExtraDataFolder = Path.Combine(PathToExtraDataBaseFolder, Name), GameRelease = settings.GameRelease, LoadOrderFilePath = settings.LoadOrderFilePath, OutputPath = settings.OutputPath, SourcePath = settings.SourcePath }; var args = Parser.Default.FormatCommandLine(internalSettings); using var process = ProcessWrapper.Create( new ProcessStartInfo("dotnet", $"run --project \"{PathToProject}\" --runtime win-x64 --no-build {args}"), cancel: cancel); _output.OnNext("Running"); _output.OnNext($"({process.StartInfo.WorkingDirectory}): {process.StartInfo.FileName} {process.StartInfo.Arguments}"); using var outputSub = process.Output.Subscribe(_output); using var errSub = process.Error.Subscribe(_error); var result = await process.Run().ConfigureAwait(false); if (result != 0) { throw new CliUnsuccessfulRunException(result, "Error running solution patcher"); } }
public void SettingsForwarding( Language language, RunSynthesisPatcher settings, ConstructSolutionPatcherRunArgs sut) { settings.TargetLanguage = language.ToString(); var ret = sut.Construct(settings); ret.DataFolderPath.Should().Be(settings.DataFolderPath); ret.GameRelease.Should().Be(settings.GameRelease); ret.LoadOrderFilePath.Should().Be(settings.LoadOrderFilePath); ret.OutputPath.Should().Be(settings.OutputPath); ret.SourcePath.Should().Be(settings.SourcePath); ret.PatcherName.Should().Be(settings.PatcherName); ret.PersistencePath.Should().Be(settings.PersistencePath); }
public async Task Run(RunSynthesisPatcher settings, CancellationToken cancel) { _logger.Information("Running"); var args = ConstructArgs.Construct(settings); var result = await ProcessRunner.Run( ProcessRunStartInfoProvider.GetStart( PathToProjProvider.Path, Formatter.Format(args), build: false), cancel : cancel).ConfigureAwait(false); if (result != 0) { throw new CliUnsuccessfulRunException(result, "Error running solution patcher"); } }
public RunSynthesisMutagenPatcher Convert(RunSynthesisPatcher settings) { return(new RunSynthesisMutagenPatcher() { DataFolderPath = settings.DataFolderPath, GameRelease = settings.GameRelease, LoadOrderFilePath = settings.LoadOrderFilePath, OutputPath = settings.OutputPath, SourcePath = settings.SourcePath, PersistencePath = settings.PersistencePath, PatcherName = settings.PatcherName, ExtraDataFolder = ExtraDataPathProvider.Path, Localize = settings.Localize, TargetLanguage = Enum.Parse <Language>(settings.TargetLanguage), ModKey = settings.ModKey, }); }
public RunSynthesisMutagenPatcher Construct(RunSynthesisPatcher settings) { var defaultDataFolderPath = DefaultDataPathProvider.Path; return(new RunSynthesisMutagenPatcher() { DataFolderPath = settings.DataFolderPath, ExtraDataFolder = PatcherExtraDataPathProvider.Path, DefaultDataFolderPath = _fileSystem.Directory.Exists(defaultDataFolderPath) ? defaultDataFolderPath.Path : null, GameRelease = settings.GameRelease, LoadOrderFilePath = settings.LoadOrderFilePath, OutputPath = settings.OutputPath, SourcePath = settings.SourcePath, InternalDataFolder = _fileSystem.Directory.Exists(_internalDataPathProvider.Path) ? _internalDataPathProvider.Path.Path : null, PatcherName = settings.PatcherName, PersistencePath = settings.PersistencePath, TargetLanguage = Enum.Parse <Language>(settings.TargetLanguage), Localize = settings.Localize, ModKey = settings.ModKey, }); }
public async Task Run(RunSynthesisPatcher settings, CancellationToken?cancel = null) { if (_assembly == null) { throw new ArgumentException("Tried to run a code snippet patcher that did not have an assembly."); } Type?type = _assembly.GetType(ClassName); if (type == null) { throw new ArgumentException("Could not find compiled class within assembly."); } var patcherCodeClass = System.Activator.CreateInstance(type); var userPrefs = new UserPreferences() { Cancel = cancel ?? CancellationToken.None }; var internalSettings = RunSynthesisMutagenPatcher.Factory(settings); using var synthesisState = ConstructStateFactory(settings.GameRelease)(internalSettings, userPrefs); Task t = (Task)type.InvokeMember("Run", BindingFlags.Default | BindingFlags.InvokeMethod, null, patcherCodeClass, new[] { synthesisState, }); await t; synthesisState.PatchMod.WriteToBinaryParallel( settings.OutputPath, new BinaryWriteParameters() { ModKey = BinaryWriteParameters.ModKeyOption.NoCheck, MastersListOrdering = new BinaryWriteParameters.MastersListOrderingByLoadOrder(synthesisState.LoadOrder.Where(i => i.Enabled).Select(i => i.ModKey)) }); }
public async Task PassesSettingsToConverter( RunSynthesisPatcher runSettings, CancellationToken cancel, CliPatcherRun sut) { sut.ProcessRunner.Run(default !, default !, default).ReturnsForAnyArgs(0);
public async Task PassesSettingsToArgConstructor( RunSynthesisPatcher settings, CancellationToken cancel, SolutionPatcherRunner sut) { sut.ProcessRunner.Run(default !, default).ReturnsForAnyArgs(0);