protected async override Task<NodeResultStatus> PerformExecuteAsync(IExecutionContext<T> context) { if (!string.IsNullOrEmpty(ExecutedScript)) { LogWriter.Debug("ExecutedScript exists, running this script."); var result = new NodeResult{IsSuccess = true}; using (var scope = new ManagerScope()) { SetScriptIdIfEmpty(); var options = new ClearScript.Manager.ExecutionOptions { HostObjects = SetupHostObjects(context, result), HostTypes = SetupHostTypes() }; await scope.RuntimeManager.ExecuteAsync(ScriptId, ExecutedScript, options); if (!result.IsSuccess) { return NodeResultStatus.Failed; } } } LogWriter.Debug("ExecutedScript doesn't exist."); return NodeResultStatus.Succeeded; }
// POST api/values public async Task <dynamic> Post([FromBody] Script script) { var scriptId = Guid.NewGuid(); using (var scope = new ManagerScope()) { dynamic host = new ExpandoObject(); //var host = new TestModel(); var option = new ExecutionOptions { HostObjects = new List <HostObject> { new HostObject { Name = "host", Target = host } } }; //var engine = new V8ScriptEngine(); //engine.AddHostObject("host", HostItemFlags.None, host); //engine.Execute(script.Text); await scope.RuntimeManager.ExecuteAsync(scriptId.ToString(), script.Text, option); return(host); } }
public async void Testtabris1() { RequireManager requireManager = new RequireManager(); ManagerPool.InitializeCurrentPool(new ManagerSettings()); JavaScript.Manager.Tabris.Tabris.Register(requireManager, new JavaScript.Manager.Tabris.TabrisOptions { }); using (var scope = new ManagerScope(requireManager)) { var code = @"var tabris; (function (){ tabris = tabris || require('javascript_tabris'); try{ var lib = require('../TestDll.dll'); var myClrObject = new lib.TestDll.MyClass('tttt'); myClrObject.SayHello(); }catch(err){ host.err=err.message; host.ex=err; } })();"; await scope.RuntimeManager.ExecuteAsync("btnExcutor_Click", code); } //RequireManager.ClearPackages(); }
private static Task RunInScope(string name, string script) { return(Task.Run(async() => { using (var scope = new ManagerScope()) { scope.RuntimeManager.AddConsoleReference = true; await scope.RuntimeManager.ExecuteAsync(name, script); } })); }
private static Task RunInScope(string name, string script) { return Task.Run(async () => { using (var scope = new ManagerScope()) { scope.RuntimeManager.AddConsoleReference = true; await scope.RuntimeManager.ExecuteAsync(name, script); } }); }
public GameEngine(int number) { GameConfig.Mouses = number; screen = new Screen { Width = ScreenWidth, Height = ScreenHeight }; ManagerScope = managerScopeFactory.Create(screen); levelManager = ManagerScope.Resolve <ILevelManager>(); ballManager = ManagerScope.Resolve <IBallManager>(); padManager = ManagerScope.Resolve <IPadManager>(); tailManager = ManagerScope.Resolve <ITailManager>(); borderManager = ManagerScope.Resolve <IBorderManager>(); collisionManager = ManagerScope.Resolve <ICollisionManager>(); screenCollisionManager = ManagerScope.Resolve <IScreenCollisionManager>(); borderCollisionManager = ManagerScope.Resolve <IBorderCollisionManager>(); FireBallCounter = new FireBallCounter(tailManager); ballStateMachine = new BallStateMachine( ManagerScope, Bricks, HitBrick, LostBall); ballBuilder = new BallBuilder( ballManager, tailManager, padManager, FastBallCounter.TimerHandler); ballExtraFeatureBuilder = new BallExtraFeatureBuilder( ballManager, tailManager, ballBuilder, FireBallCounter); levelBuilder = new LevelBuilder( screen, levelManager, padManager, borderManager, borderCollisionManager, ballBuilder, GameConfig, Bricks); }
public void Script_Engine_Is_Retrieved() { ManagerPool.InitializeCurrentPool(new ManualManagerSettings { RuntimeMaxCount = 2 }); using (var scope = new ManagerScope()) { var engine = scope.RuntimeManager.GetEngine(); engine.ShouldNotBeNull(); engine.Execute("var i = 200;"); Assert.AreEqual(200, engine.Script.i); } }
// POST api/values public async Task<dynamic> Post([FromBody]Script script) { var scriptId = Guid.NewGuid(); using (var scope = new ManagerScope()) { dynamic host = new ExpandoObject(); //var host = new TestModel(); var option = new ExecutionOptions { HostObjects = new List<HostObject> {new HostObject {Name = "host", Target = host}} }; //var engine = new V8ScriptEngine(); //engine.AddHostObject("host", HostItemFlags.None, host); //engine.Execute(script.Text); await scope.RuntimeManager.ExecuteAsync(scriptId.ToString(), script.Text, option); return host; } }
public override async Task<bool> ShouldExecuteAsync(IExecutionContext<T> context) { if (string.IsNullOrEmpty(ShouldExecuteScript)) return true; var result = new ShouldExecuteResult { ShouldExecute = true }; using (var scope = new ManagerScope()) { SetScriptIdIfEmpty(); var options = new ClearScript.Manager.ExecutionOptions { HostObjects = SetupHostObjects(context, result), HostTypes = SetupHostTypes() }; await scope.RuntimeManager.ExecuteAsync(ScriptId, ShouldExecuteScript, options); return result.ShouldExecute; } }
public async void Testtabris() { RequireManager requireManager = new RequireManager(); Tabris.Register(requireManager); ManagerPool.InitializeCurrentPool(new ManagerSettings()); using (var scope = new ManagerScope(requireManager)) { var code = "var log = this.tabris.create('LOG');" + "try{ aa.ttt =1}catch(err){log.info(err)}"; code = "var tabris;" + "(function (){\n tabris = tabris || require('javascript_tabris'); \n" + code + "\n})();"; await scope.RuntimeManager.ExecuteAsync("btnExcutor_Click", code); code = "var log = this.tabris.create('LOG');" + "try{ aa.ttt =1}catch(err){log.info(err)}"; code = "var tabris;" + "(function (){\n tabris = tabris || require('javascript_tabris'); \n" + code + "\n})();"; await scope.RuntimeManager.ExecuteAsync("btnExcutor_Click", code); } //RequireManager.ClearPackages(); }