2010-06-21 Atsushi Enomoto <atsushi@ximian.com>
[mcs.git] / class / System.Web / System.Web.Compilation / CompilationException.cs
blob4acce3f6d74f095b7098848e2b908d53486d1808
1 //
2 // System.Web.Compilation.CompilationException
3 //
4 // Authors:
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System;
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.CodeDom.Compiler;
35 using System.Runtime.Serialization;
36 using System.Security.Permissions;
37 using System.Text;
38 using System.Web;
40 namespace System.Web.Compilation
42 [Serializable]
43 internal class CompilationException : HtmlizedException
45 string filename;
46 CompilerErrorCollection errors;
47 CompilerResults results;
48 string fileText;
49 string errmsg;
50 int [] errorLines;
52 CompilationException (SerializationInfo info, StreamingContext context)
53 : base (info, context)
55 filename = info.GetString ("filename");
56 errors = info.GetValue ("errors", typeof (CompilerErrorCollection)) as CompilerErrorCollection;
57 results = info.GetValue ("results", typeof (CompilerResults)) as CompilerResults;
58 fileText = info.GetString ("fileText");
59 errmsg = info.GetString ("errmsg");
60 errorLines = info.GetValue ("errorLines", typeof (int[])) as int[];
63 public CompilationException (string filename, CompilerErrorCollection errors, string fileText)
65 this.filename = filename;
66 this.errors = errors;
67 this.fileText = fileText;
70 public CompilationException (string filename, CompilerResults results, string fileText)
71 : this (filename, results != null ? results.Errors : null, fileText)
73 this.results = results;
76 [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
77 public override void GetObjectData (SerializationInfo info, StreamingContext ctx)
79 base.GetObjectData (info, ctx);
80 info.AddValue ("filename", filename);
81 info.AddValue ("errors", errors);
82 info.AddValue ("results", results);
83 info.AddValue ("fileText", fileText);
84 info.AddValue ("errmsg", errmsg);
85 info.AddValue ("errorLines", errorLines);
88 public override string Message {
89 get { return ErrorMessage; }
92 public override string SourceFile {
93 get {
94 if (errors == null || errors.Count == 0)
95 return filename;
97 return errors [0].FileName;
101 public override string FileName {
102 get { return filename; }
105 public override string Title {
106 get { return "Compilation Error"; }
109 public override string Description {
110 get {
111 return "Error compiling a resource required to service this request. " +
112 "Review your source file and modify it to fix this error.";
116 public override string ErrorMessage {
117 get {
118 if (errmsg == null && errors != null) {
119 CompilerError firstError = null;
121 foreach (CompilerError err in errors) {
122 if (err.IsWarning)
123 continue;
124 firstError = err;
125 break;
128 errmsg = firstError.ToString ();
129 int idx = errmsg.IndexOf (" : error ");
130 if (idx > -1)
131 errmsg = errmsg.Substring (idx + 9);
134 return errmsg;
138 public override string FileText {
139 get { return fileText; }
142 public override int [] ErrorLines {
143 get {
144 if (errorLines == null && errors != null) {
145 ArrayList list = new ArrayList ();
146 foreach (CompilerError err in errors) {
147 if (err.IsWarning)
148 continue;
150 if (err.Line != 0 && !list.Contains (err.Line))
151 list.Add (err.Line);
153 errorLines = (int []) list.ToArray (typeof (int));
154 Array.Sort (errorLines);
157 return errorLines;
161 public override bool ErrorLinesPaired {
162 get { return false; }
165 public StringCollection CompilerOutput {
166 get {
167 if (results == null)
168 return null;
170 return results.Output;
174 public CompilerResults Results {
175 get { return results; }