Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CompilationConfiguration.cs « System.Web.Configuration « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 71b84e5ce29f1df0c5a4b98ca22f414aaf9c8f5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//
// System.Web.Configuration.CompilationConfiguration
//
// Authors:
//	Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (c) Copyright 2003 Ximian, Inc (http://www.ximian.com)
//

using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Configuration;
using System.IO;
using System.Web;
using System.Xml;

namespace System.Web.Configuration
{
	sealed class CompilationConfiguration
	{
		bool debug = false;
		bool batch = false;
		int batch_timeout;
		string default_language = "c#";
		bool _explicit = true;
		int max_batch_size = 30;
		int max_batch_file_size = 3000;
		int num_recompiles_before_app_restart = 15;
		bool strict = false;
		string temp_directory;
		CompilerCollection compilers;
		ArrayList assemblies;
		bool assembliesInBin = false;

		/* Only the config. handler should create instances of this. Use GetInstance (context) */
		public CompilationConfiguration (object p)
		{
			CompilationConfiguration parent = p as CompilationConfiguration;
			if (parent != null)
				Init (parent);

			if (compilers == null)
				compilers = new CompilerCollection ();

			if (assemblies == null)
				assemblies = new ArrayList ();

			if (temp_directory == null)
				temp_directory = Path.GetTempPath ();
		}

		static public CompilationConfiguration GetInstance (HttpContext context)
		{
			CompilationConfiguration config;
			if (context == null)
				context = HttpContext.Context;

			config = context.GetConfig ("system.web/compilation") as CompilationConfiguration;

			if (config == null)
				throw new Exception ("Configuration error.");

			return config;
		}
		
		public CodeDomProvider GetProvider (string language)
		{
			WebCompiler compiler = Compilers [language];
			if (compiler == null)
				return null;

			if (compiler.Provider != null)
				return compiler.Provider;

			Type t = Type.GetType (compiler.Type);
			compiler.Provider = Activator.CreateInstance (t) as CodeDomProvider;
			return compiler.Provider;
		}

		public string GetCompilerOptions (string language)
		{
			WebCompiler compiler = Compilers [language];
			if (compiler == null)
				return null;

			return compiler.CompilerOptions;
		}

		public int GetWarningLevel (string language)
		{
			WebCompiler compiler = Compilers [language];
			if (compiler == null)
				return 0;

			return compiler.WarningLevel;
		}

		void Init (CompilationConfiguration parent)
		{
			debug = parent.debug;
			batch = parent.batch;
			batch_timeout = parent.batch_timeout;
			default_language = parent.default_language;
			_explicit = parent._explicit;
			max_batch_size = parent.max_batch_size;
			max_batch_file_size = parent.max_batch_file_size;
			num_recompiles_before_app_restart = parent.num_recompiles_before_app_restart;
			strict = parent.strict;
			temp_directory = parent.temp_directory;
			compilers = new CompilerCollection (parent.compilers);
			ArrayList p = parent.assemblies;
			assembliesInBin = parent.assembliesInBin;
			ICollection coll = (p == null) ? (ICollection) new object [0] : p;
			assemblies = new ArrayList (coll);
		}

		public bool Debug {
			get { return debug; }
			set { debug = value; }
		}

		public bool Batch {
			get { return batch; }
			set { batch = value; }
		}

		public int BatchTimeout {
			get { return batch_timeout; }
			set { batch_timeout = value; }
		}

		public string DefaultLanguage {
			get { return default_language; }
			set { default_language = value; }
		}

		public bool Explicit {
			get { return _explicit; }
			set { _explicit = value; }
		}

		public int MaxBatchSize {
			get { return max_batch_size; }
			set { max_batch_size = value; }
		}

		public int MaxBatchFileSize {
			get { return max_batch_file_size; }
			set { max_batch_file_size = value; }
		}

		public int NumRecompilesBeforeAppRestart {
			get { return num_recompiles_before_app_restart; }
			set { num_recompiles_before_app_restart = value; }
		}

		public bool Strict {
			get { return strict; }
			set { strict = value; }
		}

		public string TempDirectory {
			get { return temp_directory; }
			set {
				if (value != null && !Directory.Exists (value))
					throw new ArgumentException ("Directory does not exist");

				temp_directory = value;
			}
		}

		public CompilerCollection Compilers {
			get { return compilers; }
		}

		public ArrayList Assemblies {
			get { return assemblies; }
		}

		public bool AssembliesInBin {
			get { return assembliesInBin; }
			set { assembliesInBin = value; }
		}
	}
}