public enPathType PathIs(IActivityIOPath path) { var result = enPathType.File; if (path.Path.StartsWith("\\\\")) { if (Dev2ActivityIOPathUtils.IsDirectory(path.Path)) { result = enPathType.Directory; } } else { if (FileExist(path) || DirectoryExist(path)) { result = IsDirectory(path, result); } else { if (Dev2ActivityIOPathUtils.IsDirectory(path.Path)) { result = enPathType.Directory; } } } return(result); }
public string Zip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2ZipOperationTO args) { string status; try { status = ValidateZipSourceDestinationFileOperation(src, dst, args, () => { string tempFileName; if (src.PathIs(src.IOPath) == enPathType.Directory || Dev2ActivityIOPathUtils.IsStarWildCard(src.IOPath.Path)) { tempFileName = ZipDirectoryToALocalTempFile(src, args); } else { tempFileName = ZipFileToALocalTempFile(src, args); } return(TransferTempZipFileToDestination(src, dst, args, tempFileName)); }); } finally { _filesToDelete.ForEach(RemoveTmpFile); } return(status); }
bool PerformTransfer(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, string origDstPath, IActivityIOPath p, bool result) { try { if (dst.PathIs(dst.IOPath) == enPathType.Directory) { var cpPath = ActivityIOFactory.CreatePathFromString( $"{origDstPath}{dst.PathSeperator()}{Dev2ActivityIOPathUtils.ExtractFileName(p.Path)}", dst.IOPath.Username, dst.IOPath.Password, true, dst.IOPath.PrivateKeyFile); var path = cpPath.Path; DoFileTransfer(src, dst, args, cpPath, p, path, ref result); } else { if (args.Overwrite || !dst.PathExist(dst.IOPath)) { var tmp = origDstPath + @"\\" + Dev2ActivityIOPathUtils.ExtractFileName(p.Path); var path = ActivityIOFactory.CreatePathFromString(tmp, dst.IOPath.Username, dst.IOPath.Password, dst.IOPath.PrivateKeyFile); DoFileTransfer(src, dst, args, path, p, path.Path, ref result); } } } catch (Exception ex) { Dev2Logger.Error(ex, GlobalConstants.WarewolfError); } return(result); }
protected bool TransferDirectoryContents(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args) { if (!args.Overwrite) { ValidateSourceAndDestinationContents(src, dst, args); } if (args.DoRecursiveCopy) { RecursiveCopy(src, dst, args); } var srcContents = src.ListFilesInDirectory(src.IOPath); var result = true; var origDstPath = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(dst.IOPath.Path); if (!dst.PathExist(dst.IOPath)) { CreateDirectory(dst, args); } // TODO: cleanup this code so that result is easier to follow foreach (var p in srcContents) { result = PerformTransfer(src, dst, args, origDstPath, p, result); } Dev2Logger.Debug($"Transfered: {src.IOPath.Path}", GlobalConstants.WarewolfDebug); return(result); }
/// <summary> /// Return an IActivityIOPath based upont the path string /// </summary> /// <param name="path"></param> /// <returns></returns> public static IActivityIOPath CreatePathFromString(string path, string user, string pass, bool IsNotCertVerifiable) { // Fetch path type enActivityIOPathType type = Dev2ActivityIOPathUtils.ExtractPathType(path); if (type == enActivityIOPathType.Invalid) { // Default to file system type = enActivityIOPathType.FileSystem; } return(new Dev2ActivityIOPath(type, path, user, pass, IsNotCertVerifiable)); }
private static enPathType IsDirectory(IActivityIOPath path, enPathType result) { if (!Dev2ActivityIOPathUtils.IsStarWildCard(path.Path)) { var fa = File.GetAttributes(path.Path); if ((fa & FileAttributes.Directory) == FileAttributes.Directory) { result = enPathType.Directory; } } return(result); }
public static IActivityIOPath CreatePathFromString(string path, string user, string pass, bool isNotCertVerifiable, string privateKeyFile) { VerifyArgument.IsNotNull("path", path); var type = Dev2ActivityIOPathUtils.ExtractPathType(path); if (type == enActivityIOPathType.Invalid) { // Default to file system type = enActivityIOPathType.FileSystem; if (!Path.IsPathRooted(path)) { throw new IOException(ErrorResource.InvalidPath); } } return(new Dev2ActivityIOPath(type, path, user, pass, isNotCertVerifiable, privateKeyFile)); }
/// <summary> /// Return an IActivityIOPath based upont the path string /// </summary> /// <param name="path">The path.</param> /// <param name="user">The user.</param> /// <param name="pass">The pass.</param> /// <param name="isNotCertVerifiable">if set to <c>true</c> [is not cert verifiable].</param> /// <param name="privateKeyFile">If private key file is required. This is the path</param> /// <returns></returns> public static IActivityIOPath CreatePathFromString(string path, string user, string pass, bool isNotCertVerifiable, string privateKeyFile = "") { VerifyArgument.IsNotNull("path", path); // Fetch path type enActivityIOPathType type = Dev2ActivityIOPathUtils.ExtractPathType(path); if (type == enActivityIOPathType.Invalid) { // Default to file system type = enActivityIOPathType.FileSystem; if (!Path.IsPathRooted(path)) { throw new IOException("Invalid Path. Please insure that the path provided is an absolute path, if you intended to access the local file system."); } } return(new Dev2ActivityIOPath(type, path, user, pass, isNotCertVerifiable, privateKeyFile)); }
public string Zip(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2ZipOperationTO args) { string status; try { status = _validator.ValidateZipSourceDestinationFileOperation(src, dst, args, () => { string tempFileName; tempFileName = src.PathIs(src.IOPath) == enPathType.Directory || Dev2ActivityIOPathUtils.IsStarWildCard(src.IOPath.Path) ? _implementation.ZipDirectoryToALocalTempFile(src, args) : _implementation.ZipFileToALocalTempFile(src, args); return(_implementation.TransferTempZipFileToDestination(src, dst, args, tempFileName)); }); } finally { RemoveAllTmpFiles(); } return(status); }
string ValidateCopySourceDestinationFileOperation(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args, Func <string> performAfterValidation) { var result = ResultOk; _common.ValidateSourceAndDestinationPaths(src, dst); var opStatus = CreateEndPoint(dst, args, dst.PathIs(dst.IOPath) == enPathType.Directory); if (!opStatus.Equals("Success")) { throw new Exception(string.Format(ErrorResource.RecursiveDirectoryCreateFailed, dst.IOPath.Path)); } if (src.PathIs(src.IOPath) == enPathType.Directory) { if (!TransferDirectoryContents(src, dst, args)) { result = ResultBad; } } else { if (!args.Overwrite) { EnsureFilesDontExists(src, dst); } if (!Dev2ActivityIOPathUtils.IsStarWildCard(src.IOPath.Path)) { return(performAfterValidation?.Invoke()); } if (!TransferDirectoryContents(src, dst, args)) { result = ResultBad; } } return(result); }
public enPathType PathIs(IActivityIOPath path) { enPathType result = enPathType.File; if (path.Path.StartsWith("\\\\")) { if (Dev2ActivityIOPathUtils.IsDirectory(path.Path)) { result = enPathType.Directory; } } else { // && FileExist(path) if (FileExist(path) || DirectoryExist(path)) { if (!Dev2ActivityIOPathUtils.IsStarWildCard(path.Path)) { FileAttributes fa = File.GetAttributes(path.Path); if ((fa & FileAttributes.Directory) == FileAttributes.Directory) { result = enPathType.Directory; } } } else { if (Dev2ActivityIOPathUtils.IsDirectory(path.Path)) { result = enPathType.Directory; } } } return(result); }
/// <summary> /// Transfer the contents of the directory /// </summary> /// <param name="src"></param> /// <param name="dst"></param> /// <param name="args"></param> bool TransferDirectoryContents(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args) { ValidateSourceAndDestinationContents(src, dst, args); if (args.DoRecursiveCopy) { RecursiveCopy(src, dst, args); } var srcContents = src.ListFilesInDirectory(src.IOPath); var result = true; var origDstPath = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(dst.IOPath.Path); if (!dst.PathExist(dst.IOPath)) { CreateDirectory(dst, args); } foreach (var p in srcContents) { result = PerformTransfer(src, dst, args, origDstPath, p, result); } Dev2Logger.Debug($"Transfered: {src.IOPath.Path}"); return(result); }
private IList <IActivityIOPath> ListDirectoriesAccordingToType(IActivityIOPath src, ReadTypes type) { IList <IActivityIOPath> result = new List <IActivityIOPath>(); string path = src.Path; if (!path.EndsWith("\\") && PathIs(src) == enPathType.Directory) { path += "\\"; } if (!RequiresAuth(src)) { try { IEnumerable <string> dirs; if (!Dev2ActivityIOPathUtils.IsStarWildCard(path)) { if (Directory.Exists(path)) { dirs = GetDirectoriesForType(path, string.Empty, type); } else { throw new Exception(string.Format(ErrorResource.DirectoryDoesNotExist, path)); } } else { // we have a wild-char path ;) string baseDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(path); string pattern = Dev2ActivityIOPathUtils.ExtractFileName(path); dirs = GetDirectoriesForType(baseDir, pattern, type); } if (dirs != null) { foreach (string d in dirs) { result.Add(ActivityIOFactory.CreatePathFromString(d, src.Username, src.Password, true, src.PrivateKeyFile)); } } } catch (Exception) { throw new Exception(string.Format(ErrorResource.DirectoryNotFound, src.Path)); } } else { try { // handle UNC path SafeTokenHandle safeTokenHandle; bool loginOk = LogonUser(ExtractUserName(src), ExtractDomain(src), src.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle); if (loginOk) { using (safeTokenHandle) { WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle()); using (WindowsImpersonationContext impersonatedUser = newID.Impersonate()) { // Do the operation here try { IEnumerable <string> dirs; if (!Dev2ActivityIOPathUtils.IsStarWildCard(path)) { dirs = GetDirectoriesForType(path, string.Empty, type); } else { // we have a wild-char path ;) string baseDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(path); string pattern = Dev2ActivityIOPathUtils.ExtractFileName(path); dirs = GetDirectoriesForType(baseDir, pattern, type); } if (dirs != null) { foreach (string d in dirs) { result.Add(ActivityIOFactory.CreatePathFromString(d, src.Username, src.Password, src.PrivateKeyFile)); } } } catch (Exception) { throw new Exception(string.Format(ErrorResource.DirectoryNotFound, src.Path)); } // remove impersonation now impersonatedUser.Undo(); newID.Dispose(); } } } else { // login failed throw new Exception(string.Format(ErrorResource.FailedToAuthenticateUser, src.Username, src.Path)); } } catch (Exception ex) { Dev2Logger.Error(ex); throw; } } return(result); }