public ActionResult Compile(TextReader source) { List<ParseException> compilationErrors = new List<ParseException>(); List<ParseException> compactionErrors = new List<ParseException>(); IOptimizedResult result = new JbstCompiler().Compile(source, null, compilationErrors, compactionErrors); string jbstName = (result is JbstBuildResult) ? (string)((JbstBuildResult)result).JbstName : String.Empty; HttpStatusCode statusCode = HttpStatusCode.OK; object data; if (compilationErrors.Count > 0) { statusCode = HttpStatusCode.BadRequest; List<object> foo = new List<object>(compilationErrors.Count); foreach (ParseException ex in compilationErrors) { foo.Add(new { Message = ex.Message, Line = ex.Line, Col = ex.Column }); } data = new { name = jbstName, key = result.Hash, source = result.Source, errors = foo }; } else if (compactionErrors.Count > 0) { statusCode = HttpStatusCode.BadRequest; List<CompilationError> foo = new List<CompilationError>(compactionErrors.Count); foreach (ParseException ex in compactionErrors) { foo.Add(new CompilationError { Message = ex.Message, Line = ex.Line, Col = ex.Column }); } data = new CompilationResult { name = jbstName, key = result.Hash, source = result.PrettyPrinted, errors = foo }; } else { data = new CompilationResult { name = jbstName, key = result.Hash, pretty = result.PrettyPrinted, compacted = result.Compacted }; } return this.DataResult(data, statusCode); }
public ActionResult Test(CompilationResult result) { return this.DataResult(result); }