Exemplo n.º 1
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;
        }
Exemplo n.º 2
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();
        }
        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;
        }
Exemplo n.º 4
0
		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;
		}
            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);
            }
Exemplo n.º 6
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();
            }
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
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);
				}
			}
		}
Exemplo n.º 9
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);
                }
            }
        }
Exemplo n.º 10
0
		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;
		}
Exemplo n.º 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();
			}
		}
		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();
		}
Exemplo n.º 13
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);
 }