2 // System.Web.Compilation.ClientBuildManager
5 // Chris Toshok (toshok@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
8 // (C) 2006 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.
35 using System.CodeDom.Compiler;
36 using System.Collections;
37 using System.Globalization;
40 using System.Web.Hosting;
42 namespace System.Web.Compilation {
43 public sealed class ClientBuildManager : MarshalByRefObject, IDisposable {
46 //string phys_target_dir;
47 //ClientBuildManagerParameter build_params;
48 BareApplicationHost host;
49 ApplicationManager manager;
53 public ClientBuildManager (string appVirtualDir, string appPhysicalSourceDir)
55 if (appVirtualDir == null || appVirtualDir == "")
56 throw new ArgumentNullException ("appVirtualDir");
57 if (appPhysicalSourceDir == null || appPhysicalSourceDir == "")
58 throw new ArgumentNullException ("appPhysicalSourceDir");
60 virt_dir = appVirtualDir; // TODO: adjust vpath (it allows 'blah' that turns into '/blah', '////blah', '\\blah'...
61 phys_src_dir = appPhysicalSourceDir;
62 manager = ApplicationManager.GetApplicationManager ();
65 public ClientBuildManager (string appVirtualDir, string appPhysicalSourceDir,
66 string appPhysicalTargetDir)
67 : this (appVirtualDir, appPhysicalSourceDir)
69 if (appPhysicalTargetDir == null || appPhysicalTargetDir == "")
70 throw new ArgumentNullException ("appPhysicalTargetDir");
72 //phys_target_dir = appPhysicalTargetDir;
75 public ClientBuildManager (string appVirtualDir, string appPhysicalSourceDir,
76 string appPhysicalTargetDir, ClientBuildManagerParameter parameter)
77 : this (appVirtualDir, appPhysicalSourceDir, appPhysicalTargetDir)
79 //build_params = parameter;
82 public event BuildManagerHostUnloadEventHandler AppDomainShutdown;
83 public event EventHandler AppDomainStarted;
84 public event BuildManagerHostUnloadEventHandler AppDomainUnloaded;
86 BareApplicationHost Host {
91 int hashcode = virt_dir.GetHashCode ();
93 hashcode ^= Int32.Parse (app_id);
95 app_id = hashcode.ToString (CultureInfo.InvariantCulture);
96 host = manager.CreateHostWithCheck (app_id, virt_dir, phys_src_dir);
98 //cache_path = Path.Combine (Path.GetTempPath (),
99 //String.Format ("{0}-temp-aspnet-{1:x}", Environment.UserName, i));
101 int hash = virt_dir.GetHashCode () << 5 + phys_src_dir.GetHashCode ();
102 cache_path = Path.Combine (cache_path, hash.ToString (CultureInfo.InvariantCulture));
103 Directory.CreateDirectory (cache_path);
104 OnAppDomainStarted ();
109 void OnAppDomainStarted ()
111 if (AppDomainStarted != null)
112 AppDomainStarted (this, EventArgs.Empty);
115 void OnAppDomainShutdown (ApplicationShutdownReason reason)
117 if (AppDomainShutdown != null) {
118 BuildManagerHostUnloadEventArgs args = new BuildManagerHostUnloadEventArgs (reason);
119 AppDomainShutdown (this, args);
123 // void OnDomainUnload (object sender, EventArgs args)
125 // OnAppDomainUnloaded (0); // FIXME: set a reason?
128 // void OnAppDomainUnloaded (ApplicationShutdownReason reason)
130 // if (AppDomainUnloaded != null) {
131 // BuildManagerHostUnloadEventArgs args = new BuildManagerHostUnloadEventArgs (reason);
132 // AppDomainUnloaded (this, args);
136 [MonoTODO ("Not implemented")]
137 public void CompileApplicationDependencies ()
139 throw new NotImplementedException ();
142 public void CompileFile (string virtualPath)
144 CompileFile (virtualPath, null);
147 [MonoTODO ("Not implemented")]
148 public void CompileFile (string virtualPath, ClientBuildManagerCallback callback)
150 // 1. Creates the Host
151 // This creates a .compiled file + an assembly
152 // App_Code reported to be built *before* anything else (with progress callback)
153 throw new NotImplementedException ();
156 public IRegisteredObject CreateObject (Type type, bool failIfExists)
158 return manager.CreateObject (app_id, type, virt_dir, phys_src_dir, failIfExists);
161 [MonoTODO("Currently does not return the GeneratedCode")]
162 public string GenerateCode (string virtualPath, string virtualFileString, out IDictionary linePragmasTable)
164 // This thing generates a .ccu (CodeCompileUnit?) file (reported as TrueType font data by 'file'!)
165 // resultType=7 vs. resultType=3 for assemblies reported in the .compiled file
166 // The virtual path is just added to the dependencies list, but is checked to be an absolute path.
167 // IsHostCreated returns true after calling this method.
169 // A null file string causes virtualPath to be mapped and read to generate the code
172 if (virtualPath == null || virtualPath == "")
173 throw new ArgumentNullException ("virtualPath");
175 CodeCompileUnit unit = null;
177 CompilerParameters parameters;
178 unit = GenerateCodeCompileUnit (virtualPath, virtualFileString, out cprovider_type,
179 out parameters, out linePragmasTable);
183 [MonoTODO ("Not implemented")]
184 public CodeCompileUnit GenerateCodeCompileUnit (string virtualPath,
185 string virtualFileString,
186 out Type codeDomProviderType,
187 out CompilerParameters compilerParameters,
188 out IDictionary linePragmasTable)
190 throw new NotImplementedException ();
193 public CodeCompileUnit GenerateCodeCompileUnit (string virtualPath,
194 out Type codeDomProviderType,
195 out CompilerParameters compilerParameters,
196 out IDictionary linePragmasTable)
198 return GenerateCodeCompileUnit (virtualPath, out codeDomProviderType,
199 out compilerParameters, out linePragmasTable);
202 static string [] shutdown_directories = new string [] {
203 "bin", "App_GlobalResources", "App_Code",
204 "App_WebReferences", "App_Browsers" };
206 public string [] GetAppDomainShutdownDirectories ()
208 return shutdown_directories;
211 [MonoTODO ("Not implemented")]
212 public IDictionary GetBrowserDefinitions ()
214 throw new NotImplementedException ();
217 [MonoTODO ("Not implemented")]
218 public void GetCodeDirectoryInformation (string virtualCodeDir,
219 out Type codeDomProviderType,
220 out CompilerParameters compilerParameters,
221 out string generatedFilesDir)
223 throw new NotImplementedException ();
226 [MonoTODO ("Not implemented")]
227 public Type GetCompiledType (string virtualPath)
229 // CompileFile + get the type based on .compiled file information
230 // Throws if virtualPath is a special virtual directory (App_Code et al)
231 throw new NotImplementedException ();
234 [MonoTODO ("Not implemented")]
235 public void GetCompilerParameters (string virtualPath,
236 out Type codeDomProviderType,
237 out CompilerParameters compilerParameters)
239 throw new NotImplementedException ();
242 [MonoTODO ("Not implemented")]
243 public string GetGeneratedFileVirtualPath (string filePath)
245 // returns empty string for any vpath. Test with real paths.
246 throw new NotImplementedException ();
249 [MonoTODO ("Not implemented")]
250 public string GetGeneratedSourceFile (string virtualPath)
252 // This one takes a directory name /xxx and /xxx/App_Code throw either
253 // a KeyNotFoundException or an InvalidOperationException
254 throw new NotImplementedException ();
257 [MonoTODO ("Not implemented")]
258 public string [] GetTopLevelAssemblyReferences (string virtualPath)
260 throw new NotImplementedException ();
263 public string [] GetVirtualCodeDirectories ()
265 // Host is created here when needed. (Unload()+GetVirtualCodeDirectories()+IsHostCreated -> true)
267 throw new NotImplementedException ();
270 public override object InitializeLifetimeService ()
275 [MonoTODO ("Not implemented")]
276 public bool IsCodeAssembly (string assemblyName)
278 // Trying all the assemblies loaded by FullName and GetName().Name yield false here :-?
279 throw new NotImplementedException ();
282 [MonoTODO ("Not implemented")]
283 public void PrecompileApplication ()
285 throw new NotImplementedException ();
288 [MonoTODO ("Not implemented")]
289 public void PrecompileApplication (ClientBuildManagerCallback callback)
291 throw new NotImplementedException ();
294 [MonoTODO ("Not implemented")]
295 public void PrecompileApplication (ClientBuildManagerCallback callback, bool forceCleanBuild)
297 throw new NotImplementedException ();
300 public bool Unload ()
304 OnAppDomainShutdown (0);
308 return true; // FIXME: may be we should do this synch. + timeout? Test!
311 public string CodeGenDir {
312 get { return Host.GetCodeGenDir (); }
315 public bool IsHostCreated {
316 get { return host != null; }
319 void IDisposable.Dispose ()