Esempio n. 1
0
        private void CopyInterpreterToAttributes(InteractiveInterpreter interpreter,
                                                 IActionContext context)
        {
            IDictionaryEnumerator configEnum;

            configEnum = context.GetConfiguration().GetEnumerator();
            while (configEnum.MoveNext())
            {
                DictionaryEntry property;
                property = (DictionaryEntry)configEnum.Current;
                if (!property.Key.Equals("script"))
                {
                    object attributeValue   = context.GetAttribute((String)property.Key);
                    object interpreterValue = interpreter.GetValue((String)property.Key);
                    // Change the attribute only if the value changed and is marked for copying
                    if (!property.Key.Equals("script") && attributeValue != null &&
                        !attributeValue.Equals(interpreterValue) &&
                        property.Value.ToString().IndexOf("Out") != -1)
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("copy from <-interpreter key:" + property.Key + " oldvalue:" + attributeValue + " newvalue:" + interpreterValue);
                        }
                        context.SetAttribute((String)property.Key, interpreterValue);
                    }
                }
            }
        }
Esempio n. 2
0
        private static List<ValidationResult> runBooScript(string fileName)
        {
            InteractiveInterpreter interpreter = new InteractiveInterpreter();
            interpreter.Ducky = true;

            Func<string, ValidationResult> pass = (m => new ValidationResult(m, ResultType.Pass));
            Func<string, ValidationResult> fail = (m => new ValidationResult(m, ResultType.Fail));
            Func<string, ValidationResult> warn = (m => new ValidationResult(m, ResultType.Warn));

            interpreter.SetValue("results", new List<ValidationResult>());
            interpreter.SetValue("pass", pass);
            interpreter.SetValue("fail", fail);
            interpreter.SetValue("warn", warn);

            CompilerContext ctx = interpreter.EvalCompilerInput(new FileInput(fileName));

            if (ctx.Errors.Count != 0) {
                StringBuilder sb = new StringBuilder();
                foreach (CompilerError error in ctx.Errors) {
                    sb.AppendLine(error.Message);
                }

                throw new ApplicationException(sb.ToString());
            }

            List<ValidationResult> results = interpreter.GetValue("results") as List<ValidationResult>;

            return results;
        }
Esempio n. 3
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;
        }
Esempio n. 5
0
        void ProcessCommand(string command)
        {
            if (interpreter == null)
            {
                interpreter = new InteractiveInterpreter();
                interpreter.RememberLastValue = true;
                interpreter.Print             = PrintLine;
                interpreter.SetValue("cls", new Action(Clear));

                AddReference(typeof(WorkbenchSingleton).Assembly);

                interpreter.LoopEval("import System\n" +
                                     "import System.Collections.Generic\n" +
                                     "import System.IO\n" +
                                     "import System.Text");
            }
            processing = true;
            try {
                interpreter.LoopEval(command);
            } catch (System.Reflection.TargetInvocationException ex) {
                PrintLine(ex.InnerException);
            }
            processing = false;
            if (this.Document.TextLength != 0)
            {
                Append(Environment.NewLine);
            }
            PrintPrompt();
        }
Esempio n. 6
0
		private void CopyInterpreterToAttributes(InteractiveInterpreter interpreter,
												IActionContext context)
		{
			IDictionaryEnumerator configEnum;
			configEnum=context.GetConfiguration().GetEnumerator();
			while(configEnum.MoveNext())
			{
				DictionaryEntry property;
				property = (DictionaryEntry)configEnum.Current;
				if (!property.Key.Equals("script"))
				{
					object attributeValue = context.GetAttribute((String)property.Key);
					object interpreterValue = interpreter.GetValue((String)property.Key);
					// Change the attribute only if the value changed and is marked for copying
					if (!property.Key.Equals("script") && attributeValue != null 
						&& ! attributeValue.Equals(interpreterValue)
						&& property.Value.ToString().IndexOf("Out")!=-1 )
					{
						if (log.IsDebugEnabled)
						{
							log.Debug("copy from <-interpreter key:"+property.Key+" oldvalue:"+attributeValue+ " newvalue:"+interpreterValue);
						}
						context.SetAttribute((String)property.Key,interpreterValue);
					}
				}
			}
		}
		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;
		}
Esempio n. 8
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();
		}
Esempio n. 9
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();
        }
 public BooScriptExecutor(Assembly[] referencedAssemblies, string script)
 {
     _referencedAssemblies = referencedAssemblies;
     _script = script;
     _engine = new InteractiveInterpreter();
     _engine.RememberLastValue = true;
     foreach (Assembly assembly in referencedAssemblies)
     {
         _engine.References.Add(assembly);
     }
 }
 public BooScriptExecutor(Assembly[] referencedAssemblies, string script)
 {
     _referencedAssemblies = referencedAssemblies;
     _script = script;
     _engine = new InteractiveInterpreter();
     _engine.RememberLastValue = true;
     foreach (Assembly assembly in referencedAssemblies)
     {
         _engine.References.Add(assembly);
     }
 }
