2 // System.Web.Configuration.CompilationConfiguration
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (c) Copyright 2003 Ximian, Inc (http://www.ximian.com)
11 using System.CodeDom.Compiler;
12 using System.Collections;
13 using System.Configuration;
18 namespace System.Web.Configuration
20 sealed class CompilationConfiguration
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;
31 string temp_directory;
32 CompilerCollection compilers;
34 bool assembliesInBin = false;
36 /* Only the config. handler should create instances of this. Use GetInstance (context) */
37 public CompilationConfiguration (object p)
39 CompilationConfiguration parent = p as CompilationConfiguration;
43 if (compilers == null)
44 compilers = new CompilerCollection ();
46 if (assemblies == null)
47 assemblies = new ArrayList ();
49 if (temp_directory == null)
50 temp_directory = Path.GetTempPath ();
53 static public CompilationConfiguration GetInstance (HttpContext context)
55 CompilationConfiguration config;
57 context = HttpContext.Context;
59 config = context.GetConfig ("system.web/compilation") as CompilationConfiguration;
62 throw new Exception ("Configuration error.");
67 public CodeDomProvider GetProvider (string language)
69 WebCompiler compiler = Compilers [language];
73 if (compiler.Provider != null)
74 return compiler.Provider;
76 Type t = Type.GetType (compiler.Type);
77 compiler.Provider = Activator.CreateInstance (t) as CodeDomProvider;
78 return compiler.Provider;
81 public string GetCompilerOptions (string language)
83 WebCompiler compiler = Compilers [language];
87 return compiler.CompilerOptions;
90 public int GetWarningLevel (string language)
92 WebCompiler compiler = Compilers [language];
96 return compiler.WarningLevel;
99 void Init (CompilationConfiguration parent)
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);
119 get { return debug; }
120 set { debug = value; }
124 get { return batch; }
125 set { batch = value; }
128 public int BatchTimeout {
129 get { return batch_timeout; }
130 set { batch_timeout = value; }
133 public string DefaultLanguage {
134 get { return default_language; }
135 set { default_language = value; }
138 public bool Explicit {
139 get { return _explicit; }
140 set { _explicit = value; }
143 public int MaxBatchSize {
144 get { return max_batch_size; }
145 set { max_batch_size = value; }
148 public int MaxBatchFileSize {
149 get { return max_batch_file_size; }
150 set { max_batch_file_size = value; }
153 public int NumRecompilesBeforeAppRestart {
154 get { return num_recompiles_before_app_restart; }
155 set { num_recompiles_before_app_restart = value; }
159 get { return strict; }
160 set { strict = value; }
163 public string TempDirectory {
164 get { return temp_directory; }
166 if (value != null && !Directory.Exists (value))
167 throw new ArgumentException ("Directory does not exist");
169 temp_directory = value;
173 public CompilerCollection Compilers {
174 get { return compilers; }
177 public ArrayList Assemblies {
178 get { return assemblies; }
181 public bool AssembliesInBin {
182 get { return assembliesInBin; }
183 set { assembliesInBin = value; }