2 // System.Web.Configuration.CompilationConfigurationHandler
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 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.
32 using System.Collections;
33 using System.Configuration;
36 namespace System.Web.Configuration
38 class CompilationConfigurationHandler : IConfigurationSectionHandler
40 public object Create (object parent, object context, XmlNode section)
42 CompilationConfiguration config = new CompilationConfiguration (parent);
44 string tmp = AttValue ("tempDirectory", section, true);
45 if (tmp != null && tmp != "")
46 config.TempDirectory = tmp;
47 config.DefaultLanguage = AttValue ("defaultLanguage", section);
48 if (config.DefaultLanguage == null)
49 config.DefaultLanguage = "c#";
51 config.Debug = AttBoolValue ("debug", section, false);
52 config.Batch = AttBoolValue ("batch", section, false);
53 config.Explicit = AttBoolValue ("explicit", section, true);
54 config.Strict = AttBoolValue ("strict", section, false);
55 config.BatchTimeout = AttUIntValue ("batchTimeout", section, 0);
56 config.MaxBatchSize = AttUIntValue ("maxBatchSize", section, 0);
57 config.MaxBatchFileSize = AttUIntValue ("maxBatchFileSize", section, 0);
58 config.NumRecompilesBeforeAppRestart =
59 AttUIntValue ("numRecompilesBeforeAppRestart", section, 15);
61 if (section.Attributes != null && section.Attributes.Count != 0)
62 ThrowException ("Unrecognized attribute.", section);
64 XmlNodeList authNodes = section.ChildNodes;
65 foreach (XmlNode child in authNodes) {
66 XmlNodeType ntype = child.NodeType;
67 if (ntype != XmlNodeType.Element)
70 if (child.Name == "compilers") {
71 ReadCompilers (child.ChildNodes, config);
75 if (child.Name == "assemblies") {
76 ReadAssemblies (child.ChildNodes, config);
80 ThrowException ("Unexpected element", child);
86 static void ReadCompilers (XmlNodeList nodes, CompilationConfiguration config)
88 foreach (XmlNode child in nodes) {
89 XmlNodeType ntype = child.NodeType;
90 if (ntype != XmlNodeType.Element)
93 if (child.Name != "compiler")
94 ThrowException ("Unexpected element", child);
96 Compiler compiler = new Compiler ();
97 compiler.Language = AttValue ("language", child);
98 compiler.Extension = AttValue ("extension", child);
99 compiler.Type = AttValue ("type", child);
100 compiler.CompilerOptions = AttValue ("compilerOptions", child, true, true);
101 compiler.WarningLevel = AttUIntValue ("warningLevel", child, 0);
103 config.Compilers.Add (compiler);
105 config.Compilers [compiler.Language] = compiler;
110 static void ReadAssemblies (XmlNodeList nodes, CompilationConfiguration config)
112 ArrayList assemblies = config.Assemblies;
114 foreach (XmlNode child in nodes) {
115 XmlNodeType ntype = child.NodeType;
116 if (ntype != XmlNodeType.Element)
119 if (child.Name == "clear") {
121 config.AssembliesInBin = false;
125 string aname = AttValue ("assembly", child);
126 if (child.Name == "add") {
128 config.AssembliesInBin = true;
132 if (!assemblies.Contains (aname))
133 assemblies.Add (aname);
138 if (child.Name == "remove") {
140 config.AssembliesInBin = false;
143 assemblies.Remove (aname);
147 ThrowException ("Unexpected element " + child.Name, child);
151 static string AttValue (string name, XmlNode node, bool optional)
153 return AttValue (name, node, optional, false);
156 static string AttValue (string name, XmlNode node, bool optional, bool allowEmpty)
158 return HandlersUtil.ExtractAttributeValue (name, node, optional, allowEmpty);
161 static bool AttBoolValue (string name, XmlNode node, bool _default)
163 string v = AttValue (name, node, true);
167 bool result = (v == "true");
168 if (!result && v != "false")
169 ThrowException ("Invalid boolean value in " + name, node);
174 static int AttUIntValue (string name, XmlNode node, int _default)
176 string v = AttValue (name, node, true);
182 result = (int) UInt32.Parse (v);
184 ThrowException ("Invalid number in " + name, node);
190 static string AttValue (string name, XmlNode node)
192 return HandlersUtil.ExtractAttributeValue (name, node, true);
195 static void ThrowException (string message, XmlNode node)
197 HandlersUtil.ThrowException (message, node);