/// <summary> /// Destroys this instance app domain. /// </summary> /// <param name="force">A value indicating whether to force destruction immediately, /// without waiting for pending jobs to complete.</param> public void Pushdown(bool force) { try { new Action( () => { this.IsLoaded = false; this.DestroyWatchers(); if (this.machineProxy != null) { try { this.machineProxy.Dispose(force); } catch (RemotingException) { } finally { this.machineProxy = null; } } if (this.domain != null) { AppDomain.Unload(this.domain); this.domain = null; } }).InvokeWithTimeout(30000); } catch (TimeoutException) { this.watchers = new List <BlueCollar.FileSystemWatcher>(); this.machineProxy = null; this.domain = null; } }
/// <summary> /// Destroys this instance app domain. /// </summary> /// <param name="force">A value indicating whether to force destruction immediately, /// without waiting for pending jobs to complete.</param> public void Pushdown(bool force) { try { new Action( () => { this.IsLoaded = false; this.DestroyWatchers(); if (this.machineProxy != null) { try { this.machineProxy.Dispose(force); } catch (RemotingException) { } finally { this.machineProxy = null; } } if (this.domain != null) { AppDomain.Unload(this.domain); this.domain = null; } }).InvokeWithTimeout(30000); } catch (TimeoutException) { this.watchers = new List<BlueCollar.FileSystemWatcher>(); this.machineProxy = null; this.domain = null; } }
public BootstrapsPullupResult PullUp(bool forceMachine) { BootstrapsPullupResult result = null; if (!this.IsLoaded) { try { // Ensure cleanup if we got partway through this before. this.Pushdown(true); if (Directory.Exists(this.ApplicationPath)) { string configPath = this.ConfigPath; // Default to Web.config if not specified and a Web.config file exists. if (string.IsNullOrEmpty(configPath)) { string webConfigPath = Path.Combine(this.ApplicationPath, "Web.config"); if (File.Exists(webConfigPath)) { configPath = webConfigPath; } } // Root the config path relative to the application path. if (!string.IsNullOrEmpty(configPath) && !Path.IsPathRooted(configPath)) { configPath = Path.Combine(this.ApplicationPath, configPath); } if (string.IsNullOrEmpty(configPath) || File.Exists(configPath)) { // Use the bin directory if the target is a web application. string binPath = Path.Combine(this.ApplicationPath, "bin"); bool web = Directory.Exists(binPath) && (string.IsNullOrEmpty(configPath) || (!string.IsNullOrEmpty(configPath) && "Web.config".Equals(Path.GetFileName(configPath), StringComparison.OrdinalIgnoreCase))); AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = this.ApplicationPath; setup.ShadowCopyDirectories = this.ApplicationPath; setup.ShadowCopyFiles = "true"; if (!string.IsNullOrEmpty(configPath)) { setup.ConfigurationFile = configPath; } if (web) { setup.PrivateBinPath = binPath; } else { binPath = this.ApplicationPath; } this.domain = AppDomain.CreateDomain("Blue Collar Machine", AppDomain.CurrentDomain.Evidence, setup); this.logger = new EventLogger(); this.logger.Log += new EventHandler<EventLoggerEventArgs>(this.LoggerLog); object[] constructerArgs = new object[] { this.logger, binPath, forceMachine }; #if NET35 this.machineProxy = (MachineProxy)this.domain.CreateInstanceAndUnwrap( typeof(MachineProxy).Assembly.FullName, typeof(MachineProxy).FullName, false, BindingFlags.Default, null, constructerArgs, null, null, AppDomain.CurrentDomain.Evidence); #else this.machineProxy = (MachineProxy)this.domain.CreateInstanceAndUnwrap( typeof(MachineProxy).Assembly.FullName, typeof(MachineProxy).FullName, false, BindingFlags.Default, null, constructerArgs, null, null); #endif // Create the watchers based on application type. if (web) { this.watchers.Add(this.CreateWatcher(binPath, FileSystemWatcherMode.Directory, "*.dll")); if (!string.IsNullOrEmpty(configPath)) { this.watchers.Add(this.CreateWatcher(Path.GetDirectoryName(configPath), FileSystemWatcherMode.IndividualFiles, Path.GetFileName(configPath))); } string appCodePath = Path.Combine(this.ApplicationPath, "App_Code"); if (Directory.Exists(appCodePath)) { this.watchers.Add(this.CreateWatcher(appCodePath, FileSystemWatcherMode.Directory, "*.*")); } } else { this.watchers.Add(this.CreateWatcher(this.ApplicationPath, FileSystemWatcherMode.Directory, "*.dll")); } this.IsLoaded = true; } else { result = new BootstrapsPullupResult(BootstrapsPullupResultType.ConfigurationFileNotFound); } } else { result = new BootstrapsPullupResult(BootstrapsPullupResultType.ApplicationDirectoryNotFound); } } catch (Exception ex) { this.Pushdown(true); result = new BootstrapsPullupResult(BootstrapsPullupResultType.Exception, ex); } } return result ?? new BootstrapsPullupResult(BootstrapsPullupResultType.Success); }
public BootstrapsPullupResult PullUp(bool forceMachine) { BootstrapsPullupResult result = null; if (!this.IsLoaded) { try { // Ensure cleanup if we got partway through this before. this.Pushdown(true); if (Directory.Exists(this.ApplicationPath)) { string configPath = this.ConfigPath; // Default to Web.config if not specified and a Web.config file exists. if (string.IsNullOrEmpty(configPath)) { string webConfigPath = Path.Combine(this.ApplicationPath, "Web.config"); if (File.Exists(webConfigPath)) { configPath = webConfigPath; } } // Root the config path relative to the application path. if (!string.IsNullOrEmpty(configPath) && !Path.IsPathRooted(configPath)) { configPath = Path.Combine(this.ApplicationPath, configPath); } if (string.IsNullOrEmpty(configPath) || File.Exists(configPath)) { // Use the bin directory if the target is a web application. string binPath = Path.Combine(this.ApplicationPath, "bin"); bool web = Directory.Exists(binPath) && (string.IsNullOrEmpty(configPath) || (!string.IsNullOrEmpty(configPath) && "Web.config".Equals(Path.GetFileName(configPath), StringComparison.OrdinalIgnoreCase))); AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = this.ApplicationPath; setup.ShadowCopyDirectories = this.ApplicationPath; setup.ShadowCopyFiles = "true"; if (!string.IsNullOrEmpty(configPath)) { setup.ConfigurationFile = configPath; } if (web) { setup.PrivateBinPath = binPath; } else { binPath = this.ApplicationPath; } this.domain = AppDomain.CreateDomain("Blue Collar Machine", AppDomain.CurrentDomain.Evidence, setup); this.logger = new EventLogger(); this.logger.Log += new EventHandler <EventLoggerEventArgs>(this.LoggerLog); object[] constructerArgs = new object[] { this.logger, binPath, forceMachine }; #if NET35 this.machineProxy = (MachineProxy)this.domain.CreateInstanceAndUnwrap( typeof(MachineProxy).Assembly.FullName, typeof(MachineProxy).FullName, false, BindingFlags.Default, null, constructerArgs, null, null, AppDomain.CurrentDomain.Evidence); #else this.machineProxy = (MachineProxy)this.domain.CreateInstanceAndUnwrap( typeof(MachineProxy).Assembly.FullName, typeof(MachineProxy).FullName, false, BindingFlags.Default, null, constructerArgs, null, null); #endif // Create the watchers based on application type. if (web) { this.watchers.Add(this.CreateWatcher(binPath, FileSystemWatcherMode.Directory, "*.dll")); if (!string.IsNullOrEmpty(configPath)) { this.watchers.Add(this.CreateWatcher(Path.GetDirectoryName(configPath), FileSystemWatcherMode.IndividualFiles, Path.GetFileName(configPath))); } string appCodePath = Path.Combine(this.ApplicationPath, "App_Code"); if (Directory.Exists(appCodePath)) { this.watchers.Add(this.CreateWatcher(appCodePath, FileSystemWatcherMode.Directory, "*.*")); } } else { this.watchers.Add(this.CreateWatcher(this.ApplicationPath, FileSystemWatcherMode.Directory, "*.dll")); } this.IsLoaded = true; } else { result = new BootstrapsPullupResult(BootstrapsPullupResultType.ConfigurationFileNotFound); } } else { result = new BootstrapsPullupResult(BootstrapsPullupResultType.ApplicationDirectoryNotFound); } } catch (Exception ex) { this.Pushdown(true); result = new BootstrapsPullupResult(BootstrapsPullupResultType.Exception, ex); } } return(result ?? new BootstrapsPullupResult(BootstrapsPullupResultType.Success)); }