private static void SaveStartDocument(IFolderDao folderDao, IFileDao fileDao, object folderId, string path, IDataStore storeTemplate) { foreach (var file in storeTemplate.ListFilesRelative("", path, "*", false)) { SaveFile(fileDao, folderId, path + file, storeTemplate); } if (storeTemplate is S3Storage) { return; } foreach (var folderUri in storeTemplate.List(path, false)) { var folderName = Path.GetFileName(folderUri.ToString()); var subFolderId = folderDao.SaveFolder(new Folder { Title = folderName, ParentFolderID = folderId }); SaveStartDocument(folderDao, fileDao, subFolderId, path + folderName + "/", storeTemplate); } }
public DaoFactory(IFileDao fileDao, IFolderDao folderDao, ITagDao tagDao, ISecurityDao securityDao) { FileDao = fileDao; FolderDao = folderDao; TagDao = tagDao; SecurityDao = securityDao; }
public static void MoveSharedItems(object parentId, object toId, IFolderDao folderDao, IFileDao fileDao) { var fileSecurity = Global.GetFilesSecurity(); var folders = folderDao.GetFolders(parentId); foreach (var folder in folders) { var shared = folder.Shared && fileSecurity.GetShares(folder).Any(record => record.Share != FileShare.Restrict); if (shared) { Global.Logger.InfoFormat("Move shared folder {0} from {1} to {2}", folder.ID, parentId, toId); folderDao.MoveFolder(folder.ID, toId, null); } else { MoveSharedItems(folder.ID, toId, folderDao, fileDao); } } var files = fileDao.GetFiles(parentId, null, FilterType.None, false, Guid.Empty, string.Empty, true); foreach (var file in files.Where(file => file.Shared && fileSecurity.GetShares(file) .Any(record => record.Subject != FileConstant.ShareLinkId && record.Share != FileShare.Restrict))) { Global.Logger.InfoFormat("Move shared file {0} from {1} to {2}", file.ID, parentId, toId); fileDao.MoveFile(file.ID, toId); } }
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 new void TestFixtureSetUp() { try { FolderDao = DaoFactory.GetFolderDao(); } catch (TypeInitializationException exception) { throw exception.InnerException; } }
public FoldersModule( TenantManager tenantManager, UserManager userManager, WebItemSecurity webItemSecurity, FilesLinkUtility filesLinkUtility, FileSecurity fileSecurity, IDaoFactory daoFactory) : base(tenantManager, webItemSecurity) { UserManager = userManager; FilesLinkUtility = filesLinkUtility; FileSecurity = fileSecurity; FolderDao = daoFactory.GetFolderDao <int>(); }
public PlaylistController() { try { PlaylistDao = new PlaylistDao(); FolderDao = new FolderDao(); ShareCodeDao = new ShareCodeDao(); } catch (TypeInitializationException exception) { Logger.Error(exception.InnerException); throw exception.InnerException; } }
/// <summary> /// Initialize the AutoMapper mappings for the solution. /// http://automapper.codeplex.com/ /// </summary> public static void CreateAutoMapperMaps() { AutofacRegistrations.RegisterDaoFactory(); ILifetimeScope scope = AutofacRegistrations.Container.BeginLifetimeScope(); var daoFactory = scope.Resolve <IDaoFactory>(); Mapper.CreateMap <Error, ErrorDto>() .ReverseMap(); IPlaylistItemDao playlistItemDao = daoFactory.GetPlaylistItemDao(); IPlaylistDao playlistDao = daoFactory.GetPlaylistDao(); IFolderDao folderDao = daoFactory.GetFolderDao(); IUserDao userDao = daoFactory.GetUserDao(); Mapper.CreateMap <Playlist, PlaylistDto>() .ReverseMap() .ForMember(playlist => playlist.FirstItem, opt => opt.MapFrom(playlistDto => playlistItemDao.Get(playlistDto.FirstItemId))) .ForMember(playlist => playlist.NextPlaylist, opt => opt.MapFrom(playlistDto => playlistDao.Get(playlistDto.NextPlaylistId))) .ForMember(playlist => playlist.PreviousPlaylist, opt => opt.MapFrom(playlistDto => playlistDao.Get(playlistDto.PreviousPlaylistId))) .ForMember(playlist => playlist.Folder, opt => opt.MapFrom(playlistDto => folderDao.Get(playlistDto.FolderId))); Mapper.CreateMap <PlaylistItem, PlaylistItemDto>() .ReverseMap() .ForMember(playlistItem => playlistItem.NextItem, opt => opt.MapFrom(playlistItemDto => playlistItemDao.Get(playlistItemDto.NextItemId))) .ForMember(playlistItem => playlistItem.PreviousItem, opt => opt.MapFrom(playlistItemDto => playlistItemDao.Get(playlistItemDto.PreviousItemId))) .ForMember(playlistItem => playlistItem.Playlist, opt => opt.MapFrom(playlistItemDto => playlistDao.Get(playlistItemDto.PlaylistId))); Mapper.CreateMap <ShareCode, ShareCodeDto>().ReverseMap(); Mapper.CreateMap <Folder, FolderDto>() .ReverseMap() .ForMember(folder => folder.FirstPlaylist, opt => opt.MapFrom(folderDto => playlistDao.Get(folderDto.FirstPlaylistId))) .ForMember(folder => folder.User, opt => opt.MapFrom(folderDto => userDao.Get(folderDto.UserId))); Mapper.CreateMap <User, UserDto>().ReverseMap(); Mapper.CreateMap <Video, VideoDto>().ReverseMap(); Mapper.AssertConfigurationIsValid(); }
new ConcurrentDictionary <string, object>(); /*Use SYNCHRONIZED for cross thread blocks*/ public object GetFolderTrash(IFolderDao folderDao) { if (IsOutsider) { return(null); } var cacheKey = string.Format("trash/{0}/{1}", TenantManager.GetCurrentTenant().TenantId, AuthContext.CurrentAccount.ID); if (!TrashFolderCache.TryGetValue(cacheKey, out var trashFolderId)) { trashFolderId = AuthContext.IsAuthenticated ? folderDao.GetFolderIDTrash(true) : 0; TrashFolderCache[cacheKey] = trashFolderId; } return(trashFolderId); }
//Long operation public static void DeleteSubitems(object parentId, IFolderDao folderDao, IFileDao fileDao) { var folders = folderDao.GetFolders(parentId); foreach (var folder in folders) { DeleteSubitems(folder.ID, folderDao, fileDao); folderDao.DeleteFolder(folder.ID); } var files = fileDao.GetFiles(parentId, null, FilterType.None, Guid.Empty, string.Empty); foreach (var file in files) { fileDao.DeleteFile(file.ID); } }
private static void SaveStartDocument(IFolderDao folderDao, IFileDao fileDao, object folderId, string path, IDataStore storeTemplate) { foreach (var file in storeTemplate.ListFilesRelative("", path, "*", false)) { SaveFile(fileDao, folderId, path + file, storeTemplate); } foreach (var folderName in storeTemplate.ListDirectoriesRelative(path, false)) { var subFolderId = folderDao.SaveFolder(new Folder { Title = folderName, ParentFolderID = folderId }); SaveStartDocument(folderDao, fileDao, subFolderId, path + folderName + "/", storeTemplate); } }
private void SaveStartDocument(FileMarker fileMarker, IFolderDao folderDao, IFileDao fileDao, object folderId, string path, IDataStore storeTemplate) { foreach (var file in storeTemplate.ListFilesRelative("", path, "*", false)) { SaveFile(fileMarker, fileDao, folderId, path + file, storeTemplate); } foreach (var folderName in storeTemplate.ListDirectoriesRelative(path, false)) { var folder = ServiceProvider.GetService <Folder>(); folder.Title = folderName; folder.ParentFolderID = folderId; var subFolderId = folderDao.SaveFolder(folder); SaveStartDocument(fileMarker, folderDao, fileDao, subFolderId, path + folderName + "/", storeTemplate); } }
private static void SaveStartDocument(IFolderDao folderDao, IFileDao fileDao, object folderId, string path, IDataStore storeTemp) { foreach (var file in storeTemp.ListFilesRelative("", path, "*", false)) { SaveFile(fileDao, folderId, path + file, storeTemp); } foreach (var folderUri in storeTemp.List(path, false)) { var folderName = Path.GetFileName(folderUri.ToString()); var subFolderid = folderDao.SaveFolder(new Folder { Title = ReplaceInvalidCharsAndTruncate(folderName), ParentFolderID = folderId }); SaveStartDocument(folderDao, fileDao, subFolderid, path + folderName + "/", storeTemp); } }
public DropboxFolderDao( IServiceProvider serviceProvider, UserManager userManager, TenantManager tenantManager, TenantUtil tenantUtil, DbContextManager <FilesDbContext> dbContextManager, SetupInfo setupInfo, IOptionsMonitor <ILog> monitor, FileUtility fileUtility, CrossDao crossDao, DropboxDaoSelector dropboxDaoSelector, IFileDao <int> fileDao, IFolderDao <int> folderDao) : base(serviceProvider, userManager, tenantManager, tenantUtil, dbContextManager, setupInfo, monitor, fileUtility) { CrossDao = crossDao; DropboxDaoSelector = dropboxDaoSelector; FileDao = fileDao; FolderDao = folderDao; }
//Long operation public static void DeleteSubitems(object parentId, IFolderDao folderDao, IFileDao fileDao) { var folders = folderDao.GetFolders(parentId); foreach (var folder in folders) { DeleteSubitems(folder.ID, folderDao, fileDao); Global.Logger.InfoFormat("Delete folder {0} in {1}", folder.ID, parentId); folderDao.DeleteFolder(folder.ID); } var files = fileDao.GetFiles(parentId, null, FilterType.None, false, Guid.Empty, string.Empty, true); foreach (var file in files) { Global.Logger.InfoFormat("Delete file {0} in {1}", file.ID, parentId); fileDao.DeleteFile(file.ID); } }
public GoogleDriveFolderDao( IServiceProvider serviceProvider, UserManager userManager, TenantManager tenantManager, TenantUtil tenantUtil, DbContextManager <FilesDbContext> dbContextManager, SetupInfo setupInfo, IOptionsMonitor <ILog> monitor, FileUtility fileUtility, CrossDao crossDao, GoogleDriveDaoSelector googleDriveDaoSelector, IFileDao <int> fileDao, IFolderDao <int> folderDao, TempPath tempPath ) : base(serviceProvider, userManager, tenantManager, tenantUtil, dbContextManager, setupInfo, monitor, fileUtility, tempPath) { CrossDao = crossDao; GoogleDriveDaoSelector = googleDriveDaoSelector; FileDao = fileDao; FolderDao = folderDao; }
new ConcurrentDictionary <int, object>(); /*Use SYNCHRONIZED for cross thread blocks*/ public object GetFolderShare(IFolderDao folderDao) { if (CoreBaseSettings.Personal) { return(null); } if (IsOutsider) { return(null); } if (!ShareFolderCache.TryGetValue(TenantManager.GetCurrentTenant().TenantId, out var sharedFolderId)) { sharedFolderId = folderDao.GetFolderIDShare(true); if (!sharedFolderId.Equals(0)) { ShareFolderCache[TenantManager.GetCurrentTenant().TenantId] = sharedFolderId; } } return(sharedFolderId); }
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> GetEntries(IFolderDao folderDao, IFileDao fileDao, Folder parent, int from, int count, FilterType filter, bool subjectGroup, Guid subjectId, String searchText, bool searchInContent, bool withSubfolders, OrderBy orderBy, out int total) { total = 0; if (parent == null) { throw new ArgumentNullException("parent", FilesCommonResource.ErrorMassage_FolderNotFound); } var fileSecurity = Global.GetFilesSecurity(); var entries = Enumerable.Empty <FileEntry>(); searchInContent = searchInContent && filter != FilterType.ByExtension && !Equals(parent.ID, Global.FolderTrash); if (parent.FolderType == FolderType.Projects && parent.ID.Equals(Global.FolderProjects)) { var apiServer = new ASC.Api.ApiServer(); var apiUrl = string.Format("{0}project/maxlastmodified.json", SetupInfo.WebApiBaseUrl); var responseBody = apiServer.GetApiResponse(apiUrl, "GET"); if (responseBody != null) { var responseApi = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(responseBody))); var projectLastModified = responseApi["response"].Value <String>(); const string projectLastModifiedCacheKey = "documents/projectFolders/projectLastModified"; if (HttpRuntime.Cache.Get(projectLastModifiedCacheKey) == null || !HttpRuntime.Cache.Get(projectLastModifiedCacheKey).Equals(projectLastModified)) { HttpRuntime.Cache.Remove(projectLastModifiedCacheKey); HttpRuntime.Cache.Insert(projectLastModifiedCacheKey, projectLastModified); } var projectListCacheKey = string.Format("documents/projectFolders/{0}", SecurityContext.CurrentAccount.ID); var folderIDProjectTitle = (Dictionary <object, KeyValuePair <int, string> >)HttpRuntime.Cache.Get(projectListCacheKey); if (folderIDProjectTitle == null) { apiUrl = string.Format("{0}project/filter.json?sortBy=title&sortOrder=ascending&status=open&fields=id,title,security,projectFolder", SetupInfo.WebApiBaseUrl); responseApi = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(apiServer.GetApiResponse(apiUrl, "GET")))); var responseData = responseApi["response"]; if (!(responseData is JArray)) { return(entries.ToList()); } folderIDProjectTitle = new Dictionary <object, KeyValuePair <int, string> >(); foreach (JObject projectInfo in responseData.Children()) { var projectID = projectInfo["id"].Value <int>(); var projectTitle = Global.ReplaceInvalidCharsAndTruncate(projectInfo["title"].Value <String>()); JToken projectSecurityJToken; if (projectInfo.TryGetValue("security", out projectSecurityJToken)) { var projectSecurity = projectInfo["security"].Value <JObject>(); JToken projectCanFileReadJToken; if (projectSecurity.TryGetValue("canReadFiles", out projectCanFileReadJToken)) { if (!projectSecurity["canReadFiles"].Value <bool>()) { continue; } } } int projectFolderID; JToken projectFolderIDjToken; if (projectInfo.TryGetValue("projectFolder", out projectFolderIDjToken)) { projectFolderID = projectFolderIDjToken.Value <int>(); } else { projectFolderID = (int)FilesIntegration.RegisterBunch("projects", "project", projectID.ToString()); } if (!folderIDProjectTitle.ContainsKey(projectFolderID)) { folderIDProjectTitle.Add(projectFolderID, new KeyValuePair <int, string>(projectID, projectTitle)); } AscCache.Default.Remove("documents/folders/" + projectFolderID); AscCache.Default.Insert("documents/folders/" + projectFolderID, projectTitle, TimeSpan.FromMinutes(30)); } HttpRuntime.Cache.Remove(projectListCacheKey); HttpRuntime.Cache.Insert(projectListCacheKey, folderIDProjectTitle, new CacheDependency(null, new[] { projectLastModifiedCacheKey }), Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(15)); } var rootKeys = folderIDProjectTitle.Keys.ToArray(); if (filter == FilterType.None || filter == FilterType.FoldersOnly) { var folders = folderDao.GetFolders(rootKeys, filter, subjectGroup, subjectId, searchText, withSubfolders, false); var emptyFilter = string.IsNullOrEmpty(searchText) && filter == FilterType.None && subjectId == Guid.Empty; if (!emptyFilter) { var projectFolderIds = folderIDProjectTitle .Where(projectFolder => string.IsNullOrEmpty(searchText) || (projectFolder.Value.Value ?? "").ToLower().Trim().Contains(searchText.ToLower().Trim())) .Select(projectFolder => projectFolder.Key); folders.RemoveAll(folder => rootKeys.Contains(folder.ID)); var projectFolders = folderDao.GetFolders(projectFolderIds.ToArray(), filter, subjectGroup, subjectId, null, false, false); folders.AddRange(projectFolders); } folders.ForEach(x => { x.Title = folderIDProjectTitle.ContainsKey(x.ID) ? folderIDProjectTitle[x.ID].Value : x.Title; x.FolderUrl = folderIDProjectTitle.ContainsKey(x.ID) ? PathProvider.GetFolderUrl(x, folderIDProjectTitle[x.ID].Key) : string.Empty; }); if (withSubfolders) { folders = fileSecurity.FilterRead(folders).ToList(); } entries = entries.Concat(folders); } if (filter != FilterType.FoldersOnly && withSubfolders) { var files = fileDao.GetFiles(rootKeys, filter, subjectGroup, subjectId, searchText, searchInContent).ToList(); files = fileSecurity.FilterRead(files).ToList(); entries = entries.Concat(files); } } parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder)f).TotalFiles : 1)); parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder)f).TotalSubFolders + 1 : 0)); } else if (parent.FolderType == FolderType.SHARE) { //share var shared = (IEnumerable <FileEntry>)fileSecurity.GetSharesForMe(filter, subjectGroup, subjectId, searchText, searchInContent, withSubfolders); entries = entries.Concat(shared); parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder)f).TotalFiles : 1)); parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f.FileEntryType == FileEntryType.Folder ? ((Folder)f).TotalSubFolders + 1 : 0)); } else { if (parent.FolderType == FolderType.TRASH) { withSubfolders = false; } var folders = folderDao.GetFolders(parent.ID, orderBy, filter, subjectGroup, subjectId, searchText, withSubfolders).Cast <FileEntry>(); folders = fileSecurity.FilterRead(folders); entries = entries.Concat(folders); var files = fileDao.GetFiles(parent.ID, orderBy, filter, subjectGroup, subjectId, searchText, searchInContent, withSubfolders).Cast <FileEntry>(); files = fileSecurity.FilterRead(files); entries = entries.Concat(files); if (filter == FilterType.None || filter == FilterType.FoldersOnly) { var folderList = GetThirpartyFolders(parent, searchText); var thirdPartyFolder = FilterEntries(folderList, filter, subjectGroup, subjectId, searchText, searchInContent); entries = entries.Concat(thirdPartyFolder); } } if (orderBy.SortedBy != SortedByType.New) { entries = SortEntries(entries, orderBy); total = entries.Count(); if (0 < from) { entries = entries.Skip(from); } if (0 < count) { entries = entries.Take(count); } } entries = FileMarker.SetTagsNew(folderDao, parent, entries); //sorting after marking if (orderBy.SortedBy == SortedByType.New) { entries = SortEntries(entries, orderBy); total = entries.Count(); if (0 < from) { entries = entries.Skip(from); } if (0 < count) { entries = entries.Take(count); } } SetFileStatus(entries.Where(r => r != null && r.ID != null && r.FileEntryType == FileEntryType.File).Select(r => r as File).ToList()); return(entries); }
public static IEnumerable <FileEntry> GetEntries(IFolderDao folderDao, Folder parent, FilterType filter, Guid subjectId, OrderBy orderBy, String searchText, int from, int count, out int total) { total = 0; if (parent == null) { throw new ArgumentNullException("parent", FilesCommonResource.ErrorMassage_FolderNotFound); } var fileSecurity = Global.GetFilesSecurity(); var entries = Enumerable.Empty <FileEntry>(); if (parent.FolderType == FolderType.Projects && parent.ID.Equals(Global.FolderProjects)) { var apiServer = new ASC.Api.ApiServer(); var apiUrl = String.Format("{0}project/maxlastmodified.json", SetupInfo.WebApiBaseUrl); var responseApi = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(apiServer.GetApiResponse(apiUrl, "GET")))); var projectLastModified = responseApi["response"].Value <String>(); const string projectLastModifiedCacheKey = "documents/projectFolders/projectLastModified"; if (HttpRuntime.Cache.Get(projectLastModifiedCacheKey) == null || !HttpRuntime.Cache.Get(projectLastModifiedCacheKey).Equals(projectLastModified)) { HttpRuntime.Cache.Insert(projectLastModifiedCacheKey, projectLastModified); } var projectListCacheKey = String.Format("documents/projectFolders/{0}", SecurityContext.CurrentAccount.ID); var fromCache = HttpRuntime.Cache.Get(projectListCacheKey); if (fromCache == null) { apiUrl = String.Format("{0}project/filter.json?sortBy=title&sortOrder=ascending", SetupInfo.WebApiBaseUrl); responseApi = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(apiServer.GetApiResponse(apiUrl, "GET")))); var responseData = responseApi["response"]; if (!(responseData is JArray)) { return(entries.ToList()); } var folderIDProjectTitle = new Dictionary <object, String>(); foreach (JObject projectInfo in responseData.Children()) { var projectID = projectInfo["id"].Value <String>(); var projectTitle = Global.ReplaceInvalidCharsAndTruncate(projectInfo["title"].Value <String>()); int projectFolderID; JToken projectSecurityJToken; if (projectInfo.TryGetValue("security", out projectSecurityJToken)) { var projectSecurity = projectInfo["security"].Value <JObject>(); JToken projectCanFileReadJToken; if (projectSecurity.TryGetValue("canReadFiles", out projectCanFileReadJToken)) { if (!projectSecurity["canReadFiles"].Value <bool>()) { continue; } } } JToken projectFolderIDJToken; if (projectInfo.TryGetValue("projectFolder", out projectFolderIDJToken)) { projectFolderID = projectInfo["projectFolder"].Value <int>(); } else { projectFolderID = (int)FilesIntegration.RegisterBunch("projects", "project", projectID); } if (!folderIDProjectTitle.ContainsKey(projectFolderID)) { folderIDProjectTitle.Add(projectFolderID, projectTitle); } HttpRuntime.Cache.Insert("documents/folders/" + projectFolderID.ToString(), projectTitle, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(30)); } var folders = folderDao.GetFolders(folderIDProjectTitle.Keys.ToArray()); folders.ForEach(x => { x.Title = folderIDProjectTitle[x.ID]; x.Access = FileShare.ReadWrite; x.FolderUrl = PathProvider.GetFolderUrl(x); }); entries = entries.Concat(folders); if (entries.Any()) { HttpRuntime.Cache.Insert(projectListCacheKey, entries, new CacheDependency(null, new[] { projectLastModifiedCacheKey }), Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(15)); } } else { entries = entries.Concat((IEnumerable <FileEntry>)fromCache); } entries = FilterEntries(entries, filter, subjectId, searchText); parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalFiles : 1)); parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalSubFolders + 1 : 0)); } else if (parent.FolderType == FolderType.SHARE) { //share var shared = (IEnumerable <FileEntry>)fileSecurity.GetSharesForMe(); shared = FilterEntries(shared, filter, subjectId, searchText) .Where(f => f.CreateBy != SecurityContext.CurrentAccount.ID && // don't show my files f.RootFolderType == FolderType.USER); // don't show common files (common files can read) entries = entries.Concat(shared); parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalFiles : 1)); parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalSubFolders + 1 : 0)); } else { var folders = folderDao.GetFolders(parent.ID, orderBy, filter, subjectId, searchText).Cast <FileEntry>(); folders = fileSecurity.FilterRead(folders); entries = entries.Concat(folders); var files = folderDao.GetFiles(parent.ID, orderBy, filter, subjectId, searchText).Cast <FileEntry>(); files = fileSecurity.FilterRead(files); entries = entries.Concat(files); if ((parent.ID.Equals(Global.FolderMy) || parent.ID.Equals(Global.FolderCommon)) && ImportConfiguration.SupportInclusion && !CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor() && (Global.IsAdministrator || CoreContext.Configuration.Personal || FilesSettings.EnableThirdParty)) { using (var securityDao = Global.DaoFactory.GetSecurityDao()) using (var providerDao = Global.DaoFactory.GetProviderDao()) { var providers = providerDao.GetProvidersInfo(parent.RootFolderType); var folderList = providers .Select(providerInfo => //Fake folder. Don't send request to third party new Folder { ID = providerInfo.RootFolderId, ParentFolderID = parent.ID, CreateBy = providerInfo.Owner, CreateOn = providerInfo.CreateOn, FolderType = FolderType.DEFAULT, ModifiedBy = providerInfo.Owner, ModifiedOn = providerInfo.CreateOn, ProviderId = providerInfo.ID, ProviderKey = providerInfo.ProviderKey, RootFolderCreator = providerInfo.Owner, RootFolderId = providerInfo.RootFolderId, RootFolderType = providerInfo.RootFolderType, Shareable = false, Title = providerInfo.CustomerTitle, TotalFiles = 0, TotalSubFolders = 0 } ) .Where(fileSecurity.CanRead).ToList(); if (folderList.Any()) { securityDao.GetPureShareRecords(folderList.Cast <FileEntry>().ToArray()) .Where(x => x.Owner == SecurityContext.CurrentAccount.ID) .Select(x => x.EntryId).Distinct().ToList() .ForEach(id => { folderList.First(y => y.ID.Equals(id)).SharedByMe = true; }); } var thirdPartyFolder = FilterEntries(folderList, filter, subjectId, searchText); entries = entries.Concat(thirdPartyFolder); } } } if (orderBy.SortedBy != SortedByType.New) { entries = SortEntries(entries, orderBy); total = entries.Count(); if (0 < from) { entries = entries.Skip(from); } if (0 < count) { entries = entries.Take(count); } } entries = FileMarker.SetTagsNew(folderDao, parent, entries); SetFileStatus(entries.Select(r => r as File).Where(r => r != null && r.ID != null)); //sorting after marking if (orderBy.SortedBy == SortedByType.New) { entries = SortEntries(entries, orderBy); total = entries.Count(); if (0 < from) { entries = entries.Skip(from); } if (0 < count) { entries = entries.Take(count); } } return(entries); }
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; }
private static void SaveStartDocument(IFolderDao folderDao, IFileDao fileDao, object folderId, string path, IDataStore storeTemp) { foreach (var file in storeTemp.ListFilesRelative("", path, "*", false)) { SaveFile(fileDao, folderId, path + file, storeTemp); } if (storeTemp is S3Storage) return; foreach (var folderUri in storeTemp.List(path, false)) { var folderName = Path.GetFileName(folderUri.ToString()); var subFolder = folderDao.SaveFolder(new Folder { Title = folderName, ParentFolderID = folderId }); SaveStartDocument(folderDao, fileDao, subFolder.ID, path + folderName + "/", storeTemp); } }
public FolderManager() { FolderDao = DaoFactory.GetFolderDao(); }
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> GetEntries(IFolderDao folderDao, IFileDao fileDao, Folder parent, FilterType filter, Guid subjectId, OrderBy orderBy, String searchText, int from, int count, out int total) { total = 0; if (parent == null) { throw new ArgumentNullException("parent", FilesCommonResource.ErrorMassage_FolderNotFound); } var fileSecurity = Global.GetFilesSecurity(); var entries = Enumerable.Empty <FileEntry>(); if (parent.FolderType == FolderType.Projects && parent.ID.Equals(Global.FolderProjects)) { var apiServer = new ASC.Api.ApiServer(); var apiUrl = String.Format("{0}project/maxlastmodified.json", SetupInfo.WebApiBaseUrl); var responseBody = apiServer.GetApiResponse(apiUrl, "GET"); if (responseBody != null) { var responseApi = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(responseBody))); var projectLastModified = responseApi["response"].Value <String>(); const string projectLastModifiedCacheKey = "documents/projectFolders/projectLastModified"; if (HttpRuntime.Cache.Get(projectLastModifiedCacheKey) == null || !HttpRuntime.Cache.Get(projectLastModifiedCacheKey).Equals(projectLastModified)) { HttpRuntime.Cache.Remove(projectLastModifiedCacheKey); HttpRuntime.Cache.Insert(projectLastModifiedCacheKey, projectLastModified); } var projectListCacheKey = String.Format("documents/projectFolders/{0}", SecurityContext.CurrentAccount.ID); var fromCache = HttpRuntime.Cache.Get(projectListCacheKey); if (fromCache == null || !string.IsNullOrEmpty(searchText)) { apiUrl = String.Format("{0}project/filter.json?sortBy=title&sortOrder=ascending&status=open", SetupInfo.WebApiBaseUrl); responseApi = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(apiServer.GetApiResponse(apiUrl, "GET")))); var responseData = responseApi["response"]; if (!(responseData is JArray)) { return(entries.ToList()); } var folderIDProjectTitle = new Dictionary <object, String>(); foreach (JObject projectInfo in responseData.Children()) { var projectID = projectInfo["id"].Value <String>(); var projectTitle = Global.ReplaceInvalidCharsAndTruncate(projectInfo["title"].Value <String>()); int projectFolderID; JToken projectSecurityJToken; if (projectInfo.TryGetValue("security", out projectSecurityJToken)) { var projectSecurity = projectInfo["security"].Value <JObject>(); JToken projectCanFileReadJToken; if (projectSecurity.TryGetValue("canReadFiles", out projectCanFileReadJToken)) { if (!projectSecurity["canReadFiles"].Value <bool>()) { continue; } } } JToken projectFolderIDJToken; if (projectInfo.TryGetValue("projectFolder", out projectFolderIDJToken)) { projectFolderID = projectInfo["projectFolder"].Value <int>(); } else { projectFolderID = (int)FilesIntegration.RegisterBunch("projects", "project", projectID); } if (!folderIDProjectTitle.ContainsKey(projectFolderID)) { folderIDProjectTitle.Add(projectFolderID, projectTitle); } HttpRuntime.Cache.Remove("documents/folders/" + projectFolderID.ToString()); HttpRuntime.Cache.Insert("documents/folders/" + projectFolderID.ToString(), projectTitle, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(30)); } var folders = folderDao.GetFolders(folderIDProjectTitle.Keys.ToArray(), searchText, !string.IsNullOrEmpty(searchText)); folders.ForEach(x => { x.Title = folderIDProjectTitle.ContainsKey(x.ID) ? folderIDProjectTitle[x.ID] : x.Title; x.FolderUrl = PathProvider.GetFolderUrl(x); }); folders = fileSecurity.FilterRead(folders).ToList(); entries = entries.Concat(folders); if (!string.IsNullOrEmpty(searchText)) { var files = fileDao.GetFiles(folderIDProjectTitle.Keys.ToArray(), searchText, !string.IsNullOrEmpty(searchText)).ToList(); files = fileSecurity.FilterRead(files).ToList(); entries = entries.Concat(files); } if (entries.Any() && string.IsNullOrEmpty(searchText)) { HttpRuntime.Cache.Remove(projectListCacheKey); HttpRuntime.Cache.Insert(projectListCacheKey, entries, new CacheDependency(null, new[] { projectLastModifiedCacheKey }), Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(15)); } } else { entries = entries.Concat((IEnumerable <FileEntry>)fromCache); } } entries = FilterEntries(entries, filter, subjectId, searchText); parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalFiles : 1)); parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalSubFolders + 1 : 0)); } else if (parent.FolderType == FolderType.SHARE) { //share var shared = (IEnumerable <FileEntry>)fileSecurity.GetSharesForMe(searchText, !string.IsNullOrEmpty(searchText)); if (CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor()) { shared = shared.Where(r => !r.ProviderEntry); } shared = FilterEntries(shared, filter, subjectId, searchText) .Where(f => f.CreateBy != SecurityContext.CurrentAccount.ID && // don't show my files f.RootFolderType == FolderType.USER); // don't show common files (common files can read) entries = entries.Concat(shared); parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalFiles : 1)); parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalSubFolders + 1 : 0)); } else { var folders = folderDao.GetFolders(parent.ID, orderBy, filter, subjectId, searchText, !string.IsNullOrEmpty(searchText) && parent.FolderType != FolderType.TRASH).Cast <FileEntry>(); folders = fileSecurity.FilterRead(folders); entries = entries.Concat(folders); //TODO:Optimize var files = fileDao.GetFiles(parent.ID, orderBy, filter, subjectId, searchText, !string.IsNullOrEmpty(searchText) && parent.FolderType != FolderType.TRASH).Cast <FileEntry>(); files = fileSecurity.FilterRead(files); entries = entries.Concat(files); if (filter == FilterType.None || filter == FilterType.FoldersOnly) { var folderList = GetThirpartyFolders(parent, searchText); var thirdPartyFolder = FilterEntries(folderList, filter, subjectId, searchText); entries = entries.Concat(thirdPartyFolder); } } if (orderBy.SortedBy != SortedByType.New) { entries = SortEntries(entries, orderBy); total = entries.Count(); if (0 < from) { entries = entries.Skip(from); } if (0 < count) { entries = entries.Take(count); } } entries = FileMarker.SetTagsNew(folderDao, parent, entries); //sorting after marking if (orderBy.SortedBy == SortedByType.New) { entries = SortEntries(entries, orderBy); total = entries.Count(); if (0 < from) { entries = entries.Skip(from); } if (0 < count) { entries = entries.Take(count); } } SetFileStatus(entries.Select(r => r as File).Where(r => r != null && r.ID != null)); return(entries); }
public static void ReassignItems(object parentId, Guid fromUserId, Guid toUserId, IFolderDao folderDao, IFileDao fileDao) { var fileIds = fileDao.GetFiles(parentId, new OrderBy(SortedByType.AZ, true), FilterType.ByUser, false, fromUserId, null, true, true) .Where(file => file.CreateBy == fromUserId).Select(file => file.ID); fileDao.ReassignFiles(fileIds.ToArray(), toUserId); var folderIds = folderDao.GetFolders(parentId, new OrderBy(SortedByType.AZ, true), FilterType.ByUser, false, fromUserId, null, true) .Where(folder => folder.CreateBy == fromUserId).Select(folder => folder.ID); folderDao.ReassignFolders(folderIds.ToArray(), toUserId); }
public static IEnumerable<FileEntry> GetEntries(IFolderDao folderDao, Folder parent, FilterType filter, Guid subjectId, OrderBy orderBy, String searchText, int from, int count, out int total) { total = 0; if (parent == null) throw new ArgumentNullException(FilesCommonResource.ErrorMassage_FolderNotFound); var fileSecurity = Global.GetFilesSecurity(); var entries = Enumerable.Empty<FileEntry>(); if (parent.FolderType == FolderType.Projects && parent.ID.Equals(Global.FolderProjects)) { var apiServer = new ASC.Api.ApiServer(); var apiUrl = String.Format("{0}project/maxlastmodified.json", SetupInfo.WebApiBaseUrl); var responseApi = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(apiServer.GetApiResponse(apiUrl, "GET")))); var projectLastModified = responseApi["response"].Value<String>(); const string projectLastModifiedCacheKey = "documents/projectFolders/projectLastModified"; if (HttpRuntime.Cache.Get(projectLastModifiedCacheKey) == null || !HttpRuntime.Cache.Get(projectLastModifiedCacheKey).Equals(projectLastModified)) HttpRuntime.Cache.Insert(projectLastModifiedCacheKey, projectLastModified); var projectListCacheKey = String.Format("documents/projectFolders/{0}", SecurityContext.CurrentAccount.ID); var fromCache = HttpRuntime.Cache.Get(projectListCacheKey); if (fromCache == null) { apiUrl = String.Format("{0}project/filter.json?sortBy=title&sortOrder=ascending", SetupInfo.WebApiBaseUrl); responseApi = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(apiServer.GetApiResponse(apiUrl, "GET")))); var responseData = responseApi["response"]; if (!(responseData is JArray)) return entries.ToList(); var folderIDProjectTitle = new Dictionary<object, String>(); foreach (JObject projectInfo in responseData.Children()) { var projectID = projectInfo["id"].Value<String>(); var projectTitle = Global.ReplaceInvalidCharsAndTruncate(projectInfo["title"].Value<String>()); int projectFolderID; JToken projectSecurityJToken; if (projectInfo.TryGetValue("security", out projectSecurityJToken)) { var projectSecurity = projectInfo["security"].Value<JObject>(); JToken projectCanFileReadJToken; if (projectSecurity.TryGetValue("canReadFiles", out projectCanFileReadJToken)) { if (!projectSecurity["canReadFiles"].Value<bool>()) { continue; } } } JToken projectFolderIDJToken; if (projectInfo.TryGetValue("projectFolder", out projectFolderIDJToken)) projectFolderID = projectInfo["projectFolder"].Value<int>(); else projectFolderID = (int)FilesIntegration.RegisterBunch("projects", "project", projectID); if (!folderIDProjectTitle.ContainsKey(projectFolderID)) folderIDProjectTitle.Add(projectFolderID, projectTitle); HttpRuntime.Cache.Insert("documents/folders/" + projectFolderID.ToString(), projectTitle, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(30)); } var folders = folderDao.GetFolders(folderIDProjectTitle.Keys.ToArray()); folders.ForEach(x => { x.Title = folderIDProjectTitle[x.ID]; x.Access = FileShare.Read; x.FolderUrl = PathProvider.GetFolderUrl(x); }); entries = entries.Concat(folders); if (entries.Any()) HttpRuntime.Cache.Insert(projectListCacheKey, entries, new CacheDependency(null, new[] { projectLastModifiedCacheKey }), Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(15)); } else { entries = entries.Concat((IEnumerable<FileEntry>)fromCache); } entries = FilterEntries(entries, filter, subjectId, searchText); parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalFiles : 1)); parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalSubFolders + 1 : 0)); } else if (parent.FolderType == FolderType.SHARE) { //share var shared = (IEnumerable<FileEntry>)fileSecurity.GetSharesForMe(); shared = FilterEntries(shared, filter, subjectId, searchText) .Where(f => f.CreateBy != SecurityContext.CurrentAccount.ID && // don't show my files f.RootFolderType == FolderType.USER); // don't show common files (common files can read) entries = entries.Concat(shared); parent.TotalFiles = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalFiles : 1)); parent.TotalSubFolders = entries.Aggregate(0, (a, f) => a + (f is Folder ? ((Folder)f).TotalSubFolders + 1 : 0)); } else { var folders = folderDao.GetFolders(parent.ID, orderBy, filter, subjectId, searchText).Cast<FileEntry>(); folders = fileSecurity.FilterRead(folders); entries = entries.Concat(folders); var files = folderDao.GetFiles(parent.ID, orderBy, filter, subjectId, searchText).Cast<FileEntry>(); files = fileSecurity.FilterRead(files); entries = entries.Concat(files); if (ImportConfiguration.SupportInclusion && (parent.ID.Equals(Global.FolderMy) || parent.ID.Equals(Global.FolderCommon))) { using (var securityDao = Global.DaoFactory.GetSecurityDao()) using (var providerDao = Global.DaoFactory.GetProviderDao()) { var providers = providerDao.GetProvidersInfo(parent.RootFolderType); var folderList = providers .Select(providerInfo => //Fake folder. Don't send request to third party new Folder { ID = providerInfo.RootFolderId, ParentFolderID = parent.ID, CreateBy = providerInfo.Owner, CreateOn = providerInfo.CreateOn, FolderType = FolderType.DEFAULT, ModifiedBy = providerInfo.Owner, ModifiedOn = providerInfo.CreateOn, ProviderId = providerInfo.ID, ProviderKey = providerInfo.ProviderKey, RootFolderCreator = providerInfo.Owner, RootFolderId = providerInfo.RootFolderId, RootFolderType = providerInfo.RootFolderType, Shareable = false, Title = providerInfo.CustomerTitle, TotalFiles = 0, TotalSubFolders = 0 } ) .Where(fileSecurity.CanRead).ToList(); if (folderList.Any()) securityDao.GetPureShareRecords(folderList.Cast<FileEntry>().ToArray()) .Where(x => x.Owner == SecurityContext.CurrentAccount.ID) .Select(x => x.EntryId).Distinct().ToList() .ForEach(id => { folderList.First(y => y.ID.Equals(id)).SharedByMe = true; }); var thirdPartyFolder = FilterEntries(folderList, filter, subjectId, searchText); entries = entries.Concat(thirdPartyFolder); } } } if (orderBy.SortedBy != SortedByType.New) { entries = SortEntries(entries, orderBy); total = entries.Count(); if (0 < from) entries = entries.Skip(from); if (0 < count) entries = entries.Take(count); } entries = FileMarker.SetTagsNew(folderDao, parent, entries); //sorting after marking if (orderBy.SortedBy == SortedByType.New) { entries = SortEntries(entries, orderBy); total = entries.Count(); if (0 < from) entries = entries.Skip(from); if (0 < count) entries = entries.Take(count); } return entries; }
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 void ReassignItems(object parentId, Guid fromUserId, Guid toUserId, IFolderDao folderDao, IFileDao fileDao) { var files = fileDao.GetFiles(parentId, new OrderBy(SortedByType.AZ, true), FilterType.ByUser, fromUserId, null, withSubfolders: true) .Where(file => file.CreateBy == fromUserId); foreach (var file in files) { file.CreateBy = toUserId; fileDao.SaveFile(file, null); } var folders = folderDao.GetFolders(parentId, new OrderBy(SortedByType.AZ, true), FilterType.ByUser, fromUserId, null, true) .Where(folder => folder.CreateBy == fromUserId); foreach (var folder in folders) { folder.CreateBy = toUserId; folderDao.SaveFolder(folder); } }