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; }
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)); }