public override int Execute() { if (!System.IO.File.Exists(_path)) { Echo(String.Format("Script file is not found '{0}'", _path)); return(2); } SystemLogger.SetWriter(this); var hostedScript = new HostedScriptEngine(); hostedScript.CustomConfig = ScriptFileHelper.CustomConfigPath(_path); ScriptFileHelper.OnBeforeScriptRead(hostedScript); var source = hostedScript.Loader.FromFile(_path); Process process; try { process = hostedScript.CreateProcess(this, source); } catch (Exception e) { this.ShowExceptionInfo(e); return(1); } var result = process.Start(); hostedScript.Finalize(); return(result); }
private void Button_Click_1(object sender, RoutedEventArgs e) { result.Text = ""; var sw = new System.Diagnostics.Stopwatch(); var host = new Host(result); var hostedScript = new HostedScriptEngine(); hostedScript.Initialize(); var src = hostedScript.Loader.FromString(txtCode.Text); Process process = null; try { process = hostedScript.CreateProcess(host, src); } catch (Exception exc) { result.Text = exc.Message; return; } result.AppendText("Script started: " + DateTime.Now.ToString() + "\n"); sw.Start(); var returnCode = process.Start(); sw.Stop(); if (returnCode != 0) { result.AppendText("\nError detected. Exit code = " + returnCode.ToString()); } result.AppendText("\nScript completed: " + DateTime.Now.ToString()); result.AppendText("\nDuration: " + sw.Elapsed.ToString()); }
private int RunCGIMode(string scriptFile) { var engine = new HostedScriptEngine(); engine.AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly()); var request = new WebRequestContext(); engine.InjectGlobalProperty("ВебЗапрос", request, true); engine.InjectObject(this, false); engine.Initialize(); var source = engine.Loader.FromFile(scriptFile); Process process; try { process = engine.CreateProcess(this, source); } catch (Exception e) { ShowExceptionInfo(e); return(1); } int exitCode = process.Start(); if (!_isContentEchoed) { Echo(""); } return(exitCode); }
private void Button_Click_1(object sender, RoutedEventArgs e) { SaveLastCode(); // Сохраним набранный текст на случай зависания или вылета result.Text = ""; var sw = new System.Diagnostics.Stopwatch(); List <string> l_args = new List <string>(); for (var i = 0; i < args.LineCount; i++) { string s = args.GetLineText(i); if (s.IndexOf('#') != 0) { l_args.Add(s.Trim()); } } var host = new Host(result, l_args.ToArray()); SystemLogger.SetWriter(host); var hostedScript = new HostedScriptEngine(); hostedScript.CustomConfig = CustomConfigPath(_currentDocPath); SetEncodingFromConfig(hostedScript); var src = new EditedFileSource(txtCode.Text, _currentDocPath); Process process = null; try { process = hostedScript.CreateProcess(host, src); } catch (Exception exc) { host.Echo(exc.Message); return; } result.AppendText("Script started: " + DateTime.Now.ToString() + "\n"); sw.Start(); var returnCode = process.Start(); sw.Stop(); if (returnCode != 0) { result.AppendText("\nError detected. Exit code = " + returnCode.ToString()); } result.AppendText("\nScript completed: " + DateTime.Now.ToString()); result.AppendText("\nDuration: " + sw.Elapsed.ToString()); }
static void Main(string[] args) { var host = new ApplicationHost(); var source = args[0]; host.CommandLineArguments = args.Skip(1).ToArray(); var Engine = new HostedScriptEngine(); Engine.Initialize(); //Engine.Loader.ReaderEncoding = Encoding.GetEncoding("utf-8"); var process = Engine.CreateProcess(host, Engine.Loader.FromFile(source)); process.Start(); }
public override int Execute() { if (!System.IO.File.Exists(_path)) { throw new System.IO.FileNotFoundException("Script file is not found", _path); } var hostedScript = new HostedScriptEngine(); hostedScript.Initialize(); var source = hostedScript.Loader.FromFile(_path); var process = hostedScript.CreateProcess(this, source); return(process.Start()); }
private int RunTestScript(ICodeSource source, string resourceName) { var module = engine.GetCompilerService().CreateModule(source); engine.LoadUserScript(new ScriptEngine.UserAddedScript() { Type = ScriptEngine.UserAddedScriptType.Class, Module = module, Symbol = resourceName }); var process = engine.CreateProcess(this, source); return(process.Start()); }
public int Run() { try { ScriptModuleHandle module; var engine = new HostedScriptEngine(); engine.Initialize(); using (Stream codeStream = LocateCode()) using (var binReader = new BinaryReader(codeStream)) { int modulesCount; modulesCount = binReader.ReadInt32(); var formatter = new BinaryFormatter(); var reader = new ScriptEngine.Compiler.ModulePersistor(formatter); var entry = reader.Read(codeStream); --modulesCount; while (modulesCount-- > 0) { var userScript = reader.Read(codeStream); engine.LoadUserScript(userScript); } module = entry.Module; } var src = new BinaryCodeSource(module); var process = engine.CreateProcess(this, module, src); return(process.Start()); } catch (ScriptInterruptionException e) { return(e.ExitCode); } catch (Exception e) { this.ShowExceptionInfo(e); return(1); } }
public int Run() { try { Stream codeStream = LocateCode(); var formatter = new BinaryFormatter(); var reader = new ScriptEngine.Compiler.ModulePersistor(formatter); var moduleHandle = reader.Read(codeStream); var engine = new HostedScriptEngine(); var src = new BinaryCodeSource(moduleHandle); var process = engine.CreateProcess(this, moduleHandle, src); return(process.Start()); } catch (Exception e) { Console.Write(e.ToString()); return(-1); } }
public Process CreateProcess(Stream sourceStream, IHostApplication host) { var appDump = DeserializeAppDump(sourceStream); var engine = new HostedScriptEngine(); var src = new BinaryCodeSource(); var templateStorage = new TemplateStorage(new StandaloneTemplateFactory()); engine.SetGlobalEnvironment(host, src); engine.InitializationCallback = (e, env) => { e.Environment.InjectObject(templateStorage); GlobalsManager.RegisterInstance(templateStorage); }; engine.Initialize(); LoadResources(templateStorage, appDump.Resources); LoadScripts(engine, appDump.Scripts); var process = engine.CreateProcess(host, appDump.Scripts[0].Image, src); return(process); }
private int RunCGIMode(string scriptFile) { var engine = new HostedScriptEngine { CustomConfig = ScriptFileHelper.CustomConfigPath(scriptFile) }; engine.AttachAssembly(Assembly.GetExecutingAssembly()); var request = new WebRequestContext(); engine.InjectGlobalProperty("ВебЗапрос", request, true); engine.InjectGlobalProperty("WebRequest", request, true); engine.InjectObject(this, false); ScriptFileHelper.OnBeforeScriptRead(engine); var source = engine.Loader.FromFile(scriptFile); Process process; try { process = engine.CreateProcess(this, source); } catch (Exception e) { ShowExceptionInfo(e); return(1); } var exitCode = process.Start(); if (!_isContentEchoed) { Echo(""); } return(exitCode); }
public int Run() { try { Stream codeStream = LocateCode(); var formatter = new BinaryFormatter(); var reader = new ScriptEngine.Compiler.ModulePersistor(formatter); var moduleHandle = reader.Read(codeStream); var engine = new HostedScriptEngine(); var src = new BinaryCodeSource(moduleHandle); var process = engine.CreateProcess(this, moduleHandle, src); return(process.Start()); } catch (ScriptInterruptionException e) { return(e.ExitCode); } catch (Exception e) { this.ShowExceptionInfo(e); return(1); } }
public int Run() { if (_sourceStream == null && CommandLineArguments != null && CommandLineArguments.Length > 1) { var firstArg = CommandLineArguments[0]; if (firstArg == "-loadDump") { var path = CommandLineArguments[1]; CommandLineArguments = CommandLineArguments.Skip(2).ToArray(); using (var dumpStream = new FileStream(path, FileMode.Open)) { _sourceStream = GetCodeStream(dumpStream); } return(Run()); //ну да, говнокод и лапша, время жмет } } if (_sourceStream == null) { _sourceStream = LocateCode(); } var engine = new HostedScriptEngine(); var src = new BinaryCodeSource(); engine.SetGlobalEnvironment(this, src); try { var templateStorage = new TemplateStorage(new StandaloneTemplateFactory()); engine.InitializationCallback = (e, env) => { e.Environment.InjectObject(templateStorage); GlobalsManager.RegisterInstance(templateStorage); }; engine.Initialize(); var serializer = new BinaryFormatter(); var appDump = (ApplicationDump)serializer.Deserialize(_sourceStream); foreach (var resource in appDump.Resources) { templateStorage.RegisterTemplate(resource.ResourceName, DeserializeTemplate(resource.Data)); } var module = appDump.Scripts[0].Image; for (int i = 1; i < appDump.Scripts.Length; i++) { engine.LoadUserScript(appDump.Scripts[i]); } var process = engine.CreateProcess(this, module, src); return(process.Start()); } catch (ScriptInterruptionException e) { return(e.ExitCode); } catch (Exception e) { ShowExceptionInfo(e); return(1); } }
public int Run() { if (_sourceStream == null && CommandLineArguments != null && CommandLineArguments.Length > 1) { var firstArg = CommandLineArguments[0]; if (firstArg == "-loadDump") { var path = CommandLineArguments[1]; CommandLineArguments = CommandLineArguments.Skip(2).ToArray(); using (var dumpStream = new FileStream(path, FileMode.Open)) { _sourceStream = GetCodeStream(dumpStream); } Run(); //ну да, говнокод и лапша, время жмет } } if (_sourceStream == null) { _sourceStream = LocateCode(); } var engine = new HostedScriptEngine(); var src = new BinaryCodeSource(); engine.SetGlobalEnvironment(this, src); try { ModuleImage module; engine.Initialize(); using (var binReader = new BinaryReader(_sourceStream)) { var modulesCount = binReader.ReadInt32(); var reader = new ModulePersistor(); var entry = reader.Read(_sourceStream); --modulesCount; while (modulesCount-- > 0) { var userScript = reader.Read(_sourceStream); engine.LoadUserScript(userScript); } module = entry.Image; } var process = engine.CreateProcess(this, module, src); return(process.Start()); } catch (ScriptInterruptionException e) { return(e.ExitCode); } catch (Exception e) { ShowExceptionInfo(e); return(1); } }