Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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?));