fixed ParseServerVariables().
[mono.git] / mcs / class / System.Web / System.Web.Configuration / CompilationConfiguration.cs
1 //
2 // System.Web.Configuration.CompilationConfiguration
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (c) Copyright 2003 Ximian, Inc (http://www.ximian.com)
8 //
9
10 using System;
11 using System.CodeDom.Compiler;
12 using System.Collections;
13 using System.Configuration;
14 using System.IO;
15 using System.Web;
16 using System.Xml;
17
18 namespace System.Web.Configuration
19 {
20         sealed class CompilationConfiguration
21         {
22                 bool debug = false;
23                 bool batch = false;
24                 int batch_timeout;
25                 string default_language = "c#";
26                 bool _explicit = true;
27                 int max_batch_size = 30;
28                 int max_batch_file_size = 3000;
29                 int num_recompiles_before_app_restart = 15;
30                 bool strict = false;
31                 string temp_directory;
32                 CompilerCollection compilers;
33                 ArrayList assemblies;
34                 bool assembliesInBin = false;
35
36                 /* Only the config. handler should create instances of this. Use GetInstance (context) */
37                 public CompilationConfiguration (object p)
38                 {
39                         CompilationConfiguration parent = p as CompilationConfiguration;
40                         if (parent != null)
41                                 Init (parent);
42
43                         if (compilers == null)
44                                 compilers = new CompilerCollection ();
45
46                         if (assemblies == null)
47                                 assemblies = new ArrayList ();
48
49                         if (temp_directory == null)
50                                 temp_directory = Path.GetTempPath ();
51                 }
52
53                 static public CompilationConfiguration GetInstance (HttpContext context)
54                 {
55                         CompilationConfiguration config;
56                         if (context == null)
57                                 context = HttpContext.Context;
58
59                         config = context.GetConfig ("system.web/compilation") as CompilationConfiguration;
60
61                         if (config == null)
62                                 throw new Exception ("Configuration error.");
63
64                         return config;
65                 }
66                 
67                 public CodeDomProvider GetProvider (string language)
68                 {
69                         WebCompiler compiler = Compilers [language];
70                         if (compiler == null)
71                                 return null;
72
73                         if (compiler.Provider != null)
74                                 return compiler.Provider;
75
76                         Type t = Type.GetType (compiler.Type);
77                         compiler.Provider = Activator.CreateInstance (t) as CodeDomProvider;
78                         return compiler.Provider;
79                 }
80
81                 public string GetCompilerOptions (string language)
82                 {
83                         WebCompiler compiler = Compilers [language];
84                         if (compiler == null)
85                                 return null;
86
87                         return compiler.CompilerOptions;
88                 }
89
90                 public int GetWarningLevel (string language)
91                 {
92                         WebCompiler compiler = Compilers [language];
93                         if (compiler == null)
94                                 return 0;
95
96                         return compiler.WarningLevel;
97                 }
98
99                 void Init (CompilationConfiguration parent)
100                 {
101                         debug = parent.debug;
102                         batch = parent.batch;
103                         batch_timeout = parent.batch_timeout;
104                         default_language = parent.default_language;
105                         _explicit = parent._explicit;
106                         max_batch_size = parent.max_batch_size;
107                         max_batch_file_size = parent.max_batch_file_size;
108                         num_recompiles_before_app_restart = parent.num_recompiles_before_app_restart;
109                         strict = parent.strict;
110                         temp_directory = parent.temp_directory;
111                         compilers = new CompilerCollection (parent.compilers);
112                         ArrayList p = parent.assemblies;
113                         assembliesInBin = parent.assembliesInBin;
114                         ICollection coll = (p == null) ? (ICollection) new object [0] : p;
115                         assemblies = new ArrayList (coll);
116                 }
117
118                 public bool Debug {
119                         get { return debug; }
120                         set { debug = value; }
121                 }
122
123                 public bool Batch {
124                         get { return batch; }
125                         set { batch = value; }
126                 }
127
128                 public int BatchTimeout {
129                         get { return batch_timeout; }
130                         set { batch_timeout = value; }
131                 }
132
133                 public string DefaultLanguage {
134                         get { return default_language; }
135                         set { default_language = value; }
136                 }
137
138                 public bool Explicit {
139                         get { return _explicit; }
140                         set { _explicit = value; }
141                 }
142
143                 public int MaxBatchSize {
144                         get { return max_batch_size; }
145                         set { max_batch_size = value; }
146                 }
147
148                 public int MaxBatchFileSize {
149                         get { return max_batch_file_size; }
150                         set { max_batch_file_size = value; }
151                 }
152
153                 public int NumRecompilesBeforeAppRestart {
154                         get { return num_recompiles_before_app_restart; }
155                         set { num_recompiles_before_app_restart = value; }
156                 }
157
158                 public bool Strict {
159                         get { return strict; }
160                         set { strict = value; }
161                 }
162
163                 public string TempDirectory {
164                         get { return temp_directory; }
165                         set {
166                                 if (value != null && !Directory.Exists (value))
167                                         throw new ArgumentException ("Directory does not exist");
168
169                                 temp_directory = value;
170                         }
171                 }
172
173                 public CompilerCollection Compilers {
174                         get { return compilers; }
175                 }
176
177                 public ArrayList Assemblies {
178                         get { return assemblies; }
179                 }
180
181                 public bool AssembliesInBin {
182                         get { return assembliesInBin; }
183                         set { assembliesInBin = value; }
184                 }
185         }
186 }
187