コード例 #1
0
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();

            commandLineArgs = new string[] { };

            return(engine);
        }
コード例 #2
0
        public void Refresh()
        {
            var file = HostedScriptEngine.ConfigFilePath();

            if (file != null)
            {
                _config = KeyValueConfig.Read(file);
            }
        }
コード例 #3
0
        public static HostedScriptEngine StartEngine()
        {
            var engine = new HostedScriptEngine();

            engine.Initialize();

            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(Bracker.BrackerWriterImpl)));

            return(engine);
        }
コード例 #4
0
        private void CreateDump(Stream output)
        {
            var offset = (int)output.Length;

            var engine = new HostedScriptEngine
            {
                CustomConfig = ScriptFileHelper.CustomConfigPath(_codePath)
            };

            engine.Initialize();
            ScriptFileHelper.OnBeforeScriptRead(engine);
            var source   = engine.Loader.FromFile(_codePath);
            var compiler = engine.GetCompilerService();

            engine.SetGlobalEnvironment(new DoNothingHost(), source);
            var entry = compiler.Compile(source);

            var embeddedContext = engine.GetUserAddedScripts();
            var templates       = GlobalsManager.GetGlobalContext <TemplateStorage>();

            var dump = new ApplicationDump();

            dump.Scripts = new UserAddedScript[]
            {
                new UserAddedScript()
                {
                    Image  = entry,
                    Symbol = "$entry",
                    Type   = UserAddedScriptType.Module
                }
            }.Concat(embeddedContext)
            .ToArray();
            dump.Resources = templates.GetTemplates()
                             .Select(SerializeTemplate)
                             .ToArray();

            using (var bw = new BinaryWriter(output))
            {
                var serializer = new BinaryFormatter();
                serializer.Serialize(output, dump);

                var signature = new byte[]
                {
                    0x4f,
                    0x53,
                    0x4d,
                    0x44
                };
                output.Write(signature, 0, signature.Length);

                bw.Write(offset);

                OutputToFile(output);
            }
        }
コード例 #5
0
        private void SetEncodingFromConfig(HostedScriptEngine engine)
        {
            var cfg = engine.GetWorkingConfig();

            string openerEncoding = cfg["encoding.script"];

            if (!String.IsNullOrWhiteSpace(openerEncoding) && StringComparer.InvariantCultureIgnoreCase.Compare(openerEncoding, "default") != 0)
            {
                engine.Loader.ReaderEncoding = Encoding.GetEncoding(openerEncoding);
            }
        }
コード例 #6
0
        private void CreateExe()
        {
            using (var exeStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("oscript.StandaloneRunner.exe"))
                using (var output = new MemoryStream())
                {
                    exeStream?.CopyTo(output);

                    var offset = (int)output.Length;

                    var engine = new HostedScriptEngine
                    {
                        CustomConfig = ScriptFileHelper.CustomConfigPath(_codePath)
                    };
                    engine.Initialize();
                    ScriptFileHelper.OnBeforeScriptRead(engine);
                    var source   = engine.Loader.FromFile(_codePath);
                    var compiler = engine.GetCompilerService();
                    engine.SetGlobalEnvironment(new DoNothingHost(), source);
                    var entry = compiler.CreateModule(source);

                    var embeddedContext = engine.GetUserAddedScripts();

                    using (var bw = new BinaryWriter(output))
                    {
                        var userAddedScripts = embeddedContext as IList <UserAddedScript> ?? embeddedContext.ToList();
                        bw.Write(userAddedScripts.Count + 1);

                        var persistor = new ModulePersistor();
                        persistor.Save(new UserAddedScript
                        {
                            Type   = UserAddedScriptType.Module,
                            Symbol = "$entry",
                            Module = entry
                        }, output);

                        foreach (var item in userAddedScripts)
                        {
                            persistor.Save(item, output);
                        }

                        var signature = new byte[]
                        {
                            0x4f,
                            0x53,
                            0x4d,
                            0x44
                        };
                        output.Write(signature, 0, signature.Length);

                        bw.Write(offset);
                        OutputToFile(output);
                    }
                }
        }