Esempio n. 12
0
 public double Calcular(string expressao)
 {
     var interpreter = new InteractiveInterpreter {RememberLastValue = true};
     var contexto = interpreter.Parse(new StringInput("expressao", expressao));
     contexto.CompileUnit.Accept(new MethodInvocationFilter());
     var contexto2 = interpreter.EvalCompileUnit(contexto.CompileUnit);
     //var context = interpreter.Eval(expressao);
     if (contexto2.Errors.Count > 0)
     {
         throw new ErroDeCalculoException(contexto2.Errors[0].Message);
     }
     return Convert.ToDouble(interpreter.LastValue);
 }
Esempio n. 13
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);
		}
Esempio n. 14
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);
        }
Esempio n. 15
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();
            }
        }
Esempio n. 16
0
        private void init()
        {
            string filePath = HttpContext.Current.Server.MapPath("~/App_Data/rules.boo");
            _interpreter = new InteractiveInterpreter();
            _interpreter.Ducky = true;

            Action<string, Action> ruleFor = delegate(string name, Action action)
            {
                if (!_rules.ContainsKey(name))
                    _rules[name] = new Dictionary<string, Func<object, string>>();
                _ruleName = name;
                action();
            };

            List<string> fields = RssFieldFactory.Create();
            fields.ForEach(x => getRuleBody(x));

            _interpreter.SetValue("rule_for", ruleFor);
            _interpreter.EvalCompilerInput(new FileInput(filePath));
        }
Esempio n. 17
0
		private void CopyAttributesToInterpreter(InteractiveInterpreter interpreter,
												IActionContext context)
		{
			IDictionaryEnumerator configEnum;
			configEnum=context.GetConfiguration().GetEnumerator();
			while(configEnum.MoveNext())
			{
				DictionaryEntry property;
				property = (DictionaryEntry)configEnum.Current;
				if (!property.Key.Equals("script") && property.Value.ToString().IndexOf("In")!=-1)
				{
					object attributeValue;
					attributeValue = context.GetAttribute((String)property.Key);
					if (log.IsDebugEnabled)
					{
						log.Debug("copy to ->interpreter key:"+property.Key+" value:"+attributeValue);
					}
					interpreter.SetValue((String)property.Key,attributeValue);
				}
			}
		}
Esempio n. 18
0
        private void CopyAttributesToInterpreter(InteractiveInterpreter interpreter,
                                                 IActionContext context)
        {
            IDictionaryEnumerator configEnum;

            configEnum = context.GetConfiguration().GetEnumerator();
            while (configEnum.MoveNext())
            {
                DictionaryEntry property;
                property = (DictionaryEntry)configEnum.Current;
                if (!property.Key.Equals("script") && property.Value.ToString().IndexOf("In") != -1)
                {
                    object attributeValue;
                    attributeValue = context.GetAttribute((String)property.Key);
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("copy to ->interpreter key:" + property.Key + " value:" + attributeValue);
                    }
                    interpreter.SetValue((String)property.Key, attributeValue);
                }
            }
        }
		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;
		}
Esempio n. 20
0
        static void Main(string[] args)
        {
            if (args.Length >= 1)
            {
                var code = File.ReadAllText(args[0]);

                var stw         = new System.Diagnostics.Stopwatch();
                var interpreter = new InteractiveInterpreter(ConsoleProxy);
                stw.Start();
                try
                {
                    interpreter.Run(code);
                }
                finally
                {
                    stw.Stop();
                    Console.WriteLine("[End] " + stw.ElapsedMilliseconds + " ms");
                }
            }
            else
            {
                Console.WriteLine("Script path?");
            }
        }
Esempio n. 21
0
 public BooEnv(BooScripter parent)
 {
     CreatedDate = DateTime.Now;
     _interp = new InteractiveInterpreter();
     _interp.Ducky = true;
     _interp.RememberLastValue = true;
     _interp.SetValue("Db", parent.Db);
     _interp.SetValue("Services", parent.ServiceResolver);
     _interp.SetValue("DSRepo", parent.DSRepo);
     _interp.References.Add(typeof(BooEnv).Assembly);
     _interp.References.Add(typeof(CogMon.Lib.DataRecord).Assembly);
 }
Esempio n. 22
0
		/// <summary>
		/// Initializes a new instance of the <see cref="BooInterpretedScript"/> class.
		/// </summary>
		/// <param name="filename">The filename.</param>
		/// <param name="compilerOutput"></param>
		public BooInterpretedScript(string filename, string compilerOutput)
			: base(filename, compilerOutput)
		{
			_interpreter = new InteractiveInterpreter();
		}
		void ProcessCommand(string command)
		{
			if (interpreter == null) {
				interpreter = new InteractiveInterpreter();
				interpreter.RememberLastValue = true;
				interpreter.Print = PrintLine;
				interpreter.SetValue("cls", new Action(Clear));
				
				AddReference(typeof(WorkbenchSingleton).Assembly);
				
				interpreter.LoopEval("import System\n" +
				                     "import System.Collections.Generic\n" +
				                     "import System.IO\n" +
				                     "import System.Text");
			}
			processing = true;
			try {
				interpreter.LoopEval(command);
			} catch (System.Reflection.TargetInvocationException ex) {
				PrintLine(ex.InnerException);
			}
			processing = false;
			if (this.Document.TextLength != 0) {
				Append(Environment.NewLine);
			}
			PrintPrompt();
		}
Esempio n. 24
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();
			}
		}