Example #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;
        }
Example #2
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);
					}
				}
			}
		}
Example #3
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);
                    }
                }
            }
        }
Example #4
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"));
        }
Example #5
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();
            }
        }
Example #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();
			}
		}