Exemple #1
0
        private static object InterpretScriptLines(IEnumerable <string> scriptLines, DataPackage data)
        {
            var interpreter = new InteractiveInterpreter {
                RememberLastValue = true
            };
            const string exprText = "%Expression%";
            var          sb       = new StringBuilder();

            foreach (var line in scriptLines)
            {
                var newLine = line;
                var pos     = line.IndexOf(exprText);
                if (pos == -1)
                {
                    sb.AppendLine(newLine);
                    continue;
                }
                newLine = line.Substring(0, pos) + data.Text + line.Substring(pos + exprText.Length);
                sb.AppendLine(newLine);
            }
            sb.AppendLine("expr = BooEvaluator()");
            sb.AppendLine("result = expr.Evaluate()");
            var interpreterContext = interpreter.Eval(sb.ToString());

            Ensure.IsZero(interpreterContext.Errors.Count);
            return(interpreter.GetValue("result"));
        }
		void ProcessCommand(string command)
		{
			if (interpreter == null) {
				interpreter = new InteractiveInterpreter();
				interpreter.RememberLastValue = true;
				//interpreter.Print = PrintLine; TODO reimplement print
				interpreter.SetValue("cls", new Action(Clear));
				
				AddReference(typeof(WorkbenchSingleton).Assembly);
				
				interpreter.Eval("import System\n" +
				                 "import System.Collections.Generic\n" +
				                 "import System.IO\n" +
				                 "import System.Text\n" +
				                 "import System.Linq.Enumerable");
			}
			processing = true;
			try {
				CompilerContext results = interpreter.Eval(command);
				if (results.Errors.Count > 0) {
					PrintLine("ERROR: " + results.Errors[0].Message);
				} else if (interpreter.LastValue != null) {
					PrintLine(ReprModule.repr(interpreter.LastValue));
				}
			} catch (System.Reflection.TargetInvocationException ex) {
				PrintLine(ex.InnerException);
			}
			processing = false;
		}
        void ProcessCommand(string command)
        {
            if (interpreter == null)
            {
                interpreter = new InteractiveInterpreter();
                interpreter.RememberLastValue = true;
                //interpreter.Print = PrintLine; TODO reimplement print
                interpreter.SetValue("cls", new Action(Clear));

                AddReference(typeof(WorkbenchSingleton).Assembly);

                interpreter.Eval("import System\n" +
                                 "import System.Collections.Generic\n" +
                                 "import System.IO\n" +
                                 "import System.Text\n" +
                                 "import System.Linq.Enumerable");
            }
            processing = true;
            try {
                CompilerContext results = interpreter.Eval(command);
                if (results.Errors.Count > 0)
                {
                    PrintLine("ERROR: " + results.Errors[0].Message);
                }
                else if (interpreter.LastValue != null)
                {
                    PrintLine(ReprModule.repr(interpreter.LastValue));
                }
            } catch (System.Reflection.TargetInvocationException ex) {
                PrintLine(ex.InnerException);
            }
            processing = false;
        }
Exemple #4
0
		private static void Main(string[] args)
		{
			InteractiveInterpreter  interpreter = new InteractiveInterpreter();
			interpreter.RememberLastValue = true;
			interpreter.References.Add(Assembly.Load("Bumbler"));
			interpreter.References.Add(Assembly.Load("NHibernate"));
			interpreter.Eval("import Bumbler");
			interpreter.ConsoleLoopEval();
		}
Exemple #5
0
        private static void Main(string[] args)
        {
            InteractiveInterpreter interpreter = new InteractiveInterpreter();

            interpreter.RememberLastValue = true;
            interpreter.References.Add(Assembly.Load("Bumbler"));
            interpreter.References.Add(Assembly.Load("NHibernate"));
            interpreter.Eval("import Bumbler");
            interpreter.ConsoleLoopEval();
        }
Exemple #6
0
		public void Run(IActionContext actionContext)
		{
			InteractiveInterpreter interpreter = new InteractiveInterpreter();

			IDictionary configuration = actionContext.GetConfiguration();
			String script = (String) configuration["script"];
			if (script == null)
			{
				throw new ArgumentException("Can’t find boo script in configuration! Please check processdefiniton.xml if action defines <parameter name = \"script\">");
			}

			CopyAttributesToInterpreter(interpreter,actionContext);
			interpreter.Eval(script);
			CopyInterpreterToAttributes(interpreter,actionContext);
		}
Exemple #7
0
        public void Run(IActionContext actionContext)
        {
            InteractiveInterpreter interpreter = new InteractiveInterpreter();

            IDictionary configuration = actionContext.GetConfiguration();
            String      script        = (String)configuration["script"];

            if (script == null)
            {
                throw new ArgumentException("Can’t find boo script in configuration! Please check processdefiniton.xml if action defines <parameter name = \"script\">");
            }

            CopyAttributesToInterpreter(interpreter, actionContext);
            interpreter.Eval(script);
            CopyInterpreterToAttributes(interpreter, actionContext);
        }
            public object Execute(IDictionary <string, object> arguments)
            {
                // add all the globals
                IDictionary <string, object> args = CollectionUtil.NullAsEmpty(arguments);

                foreach (KeyValuePair <string, object> entry in args)
                {
                    _engine.SetValue(entry.Key, entry.Value);
                }
                CompilerContext context = _engine.Eval(_script);

                if (context.Errors.Count > 0)
                {
                    throw context.Errors[0];
                }
                return(_engine.LastValue);
            }
Exemple #9
0
        void BtnEvaluateCodeClick(object sender, EventArgs e)
        {
            InteractiveInterpreter ii = new InteractiveInterpreter();

            ii.References.Add(System.Reflection.Assembly.GetExecutingAssembly());
            ii.Ducky = true;
            ii.SetValue("console", "");
            CompilerContext cx = ii.Eval(txtCode.Text);

            if (cx.Errors.Count > 0)
            {
                txtConsoleOutput.Text = cx.Errors.ToString();
            }
            else
            {
                txtConsoleOutput.Text = ii.GetValue("console").ToString();
            }
        }
		void ProcessCommand(string command)
		{
			if (interpreter == null) {
				interpreter = new InteractiveInterpreter();
				interpreter.RememberLastValue = true;
				//interpreter.Print = PrintLine; TODO reimplement print
				interpreter.SetValue("cls", new Action(Clear));
				
				AddReference(typeof(WorkbenchSingleton).Assembly);
				
				interpreter.Eval("import System\n" +
				                 "import System.Collections.Generic\n" +
				                 "import System.IO\n" +
				                 "import System.Text\n" +
				                 "import System.Linq.Enumerable");
			}
			processing = true;
			try {
				interpreter.Eval(command);
			} catch (System.Reflection.TargetInvocationException ex) {
				PrintLine(ex.InnerException);
			}
			processing = false;
		}
Exemple #11
0
		void BtnEvaluateCodeClick(object sender, EventArgs e)
		{
			InteractiveInterpreter ii = new InteractiveInterpreter();
			ii.References.Add(System.Reflection.Assembly.GetExecutingAssembly());
			ii.Ducky = true;
			ii.SetValue("console", "");
			CompilerContext cx = ii.Eval(txtCode.Text);
			if(cx.Errors.Count > 0)
			{
				txtConsoleOutput.Text = cx.Errors.ToString();
			}
			else
			{
				txtConsoleOutput.Text = ii.GetValue("console").ToString();
			}
		}