public void BreadcrumbHelperTest_ExampleBreadcrumb() { var breadcrumb = Breadcrumbs.BreadcrumbHelper("/test/file.jpg"); Assert.AreEqual("/", breadcrumb.FirstOrDefault()); Assert.AreEqual("/test", breadcrumb.LastOrDefault()); }
public async Task AddParentItemsAsync(string subPath) { var path = subPath == "/" || string.IsNullOrEmpty(subPath) ? "/" : PathHelper.RemoveLatestSlash(subPath); var pathListShouldExist = Breadcrumbs.BreadcrumbHelper(path).ToList(); var toAddList = new List <FileIndexItem>(); var indexItems = _fakeContext .Where(p => pathListShouldExist.Any(f => f == p.FilePath)).ToList(); // ReSharper disable once ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator foreach (var pathShouldExist in pathListShouldExist) { if (!indexItems.Select(p => p.FilePath).Contains(pathShouldExist)) { toAddList.Add(new FileIndexItem(pathShouldExist) { IsDirectory = true, AddToDatabase = DateTime.UtcNow, ColorClass = ColorClassParser.Color.None }); } } await AddRangeAsync(toAddList); }
public void BreadcrumbNullTest() { var breadcrumbExample = Breadcrumbs.BreadcrumbHelper(null); var breadcrumblist = new List <string>(); CollectionAssert.AreEqual(breadcrumbExample, breadcrumblist); }
/// <summary> /// Makes a list of containing: the root folder, subfolders to create on the ftp service /// make the 1000 and 500 dirs on ftp /// </summary> /// <param name="parentDirectory"></param> /// <param name="slug"></param> /// <param name="copyContent"></param> /// <returns></returns> internal IEnumerable <string> CreateListOfRemoteDirectories(string parentDirectory, string slug, Dictionary <string, bool> copyContent) { var pushDirectory = _webFtpNoLogin + "/" + slug; var createThisDirectories = new List <string> { _webFtpNoLogin, // <= the base dir pushDirectory // <= current log item }; // ReSharper disable once LoopCanBeConvertedToQuery foreach (var copyItem in copyContent.Where(p => p.Value)) { var parentItems = Breadcrumbs.BreadcrumbHelper(copyItem.Key); foreach (var item in parentItems.Where(p => p != Path.DirectorySeparatorChar.ToString())) { if (_storage.ExistFolder(parentDirectory + item)) { createThisDirectories.Add(pushDirectory + "/" + item); } } } return(new HashSet <string>(createThisDirectories).ToList()); }
private string GetErrorLogItemFullPath(string subPath) { return(Breadcrumbs.BreadcrumbHelper(subPath).LastOrDefault() + "/" + "_" + Path.GetFileNameWithoutExtension(PathHelper.GetFileName(subPath)) + ".log"); }
public void BreadcrumbFileNameMethodTest() { var breadcrumbExample = Breadcrumbs.BreadcrumbHelper("/2018/2.jpg"); var breadcrumblist = new List <string> { "/", "/2018" }; CollectionAssert.AreEqual(breadcrumbExample, breadcrumblist); }
public void BreadcrumbNoInputTest() { var breadcrumbExample = Breadcrumbs.BreadcrumbHelper(string.Empty); var breadcrumblist = new List <string> { "/" }; CollectionAssert.AreEqual(breadcrumbExample, breadcrumblist); }
public void BreadcrumbSlashMethodTest() { var breadcrumbExample = Breadcrumbs.BreadcrumbHelper("/"); var breadcrumblist = new List <string> { "/" }; CollectionAssert.AreEqual(breadcrumbExample, breadcrumblist); }
private async Task FromFileToFolder(string inputFileSubPath, string toFileSubPath, List <FileIndexItem> fileIndexResultsList, List <FileIndexItem> fileIndexItems, DetailView detailView) { // you can't move the file to the same location if (inputFileSubPath == toFileSubPath) { fileIndexResultsList.Add(new FileIndexItem { Status = FileIndexItem.ExifStatus.OperationNotSupported }); return; //next } // when renaming a folder it should warn the UI that it should remove the source item fileIndexResultsList.Add(new FileIndexItem(inputFileSubPath) { Status = FileIndexItem.ExifStatus.NotFoundSourceMissing }); // from/input cache should be cleared var inputParentSubFolder = Breadcrumbs.BreadcrumbHelper(inputFileSubPath).LastOrDefault(); _query.RemoveCacheParentItem(inputParentSubFolder); // clear cache // parentSubFolder (to FileSubPath parents) var toParentSubFolder = Breadcrumbs.BreadcrumbHelper(toFileSubPath).LastOrDefault(); _query.RemoveCacheParentItem(toParentSubFolder); // Check if the parent folder exist in the database // parentSubFolder await _query.AddParentItemsAsync(toParentSubFolder); await SaveToDatabaseAsync(fileIndexItems, fileIndexResultsList, detailView, toFileSubPath); // First update database and then update for diskwatcher _iStorage.FileMove(inputFileSubPath, toFileSubPath); MoveSidecarFile(inputFileSubPath, toFileSubPath); }
/// <summary> /// fileIndexItemsList, Create an detailView object /// </summary> /// <param name="fileIndexItemsList">list of fileIndexItems</param> /// <param name="singleItemDbPath">database style path</param> /// <param name="colorClassActiveList">list of colorClasses to show, default show all</param> /// <param name="enableCollections">enable collections feature > default true</param> /// <param name="hideDeleted">do not show deleted files > default true</param> /// <returns>view object to show on the page</returns> public DetailView SingleItem( List <FileIndexItem> fileIndexItemsList, string singleItemDbPath, List <ColorClassParser.Color> colorClassActiveList = null, bool enableCollections = true, bool hideDeleted = true, SortType sort = SortType.FileName) { // reject empty requests if (string.IsNullOrWhiteSpace(singleItemDbPath)) { return(null); } var parentFolder = FilenamesHelper.GetParentPath(singleItemDbPath); // RemoveLatestSlash is for '/' folder var fileName = singleItemDbPath.Replace( PathHelper.RemoveLatestSlash(parentFolder) + "/", string.Empty); // Home has no parent, so return a value if (fileName == string.Empty && parentFolder == "/" && GetObjectByFilePath("/") != null) { return(new DetailView { FileIndexItem = GetObjectByFilePath("/"), RelativeObjects = new RelativeObjects(), Breadcrumb = new List <string> { "/" }, ColorClassActiveList = colorClassActiveList, IsDirectory = true, SubPath = "/", Collections = enableCollections }); } var currentFileIndexItem = fileIndexItemsList.FirstOrDefault(p => p.FileName == fileName); // Could be not found or not in directory cache if (currentFileIndexItem == null) { // retry currentFileIndexItem = GetObjectByFilePath(singleItemDbPath); if (currentFileIndexItem == null) { return(null); } AddCacheItem(currentFileIndexItem); } // To know when a file is deleted if (currentFileIndexItem.Tags.Contains("!delete!")) { currentFileIndexItem.Status = FileIndexItem.ExifStatus.Deleted; } if (currentFileIndexItem.IsDirectory == true) { currentFileIndexItem.CollectionPaths = new List <string> { singleItemDbPath }; return(new DetailView { IsDirectory = true, SubPath = singleItemDbPath, FileIndexItem = currentFileIndexItem, Collections = enableCollections, }); } if (currentFileIndexItem.Tags.Contains("!delete!")) { hideDeleted = false; } var fileIndexItemsForPrevNextList = DisplayFileFolders( parentFolder, colorClassActiveList, enableCollections, hideDeleted).ToList(); var itemResult = new DetailView { FileIndexItem = currentFileIndexItem, RelativeObjects = GetNextPrevInSubFolder(currentFileIndexItem, fileIndexItemsForPrevNextList, sort), Breadcrumb = Breadcrumbs.BreadcrumbHelper(singleItemDbPath), ColorClassActiveList = colorClassActiveList, IsDirectory = false, SubPath = singleItemDbPath, Collections = enableCollections }; // First item is current item var collectionPaths = new List <string> { singleItemDbPath }; collectionPaths.AddRange(fileIndexItemsList .Where(p => p.FileCollectionName == currentFileIndexItem.FileCollectionName) .Select(p => p.FilePath)); var collectionPathsHashSet = new HashSet <string>(collectionPaths); itemResult.FileIndexItem.CollectionPaths = collectionPathsHashSet.ToList(); return(itemResult); }
public void BreadcrumbHelperTest_WithoutStartSlash() { var breadcrumb = Breadcrumbs.BreadcrumbHelper("test"); Assert.AreEqual("/", breadcrumb.FirstOrDefault()); }
public IActionResult Index( string f = "/", string colorClass = null, bool collections = true, bool hidedelete = true, SortType sort = SortType.FileName ) { // Used in Detail and Index View => does not hide this single item var colorClassActiveList = FileIndexItem.GetColorClassList(colorClass); var subPath = PathHelper.PrefixDbSlash(f); subPath = PathHelper.RemoveLatestSlash(subPath); if (string.IsNullOrEmpty(subPath)) { subPath = "/"; } // First check if it is a single Item var singleItem = _query.SingleItem(subPath, colorClassActiveList, collections, hidedelete, sort); // returns no object when it a directory if (singleItem?.IsDirectory == false) { singleItem.IsReadOnly = _appSettings.IsReadOnly(singleItem.FileIndexItem.ParentDirectory); return(Json(singleItem)); } var fileIndexItems = SortHelper.Helper( _query.DisplayFileFolders(subPath, colorClassActiveList, collections, hidedelete), sort).ToList(); var fileIndexItemsWithoutCollections = _query.DisplayFileFolders( subPath, null, false, hidedelete).ToList(); // (singleItem.IsDirectory) or not found var directoryModel = new ArchiveViewModel { FileIndexItems = fileIndexItems, ColorClassActiveList = colorClassActiveList, RelativeObjects = _query.GetNextPrevInFolder(subPath), // Args are not shown in this view Breadcrumb = Breadcrumbs.BreadcrumbHelper(subPath), SearchQuery = subPath.Split("/").LastOrDefault(), SubPath = subPath, CollectionsCount = fileIndexItemsWithoutCollections. Count(p => p.IsDirectory == false), // when change colorclass selection you should see all options ColorClassUsage = fileIndexItemsWithoutCollections .Select(p => p.ColorClass).Distinct() .OrderBy(p => (int)(p)).ToList(), IsReadOnly = _appSettings.IsReadOnly(subPath), Collections = collections, }; if (singleItem == null) { // For showing a new database var queryIfFolder = _query.GetObjectByFilePath(subPath); // For showing a new database if (f == "/" && queryIfFolder == null) { return(Json(directoryModel)); } if (queryIfFolder == null) // used to have: singleItem?.FileIndexItem.FilePath == null && { Response.StatusCode = 404; return(Json("not found")); } } return(Json(directoryModel)); }