コード例 #7
0
        public override int Execute()
        {
            var hostedScript = new HostedScriptEngine();

            hostedScript.Initialize();
            var source   = hostedScript.Loader.FromFile(_path);
            var compiler = hostedScript.GetCompilerService();
            var writer   = new ScriptEngine.Compiler.ModuleWriter(compiler);

            writer.Write(Console.Out, source);
            return(0);
        }
コード例 #8
0
        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());
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        public override int Execute()
        {
            Output.WriteLine("Make started...");
            using (var exeStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("oscript.StandaloneRunner.exe"))
                using (var output = new FileStream(_exePath, FileMode.Create))
                {
                    exeStream.CopyTo(output);

                    int offset = (int)output.Length;

                    var engine = new HostedScriptEngine();
                    engine.CustomConfig = ScriptFileHelper.CustomConfigPath(_codePath);
                    engine.Initialize();
                    ScriptFileHelper.OnBeforeScriptRead(engine);
                    var source   = engine.Loader.FromFile(_codePath);
                    var compiler = engine.GetCompilerService();
                    var entry    = compiler.CreateModule(source);

                    var embeddedContext = engine.GetUserAddedScripts();

                    using (var bw = new BinaryWriter(output))
                    {
                        bw.Write(embeddedContext.Count() + 1);

                        var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                        var persistor = new ScriptEngine.Compiler.ModulePersistor(formatter);
                        persistor.Save(new UserAddedScript()
                        {
                            Type   = UserAddedScriptType.Module,
                            Symbol = "$entry",
                            Module = entry
                        }, output);

                        foreach (var item in embeddedContext)
                        {
                            persistor.Save(item, output);
                        }

                        byte[] signature = new byte[4]
                        {
                            0x4f, 0x53, 0x4d, 0x44
                        };
                        output.Write(signature, 0, signature.Length);

                        bw.Write(offset);
                    }
                }
            Output.WriteLine("Make completed");
            return(0);
        }
コード例 #11
0
        private void CreateDump(Stream output)
        {
            var offset = (int)output.Length;

            var engine = new HostedScriptEngine
            {
                CustomConfig = ScriptFileHelper.CustomConfigPath(_codePath)
            };

            engine.Initialize();
            ScriptFileHelper.OnBeforeScriptRead(engine);
            var source   = engine.Loader.FromFile(_codePath);
            var compiler = engine.GetCompilerService();

            engine.SetGlobalEnvironment(new DoNothingHost(), source);
            var entry = compiler.Compile(source);

            var embeddedContext = engine.GetUserAddedScripts();

            using (var bw = new BinaryWriter(output))
            {
                var userAddedScripts = embeddedContext as IList <UserAddedScript> ?? embeddedContext.ToList();
                bw.Write(userAddedScripts.Count + 1);

                var persistor = new ModulePersistor();
                persistor.Save(new UserAddedScript
                {
                    Type   = UserAddedScriptType.Module,
                    Symbol = "$entry",
                    Image  = entry
                }, output);

                foreach (var item in userAddedScripts)
                {
                    persistor.Save(item, output);
                }

                var signature = new byte[]
                {
                    0x4f,
                    0x53,
                    0x4d,
                    0x44
                };
                output.Write(signature, 0, signature.Length);

                bw.Write(offset);
                OutputToFile(output);
            }
        }
コード例 #12
0
        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());
        }
コード例 #13
0
 public ASPNETHandler()
 {
     _hostedScript = new HostedScriptEngine();
     _hostedScript.Initialize();
     _hostedScript.AttachAssembly(System.Reflection.Assembly.GetExecutingAssembly());
     // Аттачим доп сборки. По идее должны лежать в Bin
     foreach (System.Reflection.Assembly assembly in _assembliesForAttaching)
     {
         try
         {
             _hostedScript.AttachAssembly(assembly);
         }
         catch { /*что-то не так, ничего не делаем*/ }
     }
 }
