public override void ExecuteTask(EnvironmentManager environmentManager, DeleteDirectoryTask updateTask, Logger logger, StatusUpdater statusUpdater) { var directory = new DirectoryInfo(environmentManager.TranslateFilename(updateTask.DirectoryPath)); if (!directory.Exists) { logger.Info("The directory does not exist."); return; } statusUpdater.UpdateStatus(statusUpdater.Translation.DeleteDirectory, statusUpdater.FormatFilename(directory.FullName)); var tempDirectory = environmentManager.GetRandomTempDirectory(); SourceDirectoryPath = directory.FullName; TempDirectory = tempDirectory.FullName; logger.Info($"Move directory {directory.FullName} to {tempDirectory.FullName}"); Retry.Do(() => FileExtensions.RobustMoveDirectory(directory.FullName, tempDirectory.FullName), TimeSpan.FromSeconds(2), 3, logger); }
public override void ExecuteTask(EnvironmentManager environmentManager, StartProcessTask updateTask, Logger logger, StatusUpdater statusUpdater) { statusUpdater.UpdateStatus(statusUpdater.Translation.StartProcess, statusUpdater.FormatFilename(updateTask.Filename)); var processStartInfo = new ProcessStartInfo(environmentManager.TranslateFilename(updateTask.Filename), updateTask.Arguments); if (updateTask.RequireElevatedPrivileges) { processStartInfo.Verb = "runas"; } var process = Process.Start(processStartInfo); if (process == null) { throw new InvalidOperationException("Unable to start process"); } ProcessId = process.Id; ProcessName = process.ProcessName; if (updateTask.WaitForExit) { statusUpdater.UpdateStatus(statusUpdater.Translation.WaitingForProcessToExit, process.ProcessName); process.WaitForExit(); if (updateTask.FailIfProcessReturnsFailure && process.ExitCode != 0) { throw new InvalidOperationException( $"The process returned the exit code {process.ExitCode}. Because that code is not zero and \"FailIfProcessReturnsFailure\" is checked, the operation must be aborted."); } } }