using System;
using System.Collections;
+using System.Collections.Specialized;
using System.CodeDom.Compiler;
+using System.Runtime.Serialization;
+using System.Security.Permissions;
using System.Text;
using System.Web;
namespace System.Web.Compilation
{
+ [Serializable]
internal class CompilationException : HtmlizedException
{
string filename;
CompilerErrorCollection errors;
+ CompilerResults results;
string fileText;
string errmsg;
int [] errorLines;
+ CompilationException (SerializationInfo info, StreamingContext context)
+ : base (info, context)
+ {
+ filename = info.GetString ("filename");
+ errors = info.GetValue ("errors", typeof (CompilerErrorCollection)) as CompilerErrorCollection;
+ results = info.GetValue ("results", typeof (CompilerResults)) as CompilerResults;
+ fileText = info.GetString ("fileText");
+ errmsg = info.GetString ("errmsg");
+ errorLines = info.GetValue ("errorLines", typeof (int[])) as int[];
+ }
+
public CompilationException (string filename, CompilerErrorCollection errors, string fileText)
{
this.filename = filename;
this.fileText = fileText;
}
+ public CompilationException (string filename, CompilerResults results, string fileText)
+ : this (filename, results != null ? results.Errors : null, fileText)
+ {
+ this.results = results;
+ }
+
+ [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
+ public override void GetObjectData (SerializationInfo info, StreamingContext ctx)
+ {
+ base.GetObjectData (info, ctx);
+ info.AddValue ("filename", filename);
+ info.AddValue ("errors", errors);
+ info.AddValue ("results", results);
+ info.AddValue ("fileText", fileText);
+ info.AddValue ("errmsg", errmsg);
+ info.AddValue ("errorLines", errorLines);
+ }
+
+ public override string Message {
+ get { return ErrorMessage; }
+ }
+
public override string SourceFile {
get {
if (errors == null || errors.Count == 0)
public override string ErrorMessage {
get {
if (errmsg == null && errors != null) {
- StringBuilder sb = new StringBuilder ();
+ CompilerError firstError = null;
+
foreach (CompilerError err in errors) {
- sb.Append (err);
- sb.Append ("\n");
- }
- errmsg = sb.ToString ();
+ if (err.IsWarning)
+ continue;
+ firstError = err;
+ break;
+ };
+
+ errmsg = firstError.ToString ();
+ int idx = errmsg.IndexOf (" : error ");
+ if (idx > -1)
+ errmsg = errmsg.Substring (idx + 9);
}
return errmsg;
if (errorLines == null && errors != null) {
ArrayList list = new ArrayList ();
foreach (CompilerError err in errors) {
+ if (err.IsWarning)
+ continue;
+
if (err.Line != 0 && !list.Contains (err.Line))
list.Add (err.Line);
}
public override bool ErrorLinesPaired {
get { return false; }
}
+
+ public StringCollection CompilerOutput {
+ get {
+ if (results == null)
+ return null;
+
+ return results.Output;
+ }
+ }
+
+ public CompilerResults Results {
+ get { return results; }
+ }
}
}