public static List <Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao) { if (folderId == null) { return(new List <Folder>()); } var breadCrumbs = Global.GetFilesSecurity().FilterRead(folderDao.GetParentFolders(folderId)).ToList(); var firstVisible = breadCrumbs.ElementAtOrDefault(0); object rootId = null; if (firstVisible == null) { rootId = Global.FolderShare; } else { switch (firstVisible.FolderType) { case FolderType.DEFAULT: if (!firstVisible.ProviderEntry) { rootId = Global.FolderShare; } else { switch (firstVisible.RootFolderType) { case FolderType.USER: rootId = SecurityContext.CurrentAccount.ID == firstVisible.RootFolderCreator ? Global.FolderMy : Global.FolderShare; break; case FolderType.COMMON: rootId = Global.FolderCommon; break; } } break; case FolderType.BUNCH: rootId = Global.FolderProjects; break; } } if (rootId != null) { breadCrumbs.Insert(0, folderDao.GetFolder(rootId)); } return(breadCrumbs); }
public static List <Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao) { var breadCrumbs = GetFilesSecurity().FilterRead(folderDao.GetParentFolders(folderId)).ToList(); var firstVisible = breadCrumbs.ElementAtOrDefault(0); if (firstVisible != null && firstVisible.FolderType == FolderType.DEFAULT) //not first level { Folder root = null; if (string.IsNullOrEmpty(firstVisible.ProviderName)) { root = folderDao.GetFolder(folderDao.GetFolderIDShare(false)); } else { switch (firstVisible.RootFolderType) { case FolderType.USER: root = folderDao.GetFolder(folderDao.GetFolderIDUser(false)); break; case FolderType.COMMON: root = folderDao.GetFolder(folderDao.GetFolderIDCommon(false)); break; } } if (root != null) { firstVisible.ParentFolderID = root.ID; breadCrumbs.Insert(0, root); } } return(breadCrumbs); }
public static IEnumerable <FileEntry> SetTagsNew(IFolderDao folderDao, Folder parent, IEnumerable <FileEntry> entries) { using (var tagDao = Global.DaoFactory.GetTagDao()) { var totalTags = tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, parent, false).ToList(); if (totalTags.Any()) { var parentFolderTag = Equals(Global.FolderShare, parent.ID) ? tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, folderDao.GetFolder(Global.FolderShare)).FirstOrDefault() : totalTags.FirstOrDefault(tag => tag.EntryType == FileEntryType.Folder && Equals(tag.EntryId, parent.ID)); totalTags.Remove(parentFolderTag); var countSubNew = 0; totalTags.ForEach(tag => countSubNew += tag.Count); if (parentFolderTag == null) { parentFolderTag = Tag.New(SecurityContext.CurrentAccount.ID, parent, 0); parentFolderTag.Id = -1; } if (parentFolderTag.Count != countSubNew) { if (countSubNew > 0) { var diff = parentFolderTag.Count - countSubNew; parentFolderTag.Count -= diff; if (parentFolderTag.Id == -1) { tagDao.SaveTags(parentFolderTag); } else { tagDao.UpdateNewTags(parentFolderTag); } var cacheFolderId = parent.ID; var parentsList = folderDao.GetParentFolders(parent.ID); parentsList.Reverse(); parentsList.Remove(parent); if (parentsList.Any()) { var rootFolder = parentsList.Last(); object rootFolderId = null; cacheFolderId = rootFolder.ID; if (rootFolder.RootFolderType == FolderType.BUNCH) { cacheFolderId = rootFolderId = Global.FolderProjects; } else if (rootFolder.RootFolderType == FolderType.USER && !Equals(rootFolder.RootFolderId, Global.FolderMy)) { cacheFolderId = rootFolderId = Global.FolderShare; } if (rootFolderId != null) { parentsList.Add(folderDao.GetFolder(rootFolderId)); } var fileSecurity = Global.GetFilesSecurity(); foreach (var folderFromList in parentsList) { var parentTreeTag = tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, folderFromList).FirstOrDefault(); if (parentTreeTag == null) { if (fileSecurity.CanRead(folderFromList)) { tagDao.SaveTags(Tag.New(SecurityContext.CurrentAccount.ID, folderFromList, -diff)); } } else { parentTreeTag.Count -= diff; tagDao.UpdateNewTags(parentTreeTag); } } } if (cacheFolderId != null) { RemoveFromCahce(cacheFolderId); } } else { RemoveMarkAsNew(parent); } } entries.ToList().ForEach( entry => { var curTag = totalTags.FirstOrDefault(tag => tag.EntryType == entry.FileEntryType && tag.EntryId.Equals(entry.ID)); if (entry.FileEntryType == FileEntryType.Folder) { ((Folder)entry).NewForMe = curTag != null ? curTag.Count : 0; } else if (curTag != null) { entry.IsNew = true; } }); } } return(entries); }
public Folder <TTo> PerformCrossDaoFolderCopy <TFrom, TTo> (TFrom fromFolderId, IFolderDao <TFrom> fromFolderDao, IFileDao <TFrom> fromFileDao, Func <TFrom, TFrom> fromConverter, TTo toRootFolderId, IFolderDao <TTo> toFolderDao, IFileDao <TTo> toFileDao, Func <TTo, TTo> toConverter, bool deleteSourceFolder, CancellationToken?cancellationToken) { var fromFolder = fromFolderDao.GetFolder(fromConverter(fromFolderId)); var toFolder1 = ServiceProvider.GetService <Folder <TTo> >(); toFolder1.Title = fromFolder.Title; toFolder1.ParentFolderID = toConverter(toRootFolderId); var toFolder = toFolderDao.GetFolder(fromFolder.Title, toConverter(toRootFolderId)); var toFolderId = toFolder != null ? toFolder.ID : toFolderDao.SaveFolder(toFolder1); var foldersToCopy = fromFolderDao.GetFolders(fromConverter(fromFolderId)); var fileIdsToCopy = fromFileDao.GetFiles(fromConverter(fromFolderId)); Exception copyException = null; //Copy files first foreach (var fileId in fileIdsToCopy) { if (cancellationToken.HasValue) { cancellationToken.Value.ThrowIfCancellationRequested(); } try { PerformCrossDaoFileCopy(fileId, fromFileDao, fromConverter, toFolderId, toFileDao, toConverter, deleteSourceFolder); } catch (Exception ex) { copyException = ex; } } foreach (var folder in foldersToCopy) { if (cancellationToken.HasValue) { cancellationToken.Value.ThrowIfCancellationRequested(); } try { PerformCrossDaoFolderCopy(folder.ID, fromFolderDao, fromFileDao, fromConverter, toFolderId, toFolderDao, toFileDao, toConverter, deleteSourceFolder, cancellationToken); } catch (Exception ex) { copyException = ex; } } if (deleteSourceFolder) { var securityDao = ServiceProvider.GetService <SecurityDao <TFrom> >(); var fromFileShareRecords = securityDao.GetPureShareRecords(fromFolder) .Where(x => x.EntryType == FileEntryType.Folder); if (fromFileShareRecords.Any()) { fromFileShareRecords.ToList().ForEach(x => { x.EntryId = toFolderId; securityDao.SetShare(x); }); } var tagDao = ServiceProvider.GetService <TagDao <TFrom> >(); var fromFileNewTags = tagDao.GetNewTags(Guid.Empty, fromFolder).ToList(); if (fromFileNewTags.Any()) { fromFileNewTags.ForEach(x => x.EntryId = toFolderId); tagDao.SaveTags(fromFileNewTags); } if (copyException == null) { fromFolderDao.DeleteFolder(fromConverter(fromFolderId)); } } if (copyException != null) { throw copyException; } return(toFolderDao.GetFolder(toConverter(toFolderId))); }
public static IEnumerable<FileEntry> SetTagsNew(IFolderDao folderDao, Folder parent, IEnumerable<FileEntry> entries) { using (var tagDao = Global.DaoFactory.GetTagDao()) { var totalTags = tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, parent, false).ToList(); if (totalTags.Any()) { var parentFolderTag = Equals(Global.FolderShare, parent.ID) ? tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, folderDao.GetFolder(Global.FolderShare)).FirstOrDefault() : totalTags.FirstOrDefault(tag => tag.EntryType == FileEntryType.Folder && Equals(tag.EntryId, parent.ID)); totalTags.Remove(parentFolderTag); var countSubNew = 0; totalTags.ForEach(tag => countSubNew += tag.Count); if (parentFolderTag == null) { parentFolderTag = Tag.New(SecurityContext.CurrentAccount.ID, parent, 0); parentFolderTag.Id = -1; } if (parentFolderTag.Count != countSubNew) { if (countSubNew > 0) { var diff = parentFolderTag.Count - countSubNew; parentFolderTag.Count -= diff; if (parentFolderTag.Id == -1) { tagDao.SaveTags(parentFolderTag); } else { tagDao.UpdateNewTags(parentFolderTag); } var parentsList = folderDao.GetParentFolders(parent.ID); parentsList.Reverse(); parentsList.Remove(parent); if (parentsList.Any()) { var rootFolder = parentsList.Last(); if (rootFolder.RootFolderType == FolderType.BUNCH) parentsList.Add(folderDao.GetFolder(Global.FolderProjects)); else if (rootFolder.RootFolderType == FolderType.USER && !Equals(rootFolder.RootFolderId, Global.FolderMy)) parentsList.Add(folderDao.GetFolder(Global.FolderShare)); var fileSecurity = Global.GetFilesSecurity(); foreach (var folderFromList in parentsList) { var parentTreeTag = tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, new FileEntry[] { folderFromList }).FirstOrDefault(); if (parentTreeTag == null) { if (fileSecurity.CanRead(folderFromList)) { tagDao.SaveTags(Tag.New(SecurityContext.CurrentAccount.ID, folderFromList, -diff)); } } else { parentTreeTag.Count -= diff; tagDao.UpdateNewTags(parentTreeTag); } } } } else { RemoveMarkAsNew(parent); } } entries.ToList().ForEach( entry => { var folder = entry as Folder; if (folder != null) { var curTag = totalTags.FirstOrDefault(tag => tag.EntryType == FileEntryType.Folder && tag.EntryId.Equals(folder.ID)); folder.NewForMe = curTag != null ? curTag.Count : 0; } }); } } return entries; }
public static List<Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao) { var breadCrumbs = GetFilesSecurity().FilterRead(folderDao.GetParentFolders(folderId)).ToList(); var firstVisible = breadCrumbs.ElementAtOrDefault(0); if (firstVisible != null && firstVisible.FolderType == FolderType.DEFAULT) //not first level { Folder root = null; if (string.IsNullOrEmpty(firstVisible.ProviderName)) { root = folderDao.GetFolder(folderDao.GetFolderIDShare(false)); } else { switch (firstVisible.RootFolderType) { case FolderType.USER: root = folderDao.GetFolder(folderDao.GetFolderIDUser(false)); break; case FolderType.COMMON: root = folderDao.GetFolder(folderDao.GetFolderIDCommon(false)); break; } } if (root != null) { firstVisible.ParentFolderID = root.ID; breadCrumbs.Insert(0, root); } } return breadCrumbs; }
public static List<Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao) { var breadCrumbs = Global.GetFilesSecurity().FilterRead(folderDao.GetParentFolders(folderId)).ToList(); var firstVisible = breadCrumbs.ElementAtOrDefault(0); object rootId = null; if (firstVisible == null) { rootId = Global.FolderShare; } else { switch (firstVisible.FolderType) { case FolderType.DEFAULT: if (!firstVisible.ProviderEntry) { rootId = Global.FolderShare; } else { switch (firstVisible.RootFolderType) { case FolderType.USER: rootId = SecurityContext.CurrentAccount.ID == firstVisible.RootFolderCreator ? Global.FolderMy : Global.FolderShare; break; case FolderType.COMMON: rootId = Global.FolderCommon; break; } } break; case FolderType.BUNCH: rootId = Global.FolderProjects; break; } } if (rootId != null) { breadCrumbs.Insert(0, folderDao.GetFolder(rootId)); } return breadCrumbs; }