public void DecryptFiles(IPgpEncryption pgpEncryption, DecryptFileContext context, FileInfo[] sourceFiles, CancellationToken token) { foreach (var sourceFile in sourceFiles) { if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } var targetFileName = string.Concat(sourceFile.Name, ".txt"); var targetPath = Path.Combine(context.DirectoryDecrypted, targetFileName); try { logger.DebugFormat("Decrypting \"{0}\" to \"{1}\".", sourceFile.FullName, targetPath); pgpEncryption.DecryptFile(sourceFile.FullName, targetPath); logger.InfoFormat("Decrypted file \"{0}\" to \"{1}\".", sourceFile.FullName, targetPath); var archivePath = Path.Combine(context.DirectoryArchive, "Encrypted", sourceFile.Name); sourceFile.MoveTo(archivePath); } catch (Exception ex) { logger.ErrorFormat(ex, "Unknown error occurred while decrypting file \"{0}\".", sourceFile.FullName); var exceptionPath = Path.Combine(context.DirectoryException, sourceFile.Name); sourceFile.MoveTo(exceptionPath); } } }