public DoGetFilesAsPerTypeOperation(IActivityIOPath path, ReadTypes type) { _logOnProvider = new LogonProvider(); _fileWrapper = new FileWrapper(); _dirWrapper = new DirectoryWrapper(); _path = path; _type = type; ImpersonatedUser = ValidateAuthorization.RequiresAuth(_path, _logOnProvider); _newPath = AppendBackSlashes(_path, _fileWrapper, _dirWrapper); }
public DoGetFilesAsPerTypeOperation(IActivityIOPath path, ReadTypes type, IDev2LogonProvider dev2LogonProvider, IFile file, IDirectory directory, ImpersonationDelegate impersonationDelegate) : base(impersonationDelegate) { _logOnProvider = dev2LogonProvider; _fileWrapper = file; _dirWrapper = directory; _path = path; _type = type; _impersonatedUser = _impersonationDelegate(_path, _logOnProvider); _newPath = AppendBackSlashes(_path, _fileWrapper, _dirWrapper); }
public IList <IActivityIOPath> ListDirectory(IActivityIOOperationsEndPoint src, ReadTypes readTypes) { return(_implementation.ListDirectory(src, readTypes)); }
public static IEnumerable <string> GetDirectoriesForType(string path, string pattern, ReadTypes type, IDirectory dirWrapper) { if (string.IsNullOrEmpty(pattern)) { switch (type) { case ReadTypes.Files: return(dirWrapper.EnumerateFiles(path)); case ReadTypes.Folders: return(dirWrapper.EnumerateDirectories(path)); default: return(dirWrapper.EnumerateFileSystemEntries(path)); } } switch (type) { case ReadTypes.Files: return(dirWrapper.EnumerateFiles(path, pattern)); case ReadTypes.Folders: return(dirWrapper.EnumerateDirectories(path, pattern)); default: return(dirWrapper.EnumerateFileSystemEntries(path, pattern)); } }
public IList <IActivityIOPath> ListDirectory(IActivityIOOperationsEndPoint src, ReadTypes readTypes) { if (readTypes == ReadTypes.FilesAndFolders) { return(src.ListDirectory(src.IOPath)); } return(readTypes == ReadTypes.Files ? src.ListFilesInDirectory(src.IOPath) : src.ListFoldersInDirectory(src.IOPath)); }
public DoGetFilesAsPerTypeOperation(IActivityIOPath path, ReadTypes type) : this(path, type, new LogonProvider(), new FileWrapper(), new DirectoryWrapper(), ValidateAuthorization.RequiresAuth) { }
public IList<IActivityIOPath> ListDirectory(IActivityIOOperationsEndPoint src, ReadTypes readTypes) { if(readTypes == ReadTypes.FilesAndFolders) { return src.ListDirectory(src.IOPath); } return readTypes == ReadTypes.Files ? src.ListFilesInDirectory(src.IOPath) : src.ListFoldersInDirectory(src.IOPath); }
private static IEnumerable <string> GetDirectoriesForType(string path, string pattern, ReadTypes type) { if (type == ReadTypes.Files) { if (string.IsNullOrEmpty(pattern)) { return(Directory.EnumerateFiles(path)); } return(Directory.EnumerateFiles(path, pattern)); } if (type == ReadTypes.Folders) { if (string.IsNullOrEmpty(pattern)) { return(Directory.EnumerateDirectories(path)); } return(Directory.EnumerateDirectories(path, pattern)); } if (string.IsNullOrEmpty(pattern)) { return(Directory.EnumerateFileSystemEntries(path)); } return(Directory.EnumerateFileSystemEntries(path, pattern)); }
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); }
private static IEnumerable<string> GetDirectoriesForType(string path, string pattern, ReadTypes type) { if (type == ReadTypes.Files) { if (string.IsNullOrEmpty(pattern)) { return Directory.EnumerateFiles(path); } return Directory.EnumerateFiles(path, pattern); } if (type == ReadTypes.Folders) { if (string.IsNullOrEmpty(pattern)) { return Directory.EnumerateDirectories(path); } return Directory.EnumerateDirectories(path, pattern); } if (string.IsNullOrEmpty(pattern)) { return Directory.EnumerateFileSystemEntries(path); } return Directory.EnumerateFileSystemEntries(path, pattern); }
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("The Directory does not exist."); } } 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("Directory not found [ " + 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("Directory not found [ " + src.Path + " ] "); } // remove impersonation now impersonatedUser.Undo(); newID.Dispose(); } } } else { // login failed throw new Exception("Failed to authenticate with user [ " + src.Username + " ] for resource [ " + src.Path + " ] "); } } catch (Exception ex) { Dev2Logger.Log.Error(ex); throw; } } return result; }
public IList <IActivityIOPath> ListDirectory(IActivityIOOperationsEndPoint src, ReadTypes readTypes) { throw new NotImplementedException(); }
public IList<IActivityIOPath> ListDirectory(IActivityIOOperationsEndPoint src,ReadTypes readTypes) { throw new NotImplementedException(); }
public static CremaDataSet ReadFromDirectory(string path, string filterExpression, ReadTypes readType) { var filter = new CremaDataSetFilter(); if (filterExpression is not null) { filter.Tables = StringUtility.Split(filterExpression, ';'); } if (readType == ReadTypes.OmitContent) { filter.OmitContent = true; } else if (readType == ReadTypes.TypeOnly) { filter.OmitTable = true; } return(ReadFromDirectory(path, filter)); }