public static string RoboCopyDirectory(DirectoryInfo sourceDir, DirectoryInfo targetDir) { // Mirror NoProgress Wait 0 Retry 0 var arguments = new List <string> { "/MIR", "/NP", "/W:0", "/R:0", ProcessUtility.EncodeArgumentForCommandLine(sourceDir.FullName), ProcessUtility.EncodeArgumentForCommandLine(targetDir.FullName) }; var processUtilityResult = ProcessUtility.ShellAndWaitImpl(sourceDir.Parent.FullName, "robocopy.exe", arguments, true, null); var robocopySucceeded = (processUtilityResult.ReturnCode < 4); var exitCodeEvaluation = robocopySucceeded ? "Robocopy OK" : "Robocopy ERROR"; var outputAndExitCode = String.Format("{2}\r\n{0}\r\nExit Code: {1} {2}", processUtilityResult.StdOutAndStdErr, processUtilityResult, exitCodeEvaluation); if (!robocopySucceeded) { throw new Exception(outputAndExitCode); } return(outputAndExitCode); }
/// <summary> /// Convert Html page at a given URL to a PDF file using open-source tool wkhtml2pdf /// </summary> // ReSharper disable once InconsistentNaming public static void ConvertURLToPDF(Uri url, FileInfo outputFile, PdfConversionSettings settings) { Check.RequireNotNull(settings); var exeInfo = new FileInfo(SitkaConfiguration.GetRequiredAppSetting(settings.AppKeyExecPath)); Check.RequireFileExists(exeInfo); Check.RequireDirectoryExists(outputFile.DirectoryName); var commandLineArguments = settings.BuildCommandSwitches(); commandLineArguments.Add(url.ToString()); commandLineArguments.Add(outputFile.FullName); var result = ProcessUtility.ShellAndWaitImpl(exeInfo.DirectoryName, exeInfo.FullName, commandLineArguments, true, Convert.ToInt32(settings.ExecutionTimeout.TotalMilliseconds)); var retCode = result.ReturnCode; var argumentsAsString = String.Join(" ", commandLineArguments.Select(ProcessUtility.EncodeArgumentForCommandLine).ToList()); var fullProcessAndArguments = $"{ProcessUtility.EncodeArgumentForCommandLine(exeInfo.FullName)} {argumentsAsString}"; Check.Ensure(retCode == 0, $"Process {exeInfo.Name} returned with exit code {retCode}, expected exit code 0.\r\nProcess Command Line:\r\n{fullProcessAndArguments}\r\nProcess Working Directory: {exeInfo.DirectoryName}\r\nStdErr and StdOut:\r\n{result.StdOutAndStdErr}"); }