Example #1
0
        public override int Execute()
        {
            Console.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.Initialize();
                var source = engine.Loader.FromFile(_codePath);
                var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                var persistor = new ScriptEngine.Compiler.ModulePersistor(formatter);
                var compiler = engine.GetCompilerService();
                persistor.Save(compiler.CreateModule(source), output);

                byte[] signature = new byte[4]
                    {
                        0x4f,0x53,0x4d,0x44
                    };
                output.Write(signature, 0, signature.Length);
                using (var bw = new BinaryWriter(output))
                {
                    bw.Write(offset);
                }
            }
            Console.WriteLine("Make completed");
            return 0;
        }
Example #2
0
        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;
            }

        }
Example #3
0
        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;
        }
 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;
 }
Example #5
0
        public static HostedScriptEngine StartEngine()
        {
            var engine = new ScriptEngine.HostedScript.HostedScriptEngine();

            engine.Initialize();

            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(oscriptFtp.FtpConnection)));

            return(engine);
        }
Example #6
0
        public static HostedScriptEngine StartEngine()
        {
            var engine = new ScriptEngine.HostedScript.HostedScriptEngine();

            engine.Initialize();

            engine.AttachAssembly(System.Reflection.Assembly.GetAssembly(typeof(v8unpack.File8Reader)));

            return(engine);
        }
Example #7
0
        public static HostedScriptEngine StartEngine()
        {
            var engine = new ScriptEngine.HostedScript.HostedScriptEngine();

            engine.Initialize();

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

            return(engine);
        }
        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();
        }
Example #9
0
        public static HostedScriptEngine StartEngine()
        {
            var engine = new ScriptEngine.HostedScript.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)));

            return(engine);
        }
Example #10
0
        static void Main(string[] args)
        {
            var engine = new ScriptEngine.HostedScript.HostedScriptEngine();

            engine.Initialize();

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

            var MyRef = new onescript_extensions.AssemblyReflector.AssemblyReflector();

            MyRef.LoadAssembly(ScriptEngine.Machine.ValueFactory.Create(@"c:\work\portable\OneScript\lib\extensions\bin\onescript-extensions.dll"));
            var newdata = MyRef.GetAsmTypes();

            onescript_extensions.AssemblyReflector.AssemblyType curT = (onescript_extensions.AssemblyReflector.AssemblyType)newdata.Get(0);
            var PPP = curT.GetProperties();

            Console.WriteLine(newdata);
        }
Example #11
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());

            var hostedScript = new HostedScriptEngine();
            hostedScript.Initialize();
            var src = new EditedFileSource(txtCode.Text, _currentDocPath);

            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());
            
        }
Example #12
0
 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;
         }
     }
     
 }
Example #13
0
        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());
        }