コード例 #14
0
ファイル: Program.cs プロジェクト: nixel2007/os-inject-demo
        private static void CreateWorld()
        {
            _world = new HostedScriptEngine();
            var thisAsm = System.Reflection.Assembly.GetExecutingAssembly();
            var asmDir  = Path.GetDirectoryName(thisAsm.Location);
            var libDir  = Path.Combine(asmDir, "lib");

            if (Directory.Exists(libDir))
            {
                _world.InitExternalLibraries(libDir, new string[0]);
            }

            _world.SetGlobalEnvironment(new ConsoleHost(), null);
            _world.AttachAssembly(thisAsm);
            _world.Initialize();
        }
コード例 #15
0
        public override int Execute()
        {
            var engine = new HostedScriptEngine
            {
                CustomConfig = ScriptFileHelper.CustomConfigPath(_path)
            };

            engine.Initialize();
            ScriptFileHelper.OnBeforeScriptRead(engine);
            var source   = engine.Loader.FromFile(_path);
            var compiler = engine.GetCompilerService();

            engine.SetGlobalEnvironment(new DoNothingHost(), source);
            var entry           = compiler.Compile(source);
            var embeddedContext = engine.GetExternalLibraries();

            var serializer = new JsonSerializer();
            var sb         = new StringBuilder();

            using (var textWriter = new StringWriter(sb))
            {
                var writer = new JsonTextWriter(textWriter);
                writer.WriteStartArray();

                WriteImage(new UserAddedScript
                {
                    Type   = UserAddedScriptType.Module,
                    Symbol = "$entry",
                    Image  = entry
                }, writer, serializer);

                foreach (var item in embeddedContext)
                {
                    item.Classes.ForEach(x => WriteImage(x, writer, serializer));
                    item.Modules.ForEach(x => WriteImage(x, writer, serializer));
                }

                writer.WriteEndArray();
            }

            string result = sb.ToString();

            Output.WriteLine(result);

            return(0);
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
0
        System.Collections.Hashtable _dataProcessorObjectModules; // Список модулей объекта обработок

        public DataProcessorsManagerImpl(HostedScriptEngine hostedScript, System.Collections.Hashtable managerFiles, System.Collections.Hashtable objectFiles)
        {
            _hostedScript = hostedScript;
            _dataProcessorObjectModules = new System.Collections.Hashtable();

            foreach (System.Collections.DictionaryEntry co in objectFiles)
            {
                ICodeSource src = _hostedScript.Loader.FromString((string)co.Value);

                var compilerService = _hostedScript.GetCompilerService();
                var module          = compilerService.CreateModule(src);

                var _loaded = _hostedScript.EngineInstance.LoadModuleImage(module);
                _dataProcessorObjectModules.Add(co.Key, _loaded);
            }

            AddDataProcessorManagers(managerFiles);
        }
コード例 #18
0
        public static void OnBeforeScriptRead(HostedScriptEngine engine)
        {
            var cfg = engine.GetWorkingConfig();

            string openerEncoding = cfg["encoding.script"];

            if (!String.IsNullOrWhiteSpace(openerEncoding))
            {
                if (StringComparer.InvariantCultureIgnoreCase.Compare(openerEncoding, "default") == 0)
                {
                    engine.Loader.ReaderEncoding = FileOpener.SystemSpecificEncoding();
                }
                else
                {
                    engine.Loader.ReaderEncoding = Encoding.GetEncoding(openerEncoding);
                }
            }
        }
コード例 #19
0
        public override int Execute()
        {
            var hostedScript = new HostedScriptEngine
            {
                CustomConfig = ScriptFileHelper.CustomConfigPath(_path)
            };

            hostedScript.Initialize();

            if (_isCgi)
            {
                var request = ValueFactory.Create();
                hostedScript.InjectGlobalProperty("ВебЗапрос", request, true);
                hostedScript.InjectGlobalProperty("WebRequest", request, true);
            }

            ScriptFileHelper.OnBeforeScriptRead(hostedScript);
            var source = hostedScript.Loader.FromFile(_path);

            hostedScript.SetGlobalEnvironment(new DoNothingHost(), source);

            try
            {
                if (_envFile != null)
                {
                    var envCompiler = hostedScript.GetCompilerService();
                    var envSrc      = hostedScript.Loader.FromFile(_envFile);
                    envCompiler.Compile(envSrc);
                }
                var compiler = hostedScript.GetCompilerService();
                compiler.Compile(source);
            }
            catch (ScriptException e)
            {
                Output.WriteLine(e.Message);
                return(1);
            }

            Output.WriteLine("No errors.");

            return(0);
        }
コード例 #20
0
        private void Open_Execute(object sender, ExecutedRoutedEventArgs e)
        {
            var dlg = new Microsoft.Win32.OpenFileDialog();

            dlg.Filter      = GetFileDialogFilter();
            dlg.Multiselect = false;
            if (dlg.ShowDialog() == true)
            {
                var hostedScript = new HostedScriptEngine();
                hostedScript.CustomConfig = CustomConfigPath(dlg.FileName);
                SetEncodingFromConfig(hostedScript);

                using (var fs = FileOpener.OpenReader(dlg.FileName))
                {
                    txtCode.Text    = fs.ReadToEnd();
                    _currentDocPath = dlg.FileName;
                    this.Title      = _currentDocPath;
                }
            }
        }
コード例 #21
0
ファイル: StandaloneProcess.cs プロジェクト: team55/1script
        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);
            }
        }
