/// <summary> /// Returns error specific PublisherTypes.ActionResultType.Failed or PublisherTypes.ActionResultType.WithWarnings /// type PublisherActionResults in case parameters are incorrect, or ActionResultType.Successful if they are correct /// </summary> /// <param name="sourcepath">Path of the source file</param> /// <param name="targetpath">Path of the target file</param> /// <param name="currentusersecurity">CurrentUserSecurity object used to check access rights</param> /// <returns>PublisherActionResult with specific ActionResultType and message</returns> public static PublisherActionResult CopyFileToFilePreCheck(string sourcepath, string targetpath, CurrentUserSecurity currentusersecurity) { if (String.IsNullOrEmpty(sourcepath)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"Source path ({sourcepath}) is not valid!" )); } else if (!File.Exists(sourcepath)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"Source file ({sourcepath}) does not exist!" )); } else if (!currentusersecurity.HasAccess(new FileInfo(sourcepath), FileSystemRights.Read)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"No read access to source file ({sourcepath})!" )); } else if (String.IsNullOrEmpty(targetpath)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"Target path ({targetpath}) is not valid!" )); } else if (!Directory.Exists(Path.GetDirectoryName(targetpath))) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"Target directory ({Path.GetDirectoryName(targetpath)}) does not exist!" )); } else if (!currentusersecurity.HasAccess(new DirectoryInfo(Path.GetDirectoryName(targetpath)), FileSystemRights.Write)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"No write access to target path ({targetpath})!" )); } else { return(new PublisherActionResult( PublisherTypes.ActionResultType.Successful, $"Pre Check Succesful!" )); } }
/// <summary> /// Returns error specific PublisherTypes.ActionResultType.Failed or PublisherTypes.ActionResultType.WithWarnings /// type PublisherActionResults in case parameters are incorrect, or ActionResultType.Successful if they are correct /// </summary> /// <param name="filepath">Path of the file to archive</param> /// <param name="archivepath">Path of the archive file</param> /// <param name="currentusersecurity">CurrentUserSecurity object used to check access rights</param> /// <param name="overwritearchvie">Whether to overwrite an already existing archive</param> /// <returns>PublisherActionResult with specific ActionResultType and message</returns> public static PublisherActionResult ArchiveFilePreCheck(string filepath, string archivepath, CurrentUserSecurity currentusersecurity, bool overwritearchvie) { if (archivepath == null || String.IsNullOrEmpty(archivepath)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"Zip path ({archivepath}) is invalid!" )); } else if (!File.Exists(filepath)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.WithWarnings, $"File ({filepath}) does not exist (nothing has been archived)!" )); } else if (!currentusersecurity.HasAccess(new FileInfo(filepath), FileSystemRights.Read)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"No read access to the source file ({filepath})!" )); } else if (File.Exists(archivepath) && !overwritearchvie) { return(new PublisherActionResult( PublisherTypes.ActionResultType.WithWarnings, $"Zip archive ({archivepath}) already exists!" )); } else if (!currentusersecurity.HasAccess(new DirectoryInfo(Path.GetDirectoryName(archivepath)), FileSystemRights.Write)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"No write access to target path ({archivepath})!" )); } else { return(new PublisherActionResult( PublisherTypes.ActionResultType.Successful, $"Pre Check Succesful!" )); } }
/// <summary> /// Returns error specific PublisherTypes.ActionResultType.Failed or PublisherTypes.ActionResultType.WithWarnings /// type PublisherActionResults in case parameters are incorrect, or ActionResultType.Successful if they are correct /// </summary> /// <param name="directorypath">Path of the directory to be archived</param> /// <param name="currentusersecurity">CurrentUserSecurity object used to check access rights</param> /// <param name="archivepath">path of the archive file</param> /// <param name="overwritearchive">Whether to overwrite an already existing archive</param> /// <returns>PublisherActionResult with specific ActionResultType and message</returns> public static PublisherActionResult ArchivedirectoryPreCheck(string directorypath, CurrentUserSecurity currentusersecurity, string archivepath, bool overwritearchive) { if (String.IsNullOrEmpty(archivepath)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"Zip archive path ({archivepath}) is not valid!" )); } else if (File.Exists(archivepath) && !overwritearchive) { return(new PublisherActionResult( PublisherTypes.ActionResultType.WithWarnings, $"Zip archive ({archivepath}) already exists!" )); } else if (!currentusersecurity.HasAccess(new DirectoryInfo(directorypath), FileSystemRights.Read)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"No read access to the source directory ({directorypath})!" )); } else if (!currentusersecurity.HasAccess(new DirectoryInfo(Path.GetDirectoryName(archivepath)), FileSystemRights.Write)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"No write access to the archive target path ({archivepath})!" )); } else { return(new PublisherActionResult( PublisherTypes.ActionResultType.Successful, $"Pre Check Succesful!" )); } }
/// <summary> /// Returns error specific PublisherTypes.ActionResultType.Failed or PublisherTypes.ActionResultType.WithWarnings /// type PublisherActionResults in case parameters are incorrect, or ActionResultType.Successful if they are correct /// </summary> /// <param name="directorypath">Path of the directory to create</param> /// <param name="existingancestor">Path to last existing ancestor</param> /// <param name="currentusersecurity">CurrentUserSecurity object used to check access rights</param> /// <returns>PublisherActionResult with specific ActionResultType and message</returns> private static PublisherActionResult CreateDirectoryPreCheck(string directorypath, string existingancestor, CurrentUserSecurity currentusersecurity) { if (existingancestor == null) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"Could not determine root directory for ({directorypath})!" )); } else if (String.IsNullOrEmpty(directorypath)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"Target directory path ({directorypath}) was invalid!" )); } else if (!currentusersecurity.HasAccess(new DirectoryInfo(existingancestor), FileSystemRights.Write)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.Failed, $"No write access to the target directory ({existingancestor})!" )); } else if (Directory.Exists(directorypath)) { return(new PublisherActionResult( PublisherTypes.ActionResultType.WithWarnings, $"Directory ({directorypath}) already exists!" )); } else { return(new PublisherActionResult( PublisherTypes.ActionResultType.Successful, $"Pre Check Succesful!" )); } }