/// <summary> /// Emits the shell request. /// </summary> /// <param name="args">The arguments.</param> protected void EmitShellRequest(ShellRequestArgs args) { var handler = OnShellRequest; if (handler != null) { handler(this, args); } }
/// <summary> /// Observes the console finalization and restart. /// <remarks>Due to app domains being shutdown, we needed to provide a higher level tool to observe the shut-down of the app domain before we startup a new instance (with regard to the control panel).</remarks> /// </summary> private void ObserveConsoleFinalizationAndRestart() { _log.Info("Waiting for console to shutdown so it can be restarted."); bool restartIssued = false; while (!restartIssued) { Task.Delay(TimeSpan.FromSeconds(5)).Wait(); if (_console == null) { _restartConsoleTask = null; _log.Info("Console has completed its shutdown process... restarting."); StartupConsole(); restartIssued = true; if (_requestArgsForRestart != null) { _log.Info("Attempting to cleanup old versions of the console in the hoarde."); CleanupHoarde(_requestArgsForRestart); } _requestArgsForRestart = null; } } _restartConsoleTask = null; }
/// <summary> /// Handles requests coming from an app instance. /// <remarks> /// Realistically, the only app that will utilize this event will be Drey.Configuration, so it can request for instances to be started/stopped/restarted as necessary. /// </remarks> /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> private void ShellRequestHandler(object sender, ShellRequestArgs e) { // when shutting down, the shutdown command is executing the ShutdownConsole() method. if (_shuttingDown) { return; } // right now, the shutdown command is working as expected, but cannot seem to trigger a restart. if (e.PackageId.Equals(DreyConstants.ConfigurationPackageName, StringComparison.OrdinalIgnoreCase)) { _log.InfoFormat("Control Panel 'Shell Request' Event Received: {0}", e); switch (e.ActionToTake) { case ShellAction.Startup: _log.Warn("Seems odd to get a startup call here. Should investigate."); break; case ShellAction.Shutdown: ShutdownConsole(); break; case ShellAction.Restart: if (_restartConsoleTask == null) { _restartConsoleTask = new Task(ObserveConsoleFinalizationAndRestart); _restartConsoleTask.Start(); } _requestArgsForRestart = e; ShutdownConsole(); break; case ShellAction.Heartbeat: _log.TraceFormat("Received heartbeat from {packageId} at {now}", e.PackageId, DateTime.Now); break; default: _log.ErrorFormat("Received an unknown action: {0}", e.ActionToTake); break; } return; } //_console.Item2.Protege.ShellRequestHandler(sender, e); }
/// <summary> /// Removes historical versions of the applet from the hoarde. /// </summary> /// <param name="e">The e.</param> /// <exception cref="System.NotImplementedException"></exception> private void CleanupHoarde(ShellRequestArgs e) { _log.InfoFormat("Remove other versions: {removeVersions} | Action to Take: {action}", e.RemoveOtherVersionsOnRestart, e.ActionToTake); if (!(e.RemoveOtherVersionsOnRestart && e.ActionToTake == ShellAction.Restart)) { return; } _log.Info("Cleaning up hoarde due to restart and RemoveOtherVersionsOnRestart being set to true."); var dir = new DirectoryInfo(Utilities.PathUtilities.MapPath(_configurationManager.HoardeBaseDirectory)); var deployments = dir.EnumerateDirectories(e.PackageId + "*", searchOption: System.IO.SearchOption.TopDirectoryOnly) .Where(di => !di.Name.EndsWith(e.Version)) .Apply(di => { _log.DebugFormat("Removing {folder} from hoarde.", di.Name); Directory.Delete(di.FullName, true); // This removes all contents of the folder as well. }); }