public async Task RunTwice() { using var tmpFolder = Utility.GetTempFolder(); using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.Oblivion); var outputFile = Utility.TypicalOutputFile(tmpFolder); var settings = new CodeSnippetPatcherSettings() { On = true, Code = @"state.PatchMod.Npcs.AddNew();", Nickname = "UnitTests", }; for (int i = 0; i < 2; i++) { var snippet = new CodeSnippetPatcherRun(settings); await snippet.Prep(GameRelease.Oblivion, CancellationToken.None); await snippet.Run(new RunSynthesisPatcher() { OutputPath = ModPath.FromPath(outputFile), DataFolderPath = dataFolder.Dir.Path, GameRelease = GameRelease.Oblivion, LoadOrderFilePath = Utility.PathToLoadOrderFile, SourcePath = i == 1 ? outputFile.Path : null }, CancellationToken.None); } using var mod = OblivionMod.CreateFromBinaryOverlay(outputFile); Assert.Equal(2, mod.Npcs.Count); }
public async Task CreatesOutput() { using var tmpFolder = Utility.GetTempFolder(); using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.Oblivion); var settings = new CodeSnippetPatcherSettings() { On = true, Code = @"// Let's do work! int wer = 23; wer++;", Nickname = "UnitTests", }; var outputFile = Utility.TypicalOutputFile(tmpFolder); var snippet = new CodeSnippetPatcherRun(settings); await snippet.Prep(GameRelease.Oblivion, CancellationToken.None); await snippet.Run(new RunSynthesisPatcher() { OutputPath = ModPath.FromPath(outputFile), DataFolderPath = dataFolder.Dir.Path, GameRelease = GameRelease.Oblivion, LoadOrderFilePath = Utility.PathToLoadOrderFile, SourcePath = null }, CancellationToken.None); Assert.True(File.Exists(outputFile)); }
public async Task CompileWithMutagenCore() { var settings = new CodeSnippetPatcherSettings() { On = true, Code = $"var modPath = {nameof(ModPath)}.{nameof(ModPath.Empty)}; modPath.Equals({nameof(ModPath)}.{nameof(ModPath.Empty)});", Nickname = "UnitTests", }; var snippet = new CodeSnippetPatcherRun(settings); var result = snippet.Compile(GameRelease.SkyrimSE, CancellationToken.None, out var _); Assert.True(result.Success); }
public async Task CompileWithSpecificGames() { foreach (var game in EnumExt.GetValues <GameRelease>()) { var settings = new CodeSnippetPatcherSettings() { On = true, Code = $"var id = {game.ToCategory()}Mod.DefaultInitialNextFormID; id++;", Nickname = "UnitTests", }; var snippet = new CodeSnippetPatcherRun(settings); var result = snippet.Compile(game, CancellationToken.None, out var _); Assert.True(result.Success); } }
public async Task CompileBasic() { var settings = new CodeSnippetPatcherSettings() { On = true, Code = @"// Let's do work! int wer = 23; wer++;", Nickname = "UnitTests", }; var snippet = new CodeSnippetPatcherRun(settings); var result = snippet.Compile(GameRelease.SkyrimSE, CancellationToken.None, out var _); Assert.True(result.Success); }
public void ConstructStateFactory() { using var tmpFolder = Utility.GetTempFolder(); using var dataFolder = Utility.SetupDataFolder(tmpFolder, GameRelease.Oblivion); var output = Utility.TypicalOutputFile(tmpFolder); var settings = new RunSynthesisMutagenPatcher() { DataFolderPath = dataFolder.Dir.Path, GameRelease = GameRelease.Oblivion, LoadOrderFilePath = Utility.PathToLoadOrderFile, OutputPath = output, SourcePath = null }; var factory = CodeSnippetPatcherRun.ConstructStateFactory(GameRelease.Oblivion); var stateObj = factory(settings, new PatcherPreferences(), Synthesis.Bethesda.Constants.SynthesisModKey); Assert.NotNull(stateObj); using var state = stateObj as SynthesisState <IOblivionMod, IOblivionModGetter>; Assert.NotNull(state); }
public CodeSnippetPatcherVM(ProfileVM parent, CodeSnippetPatcherSettings?settings = null) : base(parent, settings) { CopyInSettings(settings); _DisplayName = this.WhenAnyValue(x => x.Nickname) .Select(x => { if (string.IsNullOrWhiteSpace(x)) { return("<No Name>"); } else { return(x); } }) .ToGuiProperty <string>(this, nameof(DisplayName), string.Empty); IObservable <(MemoryStream?AssemblyStream, EmitResult?CompileResults, Exception?Exception)> compileResults = Observable.Merge( // Anytime code changes, wipe and mark as "compiling" this.WhenAnyValue(x => x.Code) .Select(_ => (default(MemoryStream?), default(EmitResult?), default(Exception?))), // Start actual compiling task, this.WhenAnyValue(x => x.Code) // Throttle input .Throttle(TimeSpan.FromMilliseconds(350), RxApp.MainThreadScheduler) // Stick on background thread .ObserveOn(RxApp.TaskpoolScheduler) .Select(code => { CancellationTokenSource cancel = new CancellationTokenSource(); try { var emit = CodeSnippetPatcherRun.Compile( parent.Release, ID, code, cancel.Token, out var assembly); return(emit.Success ? assembly : default, emit, default(Exception?));