/// <summary> /// </summary> /// <param name="folder"></param> public FolderWrapper(Folder folder):base(folder) { ParentId = folder.ParentFolderID; FilesCount = folder.TotalFiles; FoldersCount = folder.TotalSubFolders; IsShareable = folder.Shareable; }
public Folder SaveFolder(Folder folder) { using (var dao = FilesIntegration.GetFolderDao()) { folder.ID = dao.SaveFolder(folder); return folder; } }
public IEnumerable<Tag> GetNewTags(Guid subject, Folder parentFolder, bool deepSearch) { using (var dbManager = new DbManager(FileConstant.DatabaseId)) { var folderId = SharePointDaoSelector.ConvertId(parentFolder.ID); var fakeFolderId = parentFolder.ID.ToString(); var entryIDs = dbManager.ExecuteList(Query("files_thirdparty_id_mapping") .Select("hash_id") .Where(Exp.Like("id", fakeFolderId, SqlLike.StartWith))) .ConvertAll(x => x[0]); if (!entryIDs.Any()) return new List<Tag>(); var sqlQuery = new SqlQuery("files_tag ft") .Select("ft.name", "ft.flag", "ft.owner", "ftl.entry_id", "ftl.entry_type", "ftl.tag_count", "ft.id") .Distinct() .LeftOuterJoin("files_tag_link ftl", Exp.EqColumns("ft.tenant_id", "ftl.tenant_id") & Exp.EqColumns("ft.id", "ftl.tag_id")) .Where(Exp.Eq("ft.tenant_id", TenantID) & Exp.Eq("ftl.tenant_id", TenantID) & Exp.Eq("ft.flag", (int) TagType.New) & Exp.In("ftl.entry_id", entryIDs)); if (subject != Guid.Empty) sqlQuery.Where(Exp.Eq("ft.owner", subject)); var tags = dbManager.ExecuteList(sqlQuery).ConvertAll(r => new Tag { TagName = Convert.ToString(r[0]), TagType = (TagType) r[1], Owner = new Guid(r[2].ToString()), EntryId = MappingID(r[3]), EntryType = (FileEntryType) r[4], Count = Convert.ToInt32(r[5]), Id = Convert.ToInt32(r[6]) }); if (deepSearch) return tags; var folderFileIds = new[] {fakeFolderId} .Concat(ProviderInfo.GetFolderFolders(folderId).Select(x => ProviderInfo.MakeId(x.ServerRelativeUrl))) .Concat(ProviderInfo.GetFolderFiles(folderId).Select(x => ProviderInfo.MakeId(x.ServerRelativeUrl))); return tags.Where(tag => folderFileIds.Contains(tag.EntryId.ToString())); } }
protected Folder ToFolder(Item onedriveFolder) { if (onedriveFolder == null) { return(null); } if (onedriveFolder is ErrorItem) { //Return error entry return(ToErrorFolder(onedriveFolder as ErrorItem)); } if (onedriveFolder.Folder == null) { return(null); } var isRoot = IsRoot(onedriveFolder); var folder = new Folder { ID = MakeId(isRoot ? string.Empty : onedriveFolder.Id), ParentFolderID = isRoot ? null : MakeId(GetParentFolderId(onedriveFolder)), CreateBy = OneDriveProviderInfo.Owner, CreateOn = isRoot ? OneDriveProviderInfo.CreateOn : (onedriveFolder.CreatedDateTime.HasValue ? TenantUtil.DateTimeFromUtc(onedriveFolder.CreatedDateTime.Value.DateTime) : default(DateTime)), FolderType = FolderType.DEFAULT, ModifiedBy = OneDriveProviderInfo.Owner, ModifiedOn = isRoot ? OneDriveProviderInfo.CreateOn : (onedriveFolder.LastModifiedDateTime.HasValue ? TenantUtil.DateTimeFromUtc(onedriveFolder.LastModifiedDateTime.Value.DateTime) : default(DateTime)), ProviderId = OneDriveProviderInfo.ID, ProviderKey = OneDriveProviderInfo.ProviderKey, RootFolderCreator = OneDriveProviderInfo.Owner, RootFolderId = MakeId(), RootFolderType = OneDriveProviderInfo.RootFolderType, Shareable = false, Title = MakeItemTitle(onedriveFolder), TotalFiles = 0, TotalSubFolders = 0 }; return(folder); }
/// <summary> /// </summary> /// <param name="folder"></param> public FolderWrapper(Folder folder) : base(folder) { ParentId = folder.ParentFolderID; if (folder.RootFolderType == FolderType.USER && !Equals(folder.RootFolderCreator, SecurityContext.CurrentAccount.ID)) { RootFolderType = FolderType.SHARE; using (var folderDao = Global.DaoFactory.GetFolderDao()) { var parentFolder = folderDao.GetFolder(folder.ParentFolderID); if (!Global.GetFilesSecurity().CanRead(parentFolder)) ParentId = Global.FolderShare; } } FilesCount = folder.TotalFiles; FoldersCount = folder.TotalSubFolders; IsShareable = folder.Shareable; }
public static String GetFolderUrl(Folder folder) { if (folder == null) throw new ArgumentNullException("folder", FilesCommonResource.ErrorMassage_FolderNotFound); using (var folderDao = Global.DaoFactory.GetFolderDao()) { switch (folder.RootFolderType) { case FolderType.BUNCH: var path = folderDao.GetBunchObjectID(folder.RootFolderId); var projectID = path.Split('/').Last(); if (String.IsNullOrEmpty(projectID)) return String.Empty; return String.Format("{0}?prjid={1}#{2}", CommonLinkUtility.ToAbsolute(ProjectVirtualPath), projectID, folder.ID); default: return FilesLinkUtility.FilesBaseAbsolutePath + "#" + HttpUtility.UrlPathEncode(folder.ID.ToString()); } } }
private static IEnumerable<FileEntry> GetEntries(Folder parent, FilterType filter, Guid subjectId, OrderBy orderBy, String searchText, int from, int count, out int total) { using (var folderDao = GetFolderDao()) { ErrorIf(parent == null, FilesCommonResource.ErrorMassage_FolderNotFound); var entries = Enumerable.Empty<FileEntry>(); 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 { try { 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); } catch (Exception ex) { ErrorIf(true, ex.Message); } if (ImportConfiguration.SupportInclusion && (parent.ID.Equals(Global.FolderMy) || parent.ID.Equals(Global.FolderCommon))) { using (var providerDao = 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, ProviderName = providerInfo.ProviderName, ProviderUserName = providerInfo.UserName, RootFolderCreator = providerInfo.Owner, RootFolderId = providerInfo.RootFolderId, RootFolderType = providerInfo.RootFolderType, Shareable = false, Title = providerInfo.CustomerTitle, TotalFiles = 0, TotalSubFolders = 0 } ) .Where(folder => FileSecurity.CanRead(folder)); var thirdPartyFolder = FilterEntries(folderList.Cast<FileEntry>(), filter, subjectId, searchText); entries = entries.Concat(thirdPartyFolder); parent.TotalFiles = thirdPartyFolder.Aggregate(parent.TotalFiles, (a, f) => a + (f is Folder ? ((Folder) f).TotalFiles : 1)); parent.TotalSubFolders = thirdPartyFolder.Aggregate(parent.TotalSubFolders, (a, f) => a + (f is Folder ? ((Folder) f).TotalSubFolders + 1 : 0)); } } } entries = SortEntries(entries, orderBy); total = entries.Count(); if (0 < from) entries = entries.Skip(from); if (0 < count) entries = entries.Take(count); return entries.ToList(); } }
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; }
private void MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy) { if (fileIds.Count == 0) return; var toFolderId = toFolder.ID; foreach (var fileId in fileIds) { if (Canceled) return; var file = FileDao.GetFile(fileId); if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!FilesSecurity.CanRead(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile; } else if (Global.EnableUploadFilter && !FileUtility.ExtsUploadable.Contains(FileUtility.GetFileExtension(file.Title))) { Error = FilesCommonResource.ErrorMassage_NotSupportedFormat; } else // if (!Equals(file.FolderID.ToString(), toFolderId.ToString()) || _resolveType == FileConflictResolveType.Duplicate) { var parentFolder = FolderDao.GetFolder(file.FolderID); try { var conflict = _resolveType == FileConflictResolveType.Duplicate ? null : FileDao.GetFile(toFolderId, file.Title); if (conflict != null && !FilesSecurity.CanEdit(conflict)) { Error = FilesCommonResource.ErrorMassage_SecurityException; } else if (conflict != null && EntryManager.FileLockedForMe(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (conflict == null) { if (copy) { File newFile = null; try { newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileCopied, file.Title, parentFolder.Title, toFolder.Title); if (Equals(newFile.FolderID.ToString(), _toFolderId)) { _needToMarkAsNew.Add(newFile); } if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFile.ID, SplitCharacter); ResultedFile(newFile.ID); } } catch { if (newFile != null) FileDao.DeleteFile(newFile.ID); throw; } } else { if (EntryManager.FileLockedForMe(file.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(file.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileMarker.RemoveMarkAsNewForAll(file); var newFileId = FileDao.MoveFile(file.ID, toFolderId); FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileMoved, file.Title, parentFolder.Title, toFolder.Title); if (Equals(toFolderId.ToString(), _toFolderId)) { _needToMarkAsNew.Add(FileDao.GetFile(newFileId)); } if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", newFileId, SplitCharacter); ResultedFile(newFileId); } } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } else { if (_resolveType == FileConflictResolveType.Overwrite) { if (EntryManager.FileLockedForMe(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(conflict.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else { conflict.Version++; using (var stream = FileDao.GetFileStream(file)) { conflict.ContentLength = stream.Length; conflict.Comment = string.Empty; conflict = FileDao.SaveFile(conflict, stream); _needToMarkAsNew.Add(conflict); } if (copy) { FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileCopiedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title); if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", conflict.ID, SplitCharacter); ResultedFile(conflict.ID); } } else { if (Equals(file.FolderID.ToString(), toFolderId.ToString())) { if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", conflict.ID, SplitCharacter); ResultedFile(conflict.ID); } } else { if (EntryManager.FileLockedForMe(file.ID)) { Error = FilesCommonResource.ErrorMassage_LockedFile; } else if (FileTracker.IsEditing(file.ID)) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileDao.DeleteFile(file.ID); FileDao.DeleteFolder(file.ID); FilesMessageService.Send(file, toFolder, httpRequestHeaders, MessageAction.FileMovedWithOverwriting, file.Title, parentFolder.Title, toFolder.Title); if (ProcessedFile(fileId)) { Status += string.Format("file_{0}{1}", conflict.ID, SplitCharacter); ResultedFile(conflict.ID); } } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } } } else if (_resolveType == FileConflictResolveType.Skip) { //nothing } } } catch(Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(); } }
public bool UseTrashForRemove(Folder folder) { var selector = GetSelector(folder.ID); return selector.GetFolderDao(folder.ID).UseTrashForRemove(folder); }
private Feed ToFeed(Folder folder) { var rootFolder = new FolderDao(Tenant, DbId).GetFolder(folder.ParentFolderID); if (folder.SharedToMeOn.HasValue) { var feed = new Feed(new Guid(folder.SharedToMeBy), folder.SharedToMeOn.Value, true) { Item = sharedFolderItem, ItemId = string.Format("{0}_{1}", folder.ID, folder.CreateByString), ItemUrl = CommonLinkUtility.GetFileRedirectPreviewUrl(folder.ID, false), Product = Product, Module = Name, Title = folder.Title, AdditionalInfo = rootFolder.FolderType == FolderType.DEFAULT ? rootFolder.Title : string.Empty, AdditionalInfo2 = rootFolder.FolderType == FolderType.DEFAULT ? CommonLinkUtility.GetFileRedirectPreviewUrl(folder.ParentFolderID, false) : string.Empty, Keywords = string.Format("{0}", folder.Title), HasPreview = false, CanComment = false, Target = folder.CreateByString, GroupId = GetGroupId(sharedFolderItem, new Guid(folder.SharedToMeBy), folder.ParentFolderID.ToString()) }; return feed; } return new Feed(folder.CreateBy, folder.CreateOn) { Item = folderItem, ItemId = folder.ID.ToString(), ItemUrl = CommonLinkUtility.GetFileRedirectPreviewUrl(folder.ID, false), Product = Product, Module = Name, Title = folder.Title, AdditionalInfo = rootFolder.FolderType == FolderType.DEFAULT ? rootFolder.Title : string.Empty, AdditionalInfo2 = rootFolder.FolderType == FolderType.DEFAULT ? CommonLinkUtility.GetFileRedirectPreviewUrl(folder.ParentFolderID, false) : string.Empty, Keywords = string.Format("{0}", folder.Title), HasPreview = false, CanComment = false, Target = null, GroupId = GetGroupId(folderItem, folder.CreateBy, folder.ParentFolderID.ToString()) }; }
public Folder SaveFolder(Folder folder) { if (folder.ID != null) { //Create with id var savedfolder = ProviderInfo.CreateFolder((string)folder.ID); return ProviderInfo.ToFolder(savedfolder); } if (folder.ParentFolderID != null) { var parentFolder = ProviderInfo.GetFolderById(folder.ParentFolderID); folder.Title = GetAvailableTitle(folder.Title, parentFolder, IsExist); var newFolder = ProviderInfo.CreateFolder(parentFolder.ServerRelativeUrl + "/" + folder.Title); return ProviderInfo.ToFolder(newFolder); } return null; }
protected Folder ToFolder(DriveFile driveEntry) { if (driveEntry == null) return null; if (driveEntry is ErrorDriveEntry) { //Return error entry return ToErrorFolder(driveEntry as ErrorDriveEntry); } if (driveEntry.MimeType != GoogleDriveStorage.GoogleFolderMimeType) { return null; } var isRoot = IsRoot(driveEntry); var folder = new Folder { ID = MakeId(driveEntry), ParentFolderID = isRoot ? null : MakeId(GetParentDriveId(driveEntry)), CreateBy = GoogleDriveProviderInfo.Owner, CreateOn = isRoot ? GoogleDriveProviderInfo.CreateOn : (driveEntry.CreatedDate.HasValue ? driveEntry.CreatedDate.Value : default(DateTime)), FolderType = FolderType.DEFAULT, ModifiedBy = GoogleDriveProviderInfo.Owner, ModifiedOn = isRoot ? GoogleDriveProviderInfo.CreateOn : (driveEntry.ModifiedDate.HasValue ? driveEntry.ModifiedDate.Value : default(DateTime)), ProviderId = GoogleDriveProviderInfo.ID, ProviderKey = GoogleDriveProviderInfo.ProviderKey, RootFolderCreator = GoogleDriveProviderInfo.Owner, RootFolderId = MakeId(), RootFolderType = GoogleDriveProviderInfo.RootFolderType, Shareable = false, Title = MakeFolderTitle(driveEntry), TotalFiles = 0, /*driveEntry.Count - childFoldersCount NOTE: Removed due to performance isssues*/ TotalSubFolders = 0, /*childFoldersCount NOTE: Removed due to performance isssues*/ }; if (folder.CreateOn != DateTime.MinValue && folder.CreateOn.Kind == DateTimeKind.Utc) folder.CreateOn = TenantUtil.DateTimeFromUtc(folder.CreateOn); if (folder.ModifiedOn != DateTime.MinValue && folder.ModifiedOn.Kind == DateTimeKind.Utc) folder.ModifiedOn = TenantUtil.DateTimeFromUtc(folder.ModifiedOn); return folder; }
protected Folder ToFolder(ICloudDirectoryEntry fsEntry) { if (fsEntry == null) return null; if (fsEntry is ErrorEntry) { //Return error entry return ToErrorFolder(fsEntry as ErrorEntry); } //var childFoldersCount = fsEntry.OfType<ICloudDirectoryEntry>().Count();//NOTE: Removed due to performance isssues var isRoot = IsRoot(fsEntry); var folder = new Folder { ID = MakeId(fsEntry), ParentFolderID = isRoot ? null : MakeId(fsEntry.Parent), CreateBy = SharpBoxProviderInfo.Owner, CreateOn = isRoot ? SharpBoxProviderInfo.CreateOn : fsEntry.Modified, FolderType = FolderType.DEFAULT, ModifiedBy = SharpBoxProviderInfo.Owner, ModifiedOn = isRoot ? SharpBoxProviderInfo.CreateOn : fsEntry.Modified, ProviderId = SharpBoxProviderInfo.ID, ProviderKey = SharpBoxProviderInfo.ProviderKey, RootFolderCreator = SharpBoxProviderInfo.Owner, RootFolderId = MakeId(RootFolder()), RootFolderType = SharpBoxProviderInfo.RootFolderType, Shareable = false, Title = MakeTitle(fsEntry), TotalFiles = 0, /*fsEntry.Count - childFoldersCount NOTE: Removed due to performance isssues*/ TotalSubFolders = 0, /*childFoldersCount NOTE: Removed due to performance isssues*/ }; if (folder.CreateOn != DateTime.MinValue && folder.CreateOn.Kind == DateTimeKind.Utc) folder.CreateOn = TenantUtil.DateTimeFromUtc(folder.CreateOn); if (folder.ModifiedOn != DateTime.MinValue && folder.ModifiedOn.Kind == DateTimeKind.Utc) folder.ModifiedOn = TenantUtil.DateTimeFromUtc(folder.ModifiedOn); return folder; }
private static File CreateFileFromUri(Folder folder, string fileUri, string fileTitle) { if (string.IsNullOrEmpty(fileTitle)) fileTitle = Path.GetFileName(HttpUtility.UrlDecode(fileUri)); var file = new File { Title = fileTitle, FolderID = folder.ID }; var req = (HttpWebRequest)WebRequest.Create(fileUri); using (var fileDao = Global.DaoFactory.GetFileDao()) using (var fileStream = new ResponseStream(req.GetResponse())) { file.ContentLength = fileStream.Length; return fileDao.SaveFile(file, fileStream); } }
private static File CreateFileFromTemplate(Folder folder, string template, string fileTitle, string docType) { var storeTemp = Global.GetStoreTemplate(); var lang = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).GetCulture().TwoLetterISOLanguageName; var fileExt = FileUtility.InternalExtension[FileType.Document]; if (!string.IsNullOrEmpty(docType)) { var tmpFileType = DocumentServiceParams.DocType.FirstOrDefault(r => r.Value.Equals(docType, StringComparison.OrdinalIgnoreCase)); string tmpFileExt; FileUtility.InternalExtension.TryGetValue(tmpFileType.Key, out tmpFileExt); if (!string.IsNullOrEmpty(tmpFileExt)) fileExt = tmpFileExt; } string templatePath; string templateName; if (string.IsNullOrEmpty(template)) { templateName = "new" + fileExt; templatePath = FileConstant.NewDocPath + lang + "/"; if (!storeTemp.IsDirectory(templatePath)) templatePath = FileConstant.NewDocPath + "default/"; templatePath += templateName; } else { templateName = template + fileExt; templatePath = FileConstant.TemplateDocPath + lang + "/"; if (!storeTemp.IsDirectory(templatePath)) templatePath = FileConstant.TemplateDocPath + "default/"; templatePath += templateName; if (!storeTemp.IsFile(templatePath)) { templatePath = FileConstant.TemplateDocPath + "default/"; templatePath += templateName; } } if (string.IsNullOrEmpty(fileTitle)) { fileTitle = templateName; } else { fileTitle = fileTitle + fileExt; } var file = new File { Title = fileTitle, ContentLength = storeTemp.GetFileSize(templatePath), FolderID = folder.ID }; file.ConvertedType = FileUtility.GetInternalExtension(file.Title); using (var fileDao = Global.DaoFactory.GetFileDao()) using (var stream = storeTemp.IronReadStream("", templatePath, 10)) { return fileDao.SaveFile(file, stream); } }
public object SaveFolder(Folder folder) { if (folder.ID != null) { return RenameFolder(folder.ID, folder.Title); } if (folder.ParentFolderID != null) { var driveFolderId = MakeDriveId(folder.ParentFolderID); var driveFolder = GoogleDriveProviderInfo.Storage.InsertEntry(null, folder.Title, driveFolderId, true); CacheInsert(driveFolder); var parentDriveId = GetParentDriveId(driveFolder); if (parentDriveId != null) CacheReset(parentDriveId, true); return MakeId(driveFolder); } return null; }
public static Folder SaveFolder(Folder folder) { return Engine.SaveFolder(folder); }
private void MoveOrCopyFolders(ICollection folderIds, Folder toFolder, bool copy) { if (folderIds.Count == 0) return; var toFolderId = toFolder.ID; var isToFolder = Equals(toFolderId.ToString(), _toFolderId); foreach (var folderId in folderIds) { if (Canceled) return; var folder = FolderDao.GetFolder(folderId); if (folder == null) { Error = FilesCommonResource.ErrorMassage_FolderNotFound; } else if (!FilesSecurity.CanRead(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder; } else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), toFolderId.ToString()) || _resolveType == FileConflictResolveType.Duplicate) { try { //if destination folder contains folder with same name then merge folders var conflictFolder = FolderDao.GetFolder(folder.Title, toFolderId); if (copy || conflictFolder != null) { Folder newFolder; if (conflictFolder != null) { newFolder = conflictFolder; if (isToFolder) _needToMarkAsNew.Add(conflictFolder); } else { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); FilesMessageService.Send(folder, toFolder, httpRequestHeaders, MessageAction.FolderCopied, folder.Title, toFolder.Title); if (isToFolder) _needToMarkAsNew.Add(newFolder); if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolder.ID, SplitCharacter); ResultedFolder(newFolder.ID); } } if (FolderDao.UseRecursiveOperation(folder.ID, toFolderId)) { MoveOrCopyFiles(FolderDao.GetFiles(folder.ID, false), newFolder, copy); MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy); if (!copy) { if (FolderDao.GetItemsCount(folder.ID, true) == 0 && FilesSecurity.CanDelete(folder)) { FolderDao.DeleteFolder(folder.ID); if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolder.ID, SplitCharacter); ResultedFolder(newFolder.ID); } } } } else { if (conflictFolder != null) { object newFolderId; if (copy) { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); newFolderId = newFolder.ID; FilesMessageService.Send(folder, toFolder, httpRequestHeaders, MessageAction.FolderCopiedWithOverwriting, folder.Title, toFolder.Title); if (isToFolder) _needToMarkAsNew.Add(newFolder); } else { newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId); FilesMessageService.Send(folder, toFolder, httpRequestHeaders, MessageAction.FolderMovedWithOverwriting, folder.Title, toFolder.Title); if (isToFolder) _needToMarkAsNew.Add(FolderDao.GetFolder(newFolderId)); } if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolderId, SplitCharacter); ResultedFolder(newFolderId); } } } } else { if (FilesSecurity.CanDelete(folder)) { FileMarker.RemoveMarkAsNewForAll(folder); var newFolderId = FolderDao.MoveFolder(folder.ID, toFolderId); FilesMessageService.Send(folder, toFolder, httpRequestHeaders, MessageAction.FolderMoved, folder.Title, toFolder.Title); if (isToFolder) _needToMarkAsNew.Add(FolderDao.GetFolder(newFolderId)); if (ProcessedFolder(folderId)) { Status += string.Format("folder_{0}{1}", newFolderId, SplitCharacter); ResultedFolder(newFolderId); } } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } } } catch(Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(); } }
private void MoveOrCopyFiles(ICollection fileIds, Folder toFolder, bool copy, FileConflictResolveType resolveType) { if (fileIds.Count == 0) return; var toFolderId = toFolder.ID; foreach (var fileId in fileIds) { if (Canceled) return; var file = FileDao.GetFile(fileId); if (file == null) { Error = FilesCommonResource.ErrorMassage_FileNotFound; } else if (!FilesSecurity.CanRead(file)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFile; } else if (Global.EnableUploadFilter && !Studio.Utility.FileUtility.ExtsUploadable.Contains(Studio.Utility.FileUtility.GetFileExtension(file.Title))) { Error = FilesCommonResource.ErrorMassage_NotSupportedFormat; } else if (!Equals(file.FolderID.ToString(), toFolderId)) { try { var conflict = FileDao.GetFile(toFolderId, file.Title); if (conflict != null && !FilesSecurity.CanEdit(conflict)) { Error = FilesCommonResource.ErrorMassage_SecurityException; } else if (conflict == null) { if (copy) { File newFile = null; try { newFile = FileDao.CopyFile(file.ID, toFolderId); //Stream copy will occur inside dao if (Equals(newFile.FolderID.ToString(), _toFolderId)) _needToMarkAsNew.Add(newFile); ProcessedFile(fileId); } catch { if (newFile != null) FileDao.DeleteFile(newFile.ID); throw; } } else { if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileMarker.RemoveMarkAsNewForAll(file); var newFileId = FileDao.MoveFile(file.ID, toFolderId); if (Equals(toFolderId.ToString(), _toFolderId)) _needToMarkAsNew.Add(FileDao.GetFile(newFileId)); ProcessedFile(fileId); } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } else { if (resolveType == FileConflictResolveType.Overwrite) { conflict.Version++; using (var stream = FileDao.GetFileStream(file)) { conflict.ContentLength = stream.Length; conflict = FileDao.SaveFile(conflict, stream); _needToMarkAsNew.Add(conflict); } if (copy) { ProcessedFile(fileId); } else { if ((file.FileStatus & FileStatus.IsEditing) == FileStatus.IsEditing) { Error = FilesCommonResource.ErrorMassage_SecurityException_UpdateEditingFile; } else if (FilesSecurity.CanDelete(file)) { FileDao.DeleteFile(file.ID); FileDao.DeleteFolder(file.ID); ProcessedFile(fileId); } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFile; } } } else if (resolveType == FileConflictResolveType.Skip) { //nothing } } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(); } }
public IEnumerable<Tag> GetNewTags(Guid subject, Folder parentFolder, bool deepSearch) { return GetSelector(parentFolder.ID).GetTagDao(parentFolder.ID).GetNewTags(subject, parentFolder, deepSearch); }
private void MoveOrCopyFolders(ICollection folderIds, Folder toFolder, bool copy) { if (folderIds.Count == 0) return; var toFolderId = toFolder.ID; var isToFolder = Equals(toFolderId.ToString(), _toFolderId); foreach (var folderId in folderIds) { if (Canceled) return; var folder = FolderDao.GetFolder(folderId); if (folder == null) { Error = FilesCommonResource.ErrorMassage_FolderNotFound; } else if (!FilesSecurity.CanRead(folder)) { Error = FilesCommonResource.ErrorMassage_SecurityException_ReadFolder; } else if (!Equals((folder.ParentFolderID ?? string.Empty).ToString(), toFolderId.ToString())) { try { //if destination folder contains folder with same name then merge folders var conflictFolder = FolderDao.GetFolder(folder.Title, toFolderId); if (copy || conflictFolder != null) { Folder newFolder; if (conflictFolder != null) { newFolder = conflictFolder; if (isToFolder) _needToMarkAsNew.Add(conflictFolder); } else { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); if (isToFolder) _needToMarkAsNew.Add(newFolder); ProcessedFolder(folderId); } if (FolderDao.UseRecursiveOperation(folder.ID, toFolderId)) { MoveOrCopyFiles(FolderDao.GetFiles(folder.ID, false), newFolder, copy, _resolveType); MoveOrCopyFolders(FolderDao.GetFolders(folder.ID).Select(f => f.ID).ToList(), newFolder, copy); if (!copy) { if (FolderDao.GetItemsCount(folder.ID, true) == 0 && FilesSecurity.CanDelete(folder)) { FolderDao.DeleteFolder(folder.ID); ProcessedFolder(folderId); } } } else { if (conflictFolder != null) { if (copy) { newFolder = FolderDao.CopyFolder(folder.ID, toFolderId); if (isToFolder) _needToMarkAsNew.Add(newFolder); } else { FolderDao.MoveFolder(folder.ID, toFolderId); if (isToFolder) _needToMarkAsNew.Add(FolderDao.GetFolder(folder.ID)); } ProcessedFolder(folderId); } } } else { if (FilesSecurity.CanDelete(folder)) { FileMarker.RemoveMarkAsNewForAll(folder); FolderDao.MoveFolder(folder.ID, toFolderId); if (isToFolder) _needToMarkAsNew.Add(FolderDao.GetFolder(folder.ID)); ProcessedFolder(folderId); } else { Error = FilesCommonResource.ErrorMassage_SecurityException_DeleteFolder; } } } catch (Exception ex) { Error = ex.Message; Logger.Error(Error, ex); } } ProgressStep(); } }
public object SaveFolder(Folder folder) { if (folder.ID != null) { //Create with id var savedfolder = SharpBoxProviderInfo.Storage.CreateFolder(MakePath(folder.ID)); return MakeId(savedfolder); } if (folder.ParentFolderID != null) { var parentFolder = GetFolderById(folder.ParentFolderID); folder.Title = GetAvailableTitle(folder.Title, parentFolder, IsExist); var newFolder = SharpBoxProviderInfo.Storage.CreateFolder(folder.Title, parentFolder); return MakeId(newFolder); } return null; }
private static Tuple<Folder, SmallShareRecord> ToFolder(object[] r) { var folder = new Folder { ID = Convert.ToInt32(r[0]), ParentFolderID = Convert.ToInt32(r[1]), Title = Convert.ToString(r[2]), CreateBy = new Guid(Convert.ToString(r[3])), CreateOn = Convert.ToDateTime(r[4]), ModifiedBy = new Guid(Convert.ToString(r[5])), ModifiedOn = Convert.ToDateTime(r[6]), TotalSubFolders = Convert.ToInt32(r[7]), TotalFiles = Convert.ToInt32(r[8]), RootFolderType = DocumentsDbHelper.ParseRootFolderType(r[9]), RootFolderCreator = DocumentsDbHelper.ParseRootFolderCreator(r[9]), RootFolderId = DocumentsDbHelper.ParseRootFolderId(r[9]) }; SmallShareRecord shareRecord = null; if (r[10] != null) { shareRecord = new SmallShareRecord { ShareOn = Convert.ToDateTime(r[10]), ShareBy = new Guid(Convert.ToString(r[11])), ShareTo = new Guid(Convert.ToString(r[12])) }; } return new Tuple<Folder, SmallShareRecord>(folder, shareRecord); }
public bool UseTrashForRemove(Folder folder) { return false; }
private object GetOrCreateHierarchy(string path, Folder root) { path = path != null ? path.Trim('/') : null; if (string.IsNullOrEmpty(path)) return root.ID; var pos = path.IndexOf("/"); var title = 0 < pos ? path.Substring(0, pos) : path; path = 0 < pos ? path.Substring(pos + 1) : null; title = Global.ReplaceInvalidCharsAndTruncate(title); var folder = FolderDao.GetFolder(title, root.ID) ?? FolderDao.SaveFolder( new Folder { ParentFolderID = root.ID, Title = title, FolderType = FolderType.DEFAULT }); return GetOrCreateHierarchy(path, folder); }
public object SaveFolder(Folder folder) { if (folder == null) throw new ArgumentNullException("folder"); if (folder.ID != null) { var folderId = folder.ID; var selector = GetSelector(folderId); folder.ID = selector.ConvertId(folderId); var newFolderId = selector.GetFolderDao(folderId).SaveFolder(folder); folder.ID = folderId; return newFolderId; } if (folder.ParentFolderID != null) { var folderId = folder.ParentFolderID; var selector = GetSelector(folderId); folder.ParentFolderID = selector.ConvertId(folderId); var newFolderId = selector.GetFolderDao(folderId).SaveFolder(folder); folder.ParentFolderID = folderId; return newFolderId; } throw new ArgumentException("No folder id or parent folder id to determine provider"); }
public static List<FileEntry> MarkedItems(Folder folder) { if (folder == null) throw new ArgumentNullException("folder", FilesCommonResource.ErrorMassage_FolderNotFound); if (!Global.GetFilesSecurity().CanRead(folder)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ViewFolder); if (folder.RootFolderType == FolderType.TRASH && !Equals(folder.ID, Global.FolderTrash)) throw new SecurityException(FilesCommonResource.ErrorMassage_ViewTrashItem); Dictionary<FileEntry, Tag> entryTags; using (var tagDao = Global.DaoFactory.GetTagDao()) using (var fileDao = Global.DaoFactory.GetFileDao()) using (var folderDao = Global.DaoFactory.GetFolderDao()) { var tags = (tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, folder, true) ?? new List<Tag>()).ToList(); if (!tags.Any()) return new List<FileEntry>(); if (Equals(folder.ID, Global.FolderMy) || Equals(folder.ID, Global.FolderCommon) || Equals(folder.ID, Global.FolderShare)) { var folderTags = tags.Where(tag => tag.EntryType == FileEntryType.Folder); var providerFolderTags = folderTags.Select(tag => new KeyValuePair<Tag, Folder>(tag, folderDao.GetFolder(tag.EntryId))) .Where(pair => pair.Value.ProviderEntry).ToList(); providerFolderTags.Reverse(); foreach (var providerFolderTag in providerFolderTags) { tags.AddRange(tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, providerFolderTag.Value, true)); } } tags = tags.Distinct().ToList(); tags.RemoveAll(tag => Equals(tag.EntryId, folder.ID)); tags = tags.Where(t => t.EntryType == FileEntryType.Folder) .Concat(tags.Where(t => t.EntryType == FileEntryType.File)).ToList(); entryTags = tags.ToDictionary( tag => tag.EntryType == FileEntryType.File ? (FileEntry)fileDao.GetFile(tag.EntryId) : (FileEntry)folderDao.GetFolder(tag.EntryId)); } foreach (var entryTag in entryTags) { var entry = entryTag.Key; var parentId = entryTag.Key is File ? ((File)entry).FolderID : ((Folder)entry).ParentFolderID; var parentEntry = entryTags.Keys.FirstOrDefault(entryCountTag => Equals(entryCountTag.ID, parentId)); if (parentEntry != null) entryTags[parentEntry].Count -= entryTag.Value.Count; } var result = new List<FileEntry>(); foreach (var entryTag in entryTags) { if (!string.IsNullOrEmpty(entryTag.Key.Error)) { RemoveMarkAsNew(entryTag.Key); continue; } if (entryTag.Value.Count > 0) { result.Add(entryTag.Key); } } return result; }
public static void DeleteFolder(Folder folder) { var ua = ApplyCustomeActivityParams(folder, "trash_big.png", FilesCommonResource.ActivityDeleteFolder, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity, "DeleteFolder"); ua.URL = folder.RootFolderType == FolderType.TRASH ? string.Empty : PathProvider.GetFolderUrl(folder.ParentFolderID, folder.RootFolderType == FolderType.BUNCH, folder.RootFolderId); PublishInternal(ua); }
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; }