2 // System.Web.Configuration.CompilationConfiguration
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (c) Copyright 2003 Ximian, Inc (http://www.ximian.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using System.CodeDom.Compiler;
34 using System.Collections;
35 using System.Configuration;
40 namespace System.Web.Configuration
42 sealed class CompilationConfiguration
47 string default_language = "c#";
48 bool _explicit = true;
49 int max_batch_size = 30;
50 int max_batch_file_size = 3000;
51 int num_recompiles_before_app_restart = 15;
53 string temp_directory;
54 CompilerCollection compilers;
56 bool assembliesInBin = false;
58 /* Only the config. handler should create instances of this. Use GetInstance (context) */
59 public CompilationConfiguration (object p)
61 CompilationConfiguration parent = p as CompilationConfiguration;
65 if (compilers == null)
66 compilers = new CompilerCollection ();
68 if (assemblies == null)
69 assemblies = new ArrayList ();
71 if (temp_directory == null || temp_directory == "")
72 temp_directory = AppDomain.CurrentDomain.SetupInformation.DynamicBase;
75 static public CompilationConfiguration GetInstance (HttpContext context)
77 CompilationConfiguration config;
79 context = HttpContext.Current;
81 if (context != null) {
82 config = context.GetConfig ("system.web/compilation") as CompilationConfiguration;
84 throw new Exception ("Configuration error.");
86 // empty config (as used in unit tests)
87 config = new CompilationConfiguration (null);
93 public CodeDomProvider GetProvider (string language)
95 Compiler compiler = Compilers [language];
99 if (compiler.Provider != null)
100 return compiler.Provider;
102 Type t = Type.GetType (compiler.Type, true);
103 compiler.Provider = Activator.CreateInstance (t) as CodeDomProvider;
104 return compiler.Provider;
107 public string GetCompilerOptions (string language)
109 Compiler compiler = Compilers [language];
110 if (compiler == null)
113 return compiler.CompilerOptions;
116 public int GetWarningLevel (string language)
118 Compiler compiler = Compilers [language];
119 if (compiler == null)
122 return compiler.WarningLevel;
125 void Init (CompilationConfiguration parent)
127 debug = parent.debug;
128 batch = parent.batch;
129 batch_timeout = parent.batch_timeout;
130 default_language = parent.default_language;
131 _explicit = parent._explicit;
132 max_batch_size = parent.max_batch_size;
133 max_batch_file_size = parent.max_batch_file_size;
134 num_recompiles_before_app_restart = parent.num_recompiles_before_app_restart;
135 strict = parent.strict;
136 temp_directory = parent.temp_directory;
138 compilers = new CompilerCollection ();
140 compilers = new CompilerCollection (parent.compilers);
142 ArrayList p = parent.assemblies;
143 assembliesInBin = parent.assembliesInBin;
144 ICollection coll = (p == null) ? (ICollection) new object [0] : p;
145 assemblies = new ArrayList (coll);
149 get { return debug; }
150 set { debug = value; }
154 get { return batch; }
155 set { batch = value; }
158 public int BatchTimeout {
159 get { return batch_timeout; }
160 set { batch_timeout = value; }
163 public string DefaultLanguage {
164 get { return default_language; }
165 set { default_language = value; }
168 public bool Explicit {
169 get { return _explicit; }
170 set { _explicit = value; }
173 public int MaxBatchSize {
174 get { return max_batch_size; }
175 set { max_batch_size = value; }
178 public int MaxBatchFileSize {
179 get { return max_batch_file_size; }
180 set { max_batch_file_size = value; }
183 public int NumRecompilesBeforeAppRestart {
184 get { return num_recompiles_before_app_restart; }
185 set { num_recompiles_before_app_restart = value; }
189 get { return strict; }
190 set { strict = value; }
193 public string TempDirectory {
194 get { return temp_directory; }
196 if (value != null && !Directory.Exists (value))
197 throw new ArgumentException ("Directory does not exist");
199 Console.WriteLine ("Dos: '{0}'\n{1}", value, Environment.StackTrace);
200 temp_directory = value;
204 public CompilerCollection Compilers {
205 get { return compilers; }
208 public ArrayList Assemblies {
209 get { return assemblies; }
212 public bool AssembliesInBin {
213 get { return assembliesInBin; }
214 set { assembliesInBin = value; }