/// ----------------------------------------------------------------------------- /// <summary> /// The BackupFile method backs up a file to the backup folder /// </summary> /// <param name="installFile">The file to backup</param> /// <param name="basePath">The basePath to the file</param> /// <param name="log">A Logger to log the result</param> public static void BackupFile(InstallFile installFile, string basePath, Logger log) { string fullFileName = Path.Combine(basePath, installFile.FullName); string backupFileName = Path.Combine(installFile.BackupPath, installFile.Name + ".config"); //create the backup folder if neccessary if (!Directory.Exists(installFile.BackupPath)) { Directory.CreateDirectory(installFile.BackupPath); } //Copy file to backup location RetryableAction.RetryEverySecondFor30Seconds(() => FileSystemUtils.CopyFile(fullFileName, backupFileName), "Backup file " + fullFileName); log.AddInfo(string.Format(FILE_CreateBackup, installFile.FullName)); }
/// <summary> /// Open the archive file for read and write. /// </summary> /// <param name="archiveFileName"></param> /// <returns></returns> public static ZipArchive OpenCreate(string archiveFileName) { if (string.IsNullOrWhiteSpace(archiveFileName)) { throw new ArgumentNullException(nameof(archiveFileName)); } ZipArchive zip = null; RetryableAction.RetryEverySecondFor30Seconds( () => zip = OpenCreateUnsafe(archiveFileName), $"{nameof(OpenCreateUnsafe)}(\"{archiveFileName}\")"); return(zip); }
/// ----------------------------------------------------------------------------- /// <summary> /// The DeleteFile method deletes a file. /// </summary> /// <param name="fileName">The file to delete</param> /// <param name="basePath">The basePath to the file</param> /// <param name="log">A Logger to log the result</param> /// <history> /// [cnurse] 08/03/2007 created /// </history> /// ----------------------------------------------------------------------------- public static void DeleteFile(string fileName, string basePath, Logger log) { string fullFileName = Path.Combine(basePath, fileName); if (File.Exists(fullFileName)) { RetryableAction.RetryEverySecondFor30Seconds(() => FileSystemUtils.DeleteFile(fullFileName), "Delete file " + fullFileName); log.AddInfo(string.Format(FILE_Deleted, fileName)); string folderName = Path.GetDirectoryName(fullFileName); if (folderName != null) { var folder = new DirectoryInfo(folderName); TryDeleteFolder(folder, log); } } }
/// ----------------------------------------------------------------------------- /// <summary> /// The CopyFile method copies a file from the temporary extract location. /// </summary> /// <param name="installFile">The file to copy</param> /// <param name="basePath">The basePath to the file</param> /// <param name="log">A Logger to log the result</param> /// <history> /// [cnurse] 08/03/2007 created /// </history> /// ----------------------------------------------------------------------------- public static void CopyFile(InstallFile installFile, string basePath, Logger log) { string filePath = Path.Combine(basePath, installFile.Path); string fullFileName = Path.Combine(basePath, installFile.FullName); //create the folder if neccessary if (!Directory.Exists(filePath)) { log.AddInfo(string.Format(FOLDER_Created, filePath)); Directory.CreateDirectory(filePath); } //Copy file from temp location RetryableAction.RetryEverySecondFor30Seconds(() => FileSystemUtils.CopyFile(installFile.TempFileName, fullFileName), "Copy file to " + fullFileName); log.AddInfo(string.Format(FILE_Created, installFile.FullName)); }
/// ----------------------------------------------------------------------------- /// <summary> /// VerifyFolderCreate checks whether a folder can be created /// </summary> /// ----------------------------------------------------------------------------- public bool VerifyFolderCreate() { string verifyPath = Path.Combine(_basePath, "Verify"); bool verified = true; //Attempt to create the Directory try { RetryableAction.RetryEverySecondFor30Seconds(() => FolderCreateAction(verifyPath), "Creating verification folder"); } catch (Exception exc) { DnnLog.Error(exc); verified = false; } return(verified); }
/// ----------------------------------------------------------------------------- /// <summary> /// VerifyFileCreate checks whether a file can be created /// </summary> /// ----------------------------------------------------------------------------- public bool VerifyFileCreate() { string verifyPath = Path.Combine(_basePath, "Verify\\Verify.txt"); bool verified = VerifyFolderCreate(); if (verified) { //Attempt to create the File try { RetryableAction.RetryEverySecondFor30Seconds(() => FileCreateAction(verifyPath), "Creating verification file"); } catch (Exception exc) { DnnLog.Error(exc); verified = false; } } return(verified); }
public static bool RetryOnFail(int attemptsAllowed, string actionDescriptionOnError, RetryableAction action) { bool success = false; int attempts = 0; while (!success && (attempts < attemptsAllowed)) { try { action(); success = true; } catch (Exception ex) { Console.WriteLine(actionDescriptionOnError); PrintExceptionDetails(ex); } attempts++; } return success; }