2010-01-20 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / CompilationException.cs
1 //
2 // CompilationException
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
8 //
9
10 //
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.
29 //
30
31 using System;
32 using System.Collections;
33 using System.CodeDom.Compiler;
34 using System.Text;
35 using System.Web;
36
37 namespace System.ServiceModel.Channels
38 {
39         internal class CompilationException : HtmlizedException
40         {
41                 string filename;
42                 CompilerErrorCollection errors;
43                 string fileText;
44                 string errmsg;
45                 int [] errorLines;
46
47                 public CompilationException (string filename, CompilerErrorCollection errors, string fileText)
48                 {
49                         this.filename = filename;
50                         this.errors = errors;
51                         this.fileText = fileText;
52                 }
53
54                 public override string SourceFile {
55                         get {
56                                 if (errors == null || errors.Count == 0)
57                                         return filename;
58
59                                 return errors [0].FileName;
60                         }
61                 }
62                 
63                 public override string FileName {
64                         get { return filename; }
65                 }
66                 
67                 public override string Title {
68                         get { return "Compilation Error"; }
69                 }
70
71                 public override string Description {
72                         get {
73                                 return "Error compiling a resource required to service this request. " +
74                                        "Review your source file and modify it to fix this error.";
75                         }
76                 }
77
78                 public override string ErrorMessage {
79                         get {
80                                 if (errmsg == null && errors != null) {
81                                         StringBuilder sb = new StringBuilder ();
82                                         foreach (CompilerError err in errors) {
83                                                 sb.Append (err);
84                                                 sb.Append ("\n");
85                                         }
86                                         errmsg = sb.ToString ();
87                                 }
88
89                                 return errmsg;
90                         }
91                 }
92
93                 public override string FileText {
94                         get { return fileText; }
95                 }
96
97                 public override int [] ErrorLines {
98                         get {
99                                 if (errorLines == null && errors != null) {
100                                         ArrayList list = new ArrayList ();
101                                         foreach (CompilerError err in errors) {
102                                                 if (err.Line != 0 && !list.Contains (err.Line))
103                                                         list.Add (err.Line);
104                                         }
105                                         errorLines = (int []) list.ToArray (typeof (int));
106                                         Array.Sort (errorLines);
107                                 }
108
109                                 return errorLines;
110                         }
111                 }
112
113                 public override bool ErrorLinesPaired {
114                         get { return false; }
115                 }
116         }
117 }
118