/// <summary> /// Perfroms the startup, registration, and shutdown for the given files. Useful if you don't care /// about any of the intermediate steps and just want stuff shut down (and are OK with the entire thing failing /// if any steps fail) /// </summary> /// <param name="files"></param> public void EasyShutdown(IEnumerable <string> files) { RestartManager.RM_REBOOT_REASON rebootreason = default(RestartManager.RM_REBOOT_REASON); StartSession(); RegisterResources(files); var processesToRestart = RestartManager.RmProcessToNetProcess(GetList(ref rebootreason)); if (rebootreason != RM_REBOOT_REASON.RmRebootReasonNone) { string message = "There are processes or services which the RestartManager can't shut down!"; Logger.Warn("RestartManagerSession.EasyShutdown encountered error: " + message); throw new RmSessionException(message); } Logger.Info("The following processes will be affected by the RestartManager: " + string.Join(", ", processesToRestart.Select(x => x.ProcessName))); try { Shutdown(); } catch (Exception ex) { EndSession(); throw ex; } Logger.Info("RestartManager successfully shut down the above processes"); }
/// <summary> /// Retrieve the list of processes that are holding onto registered resources. ALSO internally sets /// the list of processes to manually restart /// </summary> /// <param name="lpdwRebootReasons"></param> /// <returns></returns> public override List <RM_PROCESS_INFO> GetList(ref RM_REBOOT_REASON lpdwRebootReasons) { Logger.Trace(string.Format("Getting RMSession {0} process list with {1} manual processes to restart", SessionKey, ManualRestartProcesses.Count)); var processes = base.GetList(ref lpdwRebootReasons); var netProcesses = RestartManager.RmProcessToNetProcess(processes); ProcessesToManuallyShutdown = netProcesses.Where(x => ManualRestartProcesses.Select(y => y.Replace(".exe", "")).Contains(x.ProcessName)).ToList(); return(processes); }
/// <summary> /// Try to get the list of processes affected by the registered resources AS .net processes /// </summary> /// <param name="lpdwRebootReasons"></param> /// <returns></returns> public virtual List <Process> GetListAsProcesses(ref RM_REBOOT_REASON lpdwRebootReasons) { return(RestartManager.RmProcessToNetProcess(GetList(ref lpdwRebootReasons))); }