More 1.1 code and NET_2_0 ifdefs removed
[mono.git] / mcs / class / System.Web / System.Web.Compilation / CompilationException.cs
index d312be69804ebd18287b34b9d28cbbff1bbdf65d..4acce3f6d74f095b7098848e2b908d53486d1808 100644 (file)
 
 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;
@@ -51,6 +67,28 @@ namespace System.Web.Compilation
                        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)
@@ -78,12 +116,19 @@ namespace System.Web.Compilation
                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;
@@ -99,6 +144,9 @@ namespace System.Web.Compilation
                                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);
                                        }
@@ -113,6 +161,19 @@ namespace System.Web.Compilation
                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; }
+               }
        }
 }