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); }
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 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); }
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); }