Beispiel #1
0
        IScriptContext getTest1Context()
        {
            var fn = "test01.py";

            var engine = new ScriptController(true);
            var ctx    = engine.CreateScriptContextFromFile(fn);

            return(ctx);
        }
Beispiel #2
0
        public void Run()
        {
            // var code = new StreamReader(Resources.ResourceManager.GetStream("TextFile1.py")).ReadToEnd();
            _controller            = new ScriptController(false);
            _controller.OnMessage += (sender, message) =>
            {
                //Console.WriteLine(message);
                // Console.WriteLine(String.Format("[{0:HH:MM:ss:fff}][SCRIPT]:{1}", DateTime.Now, message.Trim()));
                Console.WriteLine(String.Format("{0}", message.Trim()));
            };
            var            code    = Resources.ResourceManager.GetString("ScriptHeader1");
            dynamic        handler = null;
            IScriptContext ctx;

            try
            {
                if (string.IsNullOrEmpty(script))
                {
                    script = code;
                    ctx    = _controller.CreateScriptContextFromString(script);
                    ctx.Execute();
                }
                else
                {
                    ctx = _controller.CreateScriptContextFromFile(script);
                    ctx.ExecuteString(code);
                    ctx.Execute();
                }



                handler = ctx.Scope.CreateHandler();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }


            _mainProcess = new PyProcessContext(ctx, handler,
                                                _processFactory,
                                                command,
                                                CommandArguments,
                                                workingDirectory,
                                                _commandParameters);


            _mainProcess.Start();

            ctx.FlushBuffer();
            // Console.ReadKey();
        }
Beispiel #3
0
        public void TestPyEngine()
        {
            //var ctx = engine.CreateScriptContextFromString("def test(): return 10 + globalAdd");
            //var fn = @"z:\Dev\Andre\Libraries\AndresCSharpResource\UnitTests\ACSR.Code.PythonScripting.UnitTests\Test01.py";
            var fn = "test01.py";

            var engine = new ScriptController(true);
            var ctx = engine.CreateScriptContextFromFile(fn);
            ctx.Scope.globalAdd = 10;
            var code = ctx.Execute();
            var retVal = ctx.Scope.test(10);
            Assert.AreEqual(ctx.Scope.globalAdd + 10, retVal);
        }
Beispiel #4
0
        public void TestPyEngine()
        {
            //var ctx = engine.CreateScriptContextFromString("def test(): return 10 + globalAdd");
            //var fn = @"z:\Dev\Andre\Libraries\AndresCSharpResource\UnitTests\ACSR.Code.PythonScripting.UnitTests\Test01.py";
            var fn = "test01.py";

            var engine = new ScriptController(true);
            var ctx    = engine.CreateScriptContextFromFile(fn);

            ctx.Scope.globalAdd = 10;
            var code   = ctx.Execute();
            var retVal = ctx.Scope.test(10);

            Assert.AreEqual(ctx.Scope.globalAdd + 10, retVal);
        }
Beispiel #5
0
        public object[] RunScript(IRpcContext context, string FileName, List <string> Args)
        {
            GetParams(Args);
            var args = _cmd.ParamsAfterSwitch("args");

            _context    = context;
            _fileName   = FileName;
            _args       = args;
            _controller = BeginProcess(_processName);

            //c.SearchPaths.Add(@"E:\Dev\Source\AndresIPyResource\Scripts");
            var ctx = _controller.CreateScriptContextFromFile(FileName);

            _controller.SetSysArgV(args);

            ctx.Execute();
            return(new object[0]);
        }
Beispiel #6
0
        public object[] RunScript(IRpcContext context, string FileName, List<string> Args)
        {
            GetParams(Args);
            var args = _cmd.ParamsAfterSwitch("args");

            _context = context;
            _fileName = FileName;
            _args = args;
            _controller = BeginProcess(_processName);

            //c.SearchPaths.Add(@"E:\Dev\Source\AndresIPyResource\Scripts");
            var ctx = _controller.CreateScriptContextFromFile(FileName);
            _controller.SetSysArgV(args);

            ctx.Execute();
            return new object[0];
        }
Beispiel #7
0
 void CreateScript()
 {
     _engine = new ScriptController(true);
     _context = _engine.CreateScriptContextFromFile(_fullPath);
     _engine.OnMessage += new MessageEvent(_engine_OnMessage);
 }
Beispiel #8
0
        public void Run()
        {
            // var code = new StreamReader(Resources.ResourceManager.GetStream("TextFile1.py")).ReadToEnd();
            _controller = new ScriptController(false);
            _controller.OnMessage += (sender, message) =>
                {
                    //Console.WriteLine(message);
                   // Console.WriteLine(String.Format("[{0:HH:MM:ss:fff}][SCRIPT]:{1}", DateTime.Now, message.Trim()));
                    Console.WriteLine(String.Format("{0}", message.Trim()));

                };
            var code = Resources.ResourceManager.GetString("ScriptHeader1");
            dynamic handler = null;
            IScriptContext ctx;
            try
            {

                if (string.IsNullOrEmpty(script))
                {
                    script = code;
                    ctx = _controller.CreateScriptContextFromString(script);
                    ctx.Execute();
                }
                else
                {
                    ctx = _controller.CreateScriptContextFromFile(script);
                    ctx.ExecuteString(code);
                    ctx.Execute();
                }

                handler = ctx.Scope.CreateHandler();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            _mainProcess = new PyProcessContext(ctx, handler,
                _processFactory,
                command,
                CommandArguments,
                workingDirectory,
                _commandParameters);

            _mainProcess.Start();

            ctx.FlushBuffer();
               // Console.ReadKey();
        }
Beispiel #9
0
        IScriptContext getTest1Context()
        {
            var fn = "test01.py";

            var engine = new ScriptController(true);
            var ctx = engine.CreateScriptContextFromFile(fn);
            return ctx;
        }