コード例 #22
0
ファイル: MainWindow.xaml.cs プロジェクト: pauliv2/OneScript
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var hostedScript = new HostedScriptEngine();

            hostedScript.Initialize();
            var src = hostedScript.Loader.FromString(txtCode.Text);

            using (var writer = new StringWriter())
            {
                try
                {
                    var moduleWriter = new ScriptEngine.Compiler.ModuleWriter(hostedScript.GetCompilerService());
                    moduleWriter.Write(writer, src);
                    result.Text = writer.GetStringBuilder().ToString();
                }
                catch (Exception exc)
                {
                    result.Text = exc.Message;
                }
            }
        }
コード例 #23
0
        public static void InjectSettings(HostedScriptEngine engine)
        {
            string server     = ConfigurationManager.AppSettings["server"];
            string userName   = ConfigurationManager.AppSettings["userName"];
            string password   = ConfigurationManager.AppSettings["password"];
            string replyTo    = ConfigurationManager.AppSettings["replyTo"] ?? String.Format("{0}@{1}", userName, server);
            string pop3server = ConfigurationManager.AppSettings["pop3server"] ?? server;
            string imapserver = ConfigurationManager.AppSettings["imapserver"] ?? server;

            int  portSmtp;
            bool useSsl;
            int  timeout;

            if (!Int32.TryParse(ConfigurationManager.AppSettings["portSmtp"], out portSmtp))
            {
                portSmtp = 25;
            }

            if (!Boolean.TryParse(ConfigurationManager.AppSettings["useSsl"], out useSsl))
            {
                useSsl = true;
            }

            if (!Int32.TryParse(ConfigurationManager.AppSettings["timeout"], out timeout))
            {
                timeout = 30;
            }

            engine.InjectGlobalProperty("Сервер", ValueFactory.Create(server), true);
            engine.InjectGlobalProperty("СерверPOP3", ValueFactory.Create(pop3server), true);
            engine.InjectGlobalProperty("СерверIMAP", ValueFactory.Create(imapserver), true);
            engine.InjectGlobalProperty("Пользователь", ValueFactory.Create(userName), true);
            engine.InjectGlobalProperty("Пароль", ValueFactory.Create(password), true);
            engine.InjectGlobalProperty("ПортSMTP", ValueFactory.Create(portSmtp), true);
            engine.InjectGlobalProperty("Отправитель", ValueFactory.Create(replyTo), true);
            engine.InjectGlobalProperty("ИспользоватьSSLSMTP", ValueFactory.Create(useSsl), true);
            engine.InjectGlobalProperty("ИспользоватьSSLPOP3", ValueFactory.Create(useSsl), true);
            engine.InjectGlobalProperty("ИспользоватьSSLIMAP", ValueFactory.Create(useSsl), true);
            engine.InjectGlobalProperty("Таймаут", ValueFactory.Create(timeout), true);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
ファイル: CgiBehavior.cs プロジェクト: lintest/OneScript
        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);
        }
