/// <summary> /// Check directory /// </summary> /// <param name="fullPath"></param> /// <param name="directoryItemSide"></param> /// <returns>True if fullpath have value and directory exists, else throw exception</returns> private bool CheckDirectory(string fullPath, DirectoryItemSide directoryItemSide) { //Check fullpath have value if (fullPath == "") { throw new CustomException(String.Format(Messages.DirectoryWithoutValue, directoryItemSide == DirectoryItemSide.First ? Messages.TheFirst: Messages.TheSecond)); } //Check folder exists if (!Directory.Exists(fullPath)) { throw new CustomException(String.Format(Messages.DirectoryDoesNotExists, directoryItemSide == DirectoryItemSide.First ? Messages.TheFirst : Messages.TheSecond)); } return(true); }
/// <summary> /// Get Directories /// </summary> /// <param name="items"></param> /// <param name="fullPath"></param> /// <param name="side"></param> /// <returns>Get Directories List</returns> private List <CompareDirectoryItem> GetDirectoriesList(GetDirectories getDirectories, string fullPath, DirectoryItemSide side, DirectoryItemType directoryItemType) { // Create empty list var items = new List <CompareDirectoryItem>(); // Try and get directories from the dir // ignoring any issues doing so try { var dirs = getDirectories(fullPath, "*.*", SearchOption.AllDirectories); if (dirs.Length > 0) { items.AddRange(dirs.Select(dir => new CompareDirectoryItem { FirstDirectoryItem = (side == DirectoryItemSide.First ? new DirectoryFileItem() { FullPath = dir, Name = dir.Substring(fullPath.Length), Type = directoryItemType } : null), SecondDirectoryItem = (side == DirectoryItemSide.Second ? new DirectoryFileItem() { FullPath = dir, Name = dir.Substring(fullPath.Length), Type = directoryItemType } : null), ComparableValue = dir.Substring(fullPath.Length), Type = directoryItemType })); } } catch (Exception ex) { throw new CustomException(String.Format(Messages.DirectoryException, side == DirectoryItemSide.First ? Messages.TheFirst : Messages.TheSecond, ex.Message)); } return(items); }