public JSServer(JSService service, HttpContext context, Action after) { _service = service; _application = CreateApplication(context, after); _sessions = new ConcurrentDictionary <string, JSSession>(); }
public void ExecuteTests(JSApplication application, JSService service, JSSession session) { foreach (var test in Tests) { if (test == null) { continue; } test.Initialize(); test.Execute(application, service, session); } }
static void Main(string[] args) { var application = new JSApplication("", app => { app.AddHostType(typeof(API.Console)); }, (error, stage) => { System.Console.WriteLine(error); }); var service = new JSService(); var session = new JSSession(); try { service.RunScriptSync(application.Settings.Startup, application, session, result => { System.Console.WriteLine(result); System.Console.ReadLine(); }); } catch (Exception e) { System.Console.WriteLine(e); System.Console.ReadLine(); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var service = new JSService(); var session = new JSSession(); var application = new JSApplication(null, app => { app.AddHostType(typeof(API.Window)); app.AddHostType(typeof(API.Graphics)); }, (exception, stage) => { if (exception is ScriptEngineException se) { NetJS.API.Log.write(se.ErrorDetails); } else { NetJS.API.Log.write(exception.ToString()); } }); service.RunScript(application.Settings.Startup, application, session, result => { }); }
public JsonResult CodeGenerate(string entity, List <JPropertyInfo> props) { try { string templates = Config.Root + "Templates"; if (!Directory.Exists(templates)) { Directory.CreateDirectory(templates); } string component = Config.Root + "Templates\\Components"; if (!Directory.Exists(component)) { Directory.CreateDirectory(component); } //Generate scripts directories string script = Config.ScriptProject + "\\Scripts"; if (!Directory.Exists(script)) { Directory.CreateDirectory(script); } script = Config.ScriptProject + "\\Scripts\\Controllers"; if (!Directory.Exists(script)) { Directory.CreateDirectory(script); } script = Config.ScriptProject + "\\Scripts\\Services"; if (!Directory.Exists(script)) { Directory.CreateDirectory(script); } //services script = Config.ServiceProject + "\\Interfaces"; if (!Directory.Exists(script)) { Directory.CreateDirectory(script); } script = Config.ServiceProject + "\\Implementation"; if (!Directory.Exists(script)) { Directory.CreateDirectory(script); } ICode code = new TemplateCode(); System.IO.File.WriteAllText(component + "\\" + entity + ".html", code.CodeGenerate(entity, props)); code = new JSController(); code.Config = this.Config; System.IO.File.WriteAllText(Config.ScriptProject + "\\Scripts\\Controllers\\" + entity + "Ctrl.cs", code.CodeGenerate(entity, props)); code = new JSService(); code.Config = this.Config; System.IO.File.WriteAllText(Config.ScriptProject + "\\Scripts\\Services\\" + entity + "Service.cs", code.CodeGenerate(entity, props)); code = new CSController(); System.IO.File.WriteAllText(Config.Root + "Controllers\\" + entity + "Controller.cs", code.CodeGenerate(entity, props)); code = new CSServiceInterface(); System.IO.File.WriteAllText(Config.ServiceProject + "\\Interfaces\\I" + entity + "Service.cs", code.CodeGenerate(entity, props)); code = new CSServiceImplementation(); System.IO.File.WriteAllText(Config.ServiceProject + "\\Implementation\\" + entity + "Service.cs", code.CodeGenerate(entity, props)); WidgetManager widgetManager = new WidgetManager(); widgetManager.RootPath = Config.Root; widgetManager.AddWidget(new JwtWidget { Name = entity, PropertyList = props }); return(Json(new { message = "Successfully Generated." })); } catch (Exception ex) { return(Json(new { message = ex.ToString() })); } }
public void Execute(JSApplication application, JSService service, JSSession session) { if (Implemented.Count >= 1) { return; } var watch = new Stopwatch(); watch.Start(); var preTestOutput = ""; if (_include != null) { foreach (var preTest in _include) { if (!preTest.Contains(".js")) { continue; } var preTestPath = Path.GetFullPath(Program.Test262Root + "/../harness/" + preTest.Replace(",", "")) .Replace('\\', '/'); preTestOutput += service.RunScript(preTestPath, application, session, true, false); } } var strictTestOutput = ""; var strictWatch = new Stopwatch(); if (UseStrict) { strictWatch.Start(); strictTestOutput = service.RunCode("\"use strict\"\n" + _code, application, session, false, true); strictWatch.Stop(); } var templateWatch = new Stopwatch(); templateWatch.Start(); var testOutput = service.RunCode(_code, application, session, false, true); templateWatch.Stop(); watch.Stop(); if (_negative != null && _negativeType != null && _negativeType.ToString().Length > 0) { var splitStrictOutput = testOutput.Split(' '); var splitOutput = testOutput.Split(' '); var comparewith = ""; if (splitOutput.Length > 1) { comparewith = splitOutput[0] + splitOutput[1][0].ToString().ToUpper() + splitOutput[1].Substring(1); } var compareStrictWith = ""; if (splitStrictOutput.Length > 1) { compareStrictWith = splitStrictOutput[0] + splitStrictOutput[1][0].ToString().ToUpper() + splitStrictOutput[1].Substring(1); } if (comparewith.Contains(_negativeType.ToString())) { NonStrictResult = true; } if (compareStrictWith.Contains(_negativeType.ToString())) { StrictResult = true; } } else { if (testOutput.Length < 1) { NonStrictResult = true; } if (strictTestOutput.Length < 1) { StrictResult = true; } } if (_useAsync && templateWatch.ElapsedMilliseconds > 75) { NonStrictResult = false; _nonStrictOutput += "Async timeout fail | "; } if (preTestOutput.Length > 0) { _nonStrictOutput += "preTest: " + preTestOutput + " | "; _strictOutput += "preTest: " + strictTestOutput + " | "; } _nonStrictOutput += testOutput; _strictOutput += strictTestOutput; var stringTime = Math.Round(templateWatch.Elapsed.TotalMilliseconds, 2).ToString().Split('.'); var strictStringTime = Math.Round(strictWatch.Elapsed.TotalMilliseconds, 2).ToString().Split('.'); var timeDecimal = "00"; if (stringTime.Length == 2) { timeDecimal = (int.Parse(stringTime[1]) * 6 / 10).ToString(); } var timeStrictDecimal = "00"; if (strictStringTime.Length == 2) { timeStrictDecimal = (int.Parse(strictStringTime[1]) * 6 / 10).ToString(); } _nonStrictTime = stringTime[0] + "." + timeDecimal; _strictTime = strictStringTime[0] + "." + timeStrictDecimal; }