コード例 #26
0
        public override int Execute()
        {
            var hostedScript = new HostedScriptEngine();

            hostedScript.CustomConfig = ScriptFileHelper.CustomConfigPath(_path);
            hostedScript.Initialize();
            ScriptFileHelper.OnBeforeScriptRead(hostedScript);
            var source   = hostedScript.Loader.FromFile(_path);
            var compiler = hostedScript.GetCompilerService();
            var writer   = new ScriptEngine.Compiler.ModuleWriter(compiler);

            try
            {
                writer.Write(Console.Out, source);
            }
            catch (ScriptException e)
            {
                Output.WriteLine(e.Message);
                return(1);
            }

            return(0);
        }
コード例 #27
0
        public override int Execute()
        {
            if (!System.IO.File.Exists(_path))
            {
                Echo($"Script file is not found '{_path}'");
                return(2);
            }

            SystemLogger.SetWriter(this);

            var hostedScript = new HostedScriptEngine();

            hostedScript.DebugController = DebugController;
            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.Dispose();

            ScriptFileHelper.OnAfterScriptExecute(hostedScript);

            return(result);
        }
コード例 #28
0
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();

            // Тут можно указать любой класс из компоненты
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent.MyClass)));

            // Если проектов компонент несколько, то надо взять по классу из каждой из них
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_2.MyClass_2)));
            // engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptcomponent_3.MyClass_3)));

            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService().Compile(testrunnerSource);

            {
                var mi = engine.GetType().GetMethod("SetGlobalEnvironment",
                                                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance);
                mi.Invoke(engine, new object[] { this, testrunnerSource });
            }

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Image  = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }
コード例 #29
0
ファイル: EngineHelpWrapper.cs プロジェクト: aliczin/lazyeco
        public HostedScriptEngine StartEngine()
        {
            engine = new HostedScriptEngine();
            engine.Initialize();


            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(OKafkaEco.KafkaClient)));
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(OKafkaEco.OKafkaProducer)));


            // Подключаем тестовую оболочку
            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(EngineHelpWrapper)));

            var testrunnerSource = LoadFromAssemblyResource("NUnitTests.Tests.testrunner.os");
            var testrunnerModule = engine.GetCompilerService()
                                   .Compile(testrunnerSource);

            {
                var mi = engine.GetType().GetMethod("SetGlobalEnvironment",
                                                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance);
                mi.Invoke(engine, new object[] { this, testrunnerSource });
            }

            engine.LoadUserScript(new ScriptEngine.UserAddedScript()
            {
                Type   = ScriptEngine.UserAddedScriptType.Class,
                Image  = testrunnerModule,
                Symbol = "TestRunner"
            });

            var testRunner = AttachedScriptsFactory.ScriptFactory("TestRunner", new IValue[] { });

            TestRunner = ValueFactory.Create(testRunner);

            return(engine);
        }
コード例 #30
0
		public override int Execute()
		{
			var hostedScript = new HostedScriptEngine
			{
				CustomConfig = ScriptFileHelper.CustomConfigPath(_path)
			};
			hostedScript.Initialize();
			ScriptFileHelper.OnBeforeScriptRead(hostedScript);
			var source = hostedScript.Loader.FromFile(_path);
			var compiler = hostedScript.GetCompilerService();
			hostedScript.SetGlobalEnvironment(new DoNothingHost(), source);
			var writer = new ModuleWriter(compiler);
			try
			{
				writer.Write(Console.Out, source);
			}
			catch (ScriptException e)
			{
				Output.WriteLine(e.Message);
				return 1;
			}

			return 0;
		}