2 // System.Web.Compilation.WebServiceCompiler
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
8 // Copyright (c) 2040 Novell, Inc. (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.CodeDom.Compiler;
34 using System.Web.Configuration;
36 using System.Reflection;
38 namespace System.Web.Compilation
40 class WebServiceCompiler : BaseCompiler
42 SimpleWebHandlerParser parser;
43 ICodeCompiler compiler;
44 CodeDomProvider provider;
45 CompilerParameters compilerParameters;
48 public WebServiceCompiler (SimpleWebHandlerParser wService)
51 this.parser = wService;
54 public static Type CompileIntoType (SimpleWebHandlerParser wService)
56 WebServiceCompiler wsc = new WebServiceCompiler (wService);
57 return wsc.GetCompiledType ();
60 public override Type GetCompiledType ()
62 Type type = CachingCompiler.GetTypeFromCache (parser.PhysicalPath, parser.ClassName);
66 if (parser.Program.Trim () == "")
67 return parser.GetTypeFromBin (parser.ClassName);
69 string lang = parser.Language;
70 CompilationConfiguration config;
71 config = CompilationConfiguration.GetInstance (parser.Context);
72 provider = config.GetProvider (lang);
74 throw new HttpException ("Configuration error. Language not supported: " +
77 compiler = provider.CreateCompiler ();
79 compilerParameters = CachingCompiler.GetOptions (parser.Assemblies);
80 compilerParameters.IncludeDebugInformation = parser.Debug;
81 compilerParameters.CompilerOptions = config.GetCompilerOptions (lang);
82 compilerParameters.WarningLevel = config.GetWarningLevel (lang);
84 bool keepFiles = (Environment.GetEnvironmentVariable ("MONO_ASPNET_NODELETE") != null);
86 TempFileCollection tempcoll;
87 tempcoll = new TempFileCollection (config.TempDirectory, keepFiles);
88 compilerParameters.TempFiles = tempcoll;
90 inputFile = tempcoll.AddExtension (provider.FileExtension);
91 Stream st = File.OpenWrite (inputFile);
92 StreamWriter sw = new StreamWriter (st);
93 sw.WriteLine (parser.Program);
96 string dllfilename = Path.GetFileName (tempcoll.AddExtension ("dll", true));
97 if (!Directory.Exists (dynamicBase))
98 Directory.CreateDirectory (dynamicBase);
100 compilerParameters.OutputAssembly = Path.Combine (dynamicBase, dllfilename);
102 CompilerResults results = CachingCompiler.Compile (this);
103 CheckCompilerErrors (results);
104 if (results.CompiledAssembly == null)
105 throw new CompilationException (inputFile, results.Errors,
106 "No assembly returned after compilation!?");
108 results.TempFiles.Delete ();
109 return results.CompiledAssembly.GetType (parser.ClassName, true);
112 void CheckCompilerErrors (CompilerResults results)
114 if (results.NativeCompilerReturnValue == 0)
117 throw new CompilationException (parser.PhysicalPath, results.Errors, parser.Program);
120 internal new SimpleWebHandlerParser Parser {
121 get { return parser; }
124 internal override ICodeCompiler Compiler {
125 get { return compiler; }
128 internal CompilerParameters CompilerOptions {
129 get { return compilerParameters; }
132 internal string InputFile {
133 get { return inputFile; }