コード例 #1
0
ファイル: Service.svc.cs プロジェクト: ridhouan/teamlab.v6.5
 public ItemList<Folder> GetFolders(String parentId, OrderBy orderBy)
 {
     using (var folderDao = GetFolderDao())
     {
         int total;
         var folders = GetEntries(folderDao.GetFolder(parentId), FilterType.FoldersOnly, Guid.Empty, orderBy, string.Empty, 0, 0, out total);
         return new ItemList<Folder>(folders.OfType<Folder>());
     }
 }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var filesSettings = SettingsManager.Instance.LoadSettingsFor<FilesSettings>(SecurityContext.CurrentAccount.ID);
            ContentOrderBy = filesSettings.ContentOrderBy;
            CompactViewFolder = filesSettings.CompactViewFolder;

            Page.ClientScript.RegisterJavaScriptResource(typeof (FilesJSResource), "ASC.Files.FilesJSResources");

            InitScriptConstants();
            InitControls();

            InitStartData();
        }
コード例 #3
0
        public List<Folder> GetFolders(object parentId, OrderBy orderBy, FilterType filterType, Guid subjectID, string searchText)
        {
            var selector = GetSelector(parentId);
            var result = selector.GetFolderDao(parentId).GetFolders(selector.ConvertId(parentId), orderBy, filterType, subjectID, searchText);

            if (!result.Any()) return new List<Folder>();

            if (!Default.IsMatch(parentId))
            {
                SetSharedByMeProperty(result);
            }

            return result;
        }
コード例 #4
0
 public ItemList<Folder> GetFolders(String parentId, OrderBy orderBy)
 {
     using (var folderDao = GetFolderDao())
     {
         try
         {
             int total;
             var folders = EntryManager.GetEntries(folderDao, folderDao.GetFolder(parentId), FilterType.FoldersOnly, Guid.Empty, orderBy, string.Empty, 0, 0, out total);
             return new ItemList<Folder>(folders.OfType<Folder>());
         }
         catch (Exception e)
         {
             Global.Logger.Error(e);
             throw GenerateException(e);
         }
     }
 }
コード例 #5
0
        public List<Folder> GetFolders(object parentId, OrderBy orderBy, FilterType filterType, Guid subjectID, string searchText)
        {
            var folders = GetFolders(parentId).AsEnumerable(); 
            //Filter
            switch (filterType)
            {
                case FilterType.ByUser:
                    folders = folders.Where(x => x.CreateBy == subjectID);
                    break;
                case FilterType.ByDepartment:
                    folders = folders.Where(x => CoreContext.UserManager.IsUserInGroup(x.CreateBy, subjectID));
                    break;
                case FilterType.FoldersOnly:
                case FilterType.None:
                    break;
                default:
                    return new List<Folder>();
            }

            if (!string.IsNullOrEmpty(searchText))
                folders = folders.Where(x => x.Title.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) != -1);

            if (orderBy == null) orderBy = new OrderBy(SortedByType.DateAndTime, false);

            switch (orderBy.SortedBy)
            {
                case SortedByType.Author:
                    folders = orderBy.IsAsc ? folders.OrderBy(x => x.CreateBy) : folders.OrderByDescending(x => x.CreateBy);
                    break;
                case SortedByType.AZ:
                    folders = orderBy.IsAsc ? folders.OrderBy(x => x.Title) : folders.OrderByDescending(x => x.Title);
                    break;
                case SortedByType.DateAndTime:
                    folders = orderBy.IsAsc ? folders.OrderBy(x => x.CreateOn) : folders.OrderByDescending(x => x.CreateOn);
                    break;
                default:
                    folders = orderBy.IsAsc ? folders.OrderBy(x => x.Title) : folders.OrderByDescending(x => x.Title);
                    break;
            }

            return folders.ToList();
        }
コード例 #6
0
        public List<File> GetFiles(object parentId, OrderBy orderBy, FilterType filterType, Guid subjectID, string searchText)
        {
            //Get only files
            var files = ProviderInfo.GetFolderFiles(parentId).Select(r => ProviderInfo.ToFile(r));
            //Filter
            switch (filterType)
            {
                case FilterType.ByUser:
                    files = files.Where(x => x.CreateBy == subjectID);
                    break;
                case FilterType.ByDepartment:
                    files = files.Where(x => CoreContext.UserManager.IsUserInGroup(x.CreateBy, subjectID));
                    break;
                case FilterType.FoldersOnly:
                    return new List<File>();
                case FilterType.DocumentsOnly:
                    files = files.Where(x => FileUtility.GetFileTypeByFileName(x.Title) == FileType.Document).ToList();
                    break;
                case FilterType.PresentationsOnly:
                    files = files.Where(x => FileUtility.GetFileTypeByFileName(x.Title) == FileType.Presentation).ToList();
                    break;
                case FilterType.SpreadsheetsOnly:
                    files = files.Where(x => FileUtility.GetFileTypeByFileName(x.Title) == FileType.Spreadsheet).ToList();
                    break;
                case FilterType.ImagesOnly:
                    files = files.Where(x => FileUtility.GetFileTypeByFileName(x.Title) == FileType.Image).ToList();
                    break;
            }

            if (!string.IsNullOrEmpty(searchText))
                files = files.Where(x => x.Title.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) != -1).ToList();

            if (orderBy == null) orderBy = new OrderBy(SortedByType.DateAndTime, false);

            switch (orderBy.SortedBy)
            {
                case SortedByType.Author:
                    files = orderBy.IsAsc ? files.OrderBy(x => x.CreateBy) : files.OrderByDescending(x => x.CreateBy);
                    break;
                case SortedByType.AZ:
                    files = orderBy.IsAsc ? files.OrderBy(x => x.Title) : files.OrderByDescending(x => x.Title);
                    break;
                case SortedByType.DateAndTime:
                    files = orderBy.IsAsc ? files.OrderBy(x => x.CreateOn) : files.OrderByDescending(x => x.CreateOn);
                    break;
                default:
                    files = orderBy.IsAsc ? files.OrderBy(x => x.Title) : files.OrderByDescending(x => x.Title);
                    break;
            }

            return files.ToList();
        }
コード例 #7
0
ファイル: Service.svc.cs プロジェクト: ridhouan/teamlab.v6.5
        public DataWrapper GetFolderItems(String parentId, String sfrom, String scount, String sfilter, OrderBy orderBy, String ssubject, String searchText, bool compactView)
        {
            var from = Convert.ToInt32(sfrom);
            var count = Convert.ToInt32(scount);
            var filter = (FilterType) Convert.ToInt32(sfilter);
            var subjectId = string.IsNullOrEmpty(ssubject) ? Guid.Empty : new Guid(ssubject);

            using (var folderDao = GetFolderDao())
            using (var tagDao = GetTagDao())
            {
                var parent = folderDao.GetFolder(parentId);
                ErrorIf(parent == null, FilesCommonResource.ErrorMassage_FolderNotFound);
                ErrorIf(!FileSecurity.CanRead(parent), FilesCommonResource.ErrorMassage_SecurityException_ViewFolder);
                ErrorIf(parent.RootFolderType == FolderType.TRASH && !Equals(parent.ID, Global.FolderTrash), FilesCommonResource.ErrorMassage_ViewTrashItem);

                if (Equals(parent.ID, Global.FolderShare))
                    orderBy = new OrderBy(SortedByType.DateAndTime, false);

                int total;
                var entries = GetEntries(parent, filter, subjectId, orderBy, searchText, from, count, out total);

                var breadCrumbs = Global.GetBreadCrumbs(parentId, folderDao);

                var prevVisible = breadCrumbs.ElementAtOrDefault(breadCrumbs.Count() - 2);
                if (prevVisible != null)
                {
                    parent.ParentFolderID = prevVisible.ID;
                }

                parent.Shareable = (parent.RootFolderType == FolderType.USER && parent.RootFolderCreator == SecurityContext.CurrentAccount.ID) ||
                                   (parent.RootFolderType == FolderType.COMMON && Global.IsAdministrator);

                var result = new DataWrapper
                                 {
                                     Folders = entries.OfType<Folder>().ToList(),
                                     Files = entries.OfType<File>().ToList(),
                                     Total = total,

                                     FolderPathParts = new ItemDictionary<object, String>(breadCrumbs.ToDictionary(f => f.ID, f => f.Title)),
                                     FolderInfo = parent
                                 };

                var newtags = tagDao.GetTags(SecurityContext.CurrentAccount.ID, TagType.New);
                result.CountNewInShare = newtags.Count();
                result.Files.ForEach(f => { if (newtags.Where(t => t.EntryType == FileEntryType.File).Select(t => t.EntryId).Contains(f.ID)) f.FileStatus |= FileStatus.IsNew; });
                result.Folders.ForEach(f => { if (newtags.Where(t => t.EntryType == FileEntryType.Folder).Select(t => t.EntryId).Contains(f.ID)) f.NewForMe = true; });

                if (newtags.Count(t => t.EntryType == FileEntryType.Folder && Equals(t.EntryId, parent.ID)) > 0)
                {
                    tagDao.RemoveTags(Tag.New(SecurityContext.CurrentAccount.ID, parent));
                    result.CountNewInShare--;
                }

                var filesSettings = SettingsManager.Instance.LoadSettingsFor<FilesSettings>(SecurityContext.CurrentAccount.ID);
                filesSettings.ContentOrderBy = orderBy;
                filesSettings.CompactViewFolder = compactView;
                SettingsManager.Instance.SaveSettingsFor(filesSettings, SecurityContext.CurrentAccount.ID);

                return result;
            }
        }
コード例 #8
0
ファイル: Service.svc.cs プロジェクト: ridhouan/teamlab.v6.5
        public ItemDictionary<String, String> GetSiblingsFile(String fileId, String sfilter, OrderBy orderBy, String ssubject, String searchText)
        {
            var filter = (FilterType) Convert.ToInt32(sfilter);
            var subjectId = string.IsNullOrEmpty(ssubject) ? Guid.Empty : new Guid(ssubject);

            using (var fileDao = GetFileDao())
            using (var folderDao = GetFolderDao())
            {
                var file = fileDao.GetFile(fileId);
                ErrorIf(file == null, FilesCommonResource.ErrorMassage_FileNotFound, true);
                ErrorIf(!FileSecurity.CanRead(file), FilesCommonResource.ErrorMassage_SecurityException_ReadFile, true);

                var folder = folderDao.GetFolder(file.FolderID);
                ErrorIf(folder == null, FilesCommonResource.ErrorMassage_FolderNotFound, true);
                ErrorIf(folder.RootFolderType == FolderType.TRASH, FilesCommonResource.ErrorMassage_ViewTrashItem, true);

                var entries = Enumerable.Empty<FileEntry>();
                if (!FileSecurity.CanRead(folder) &&
                    folder.RootFolderType == FolderType.USER && !Equals(folder.RootFolderId, Global.FolderMy))
                {
                    orderBy = new OrderBy(SortedByType.DateAndTime, false);

                    var shared = (IEnumerable<FileEntry>) FileSecurity.GetSharesForMe();
                    shared = FilterEntries(shared, filter, subjectId, searchText)
                        .Where(f => f is File &&
                                    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);
                }
                else
                {
                    entries = entries.Concat(folderDao.GetFiles(folder.ID, orderBy, filter, subjectId, searchText).Cast<FileEntry>());
                }

                entries = SortEntries(entries, orderBy);

                var result = new ItemDictionary<string, String>();
                FileSecurity.FilterRead(entries)
                    .OfType<File>()
                    .Where(f => FileUtility.ExtsImagePreviewed.Contains(FileUtility.GetFileExtension(f.Title)))
                    .ToList()
                    .ForEach(f => result.Add(f.ID.ToString(), f.Version + "#" + f.Title));

                return result;
            }
        }
コード例 #9
0
ファイル: Service.svc.cs プロジェクト: ridhouan/teamlab.v6.5
        private static IEnumerable<FileEntry> SortEntries(IEnumerable<FileEntry> entries, OrderBy orderBy)
        {
            Comparison<FileEntry> sorter;

            if (orderBy == null) orderBy = new OrderBy(SortedByType.DateAndTime, false);

            var c = orderBy.IsAsc ? 1 : -1;
            switch (orderBy.SortedBy)
            {
                case SortedByType.Type:
                    sorter = (x, y) =>
                                 {
                                     var cmp = 0;
                                     if (x is File && y is File)
                                         cmp = c*(FileUtility.GetFileExtension((x.Title)).CompareTo(FileUtility.GetFileExtension(y.Title)));
                                     return cmp == 0 ? x.Title.CompareTo(y.Title) : cmp;
                                 };
                    break;
                case SortedByType.Author:
                    sorter = (x, y) =>
                                 {
                                     var cmp = c*string.Compare(x.ModifiedByString, y.ModifiedByString);
                                     return cmp == 0 ? x.Title.CompareTo(y.Title) : cmp;
                                 };
                    break;
                case SortedByType.Size:
                    sorter = (x, y) =>
                                 {
                                     var cmp = 0;
                                     if (x is File && y is File)
                                         cmp = c*((File) x).ContentLength.CompareTo(((File) y).ContentLength);
                                     return cmp == 0 ? x.Title.CompareTo(y.Title) : cmp;
                                 };
                    break;
                case SortedByType.AZ:
                    sorter = (x, y) => c*x.Title.CompareTo(y.Title);
                    break;
                case SortedByType.DateAndTime:
                    sorter = (x, y) =>
                                 {
                                     var cmp = c*DateTime.Compare(x.ModifiedOn, y.ModifiedOn);
                                     return cmp == 0 ? x.Title.CompareTo(y.Title) : cmp;
                                 };
                    break;
                default:
                    sorter = (x, y) => c*x.Title.CompareTo(y.Title);
                    break;
            }

            // folders on top
            var folders = entries.OfType<Folder>().Cast<FileEntry>().ToList();
            var files = entries.OfType<File>().Cast<FileEntry>().ToList();
            folders.Sort(sorter);
            files.Sort(sorter);

            return folders.Concat(files);
        }
コード例 #10
0
ファイル: Service.svc.cs プロジェクト: ridhouan/teamlab.v6.5
        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();
            }
        }
コード例 #11
0
        public KeyValuePair<string, ItemDictionary<String, String>> GetSiblingsFile(String fileId, String sfilter, OrderBy orderBy, String ssubject, String searchText)
        {
            var filter = (FilterType)Convert.ToInt32(sfilter);
            var subjectId = string.IsNullOrEmpty(ssubject) ? Guid.Empty : new Guid(ssubject);

            using (var fileDao = GetFileDao())
            using (var folderDao = GetFolderDao())
            {
                var file = fileDao.GetFile(fileId);
                ErrorIf(file == null, FilesCommonResource.ErrorMassage_FileNotFound);
                ErrorIf(!FileSecurity.CanRead(file), FilesCommonResource.ErrorMassage_SecurityException_ReadFile);

                var folder = folderDao.GetFolder(file.FolderID);
                ErrorIf(folder == null, FilesCommonResource.ErrorMassage_FolderNotFound);
                ErrorIf(folder.RootFolderType == FolderType.TRASH, FilesCommonResource.ErrorMassage_ViewTrashItem);

                var folderId = file.FolderID;
                var entries = Enumerable.Empty<FileEntry>();
                if (!FileSecurity.CanRead(folder) &&
                    folder.RootFolderType == FolderType.USER && !Equals(folder.RootFolderId, Global.FolderMy))
                {
                    folderId = Global.FolderShare;
                    orderBy = new OrderBy(SortedByType.DateAndTime, false);

                    var shared = (IEnumerable<FileEntry>)FileSecurity.GetSharesForMe();
                    shared = EntryManager.FilterEntries(shared, filter, subjectId, searchText)
                                         .Where(f => f is File &&
                                                     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);
                }
                else if (folder.FolderType == FolderType.BUNCH)
                {
                    var path = folderDao.GetBunchObjectID(folder.RootFolderId);

                    var projectID = path.Split('/').Last();

                    if (String.IsNullOrEmpty(projectID))
                    {
                        folderId = Global.FolderMy;
                        entries = entries.Concat(new List<FileEntry> {file});
                    }
                    else
                    {
                        entries = entries.Concat(folderDao.GetFiles(folder.ID, orderBy, filter, subjectId, searchText));
                    }
                }
                else
                {
                    entries = entries.Concat(folderDao.GetFiles(folder.ID, orderBy, filter, subjectId, searchText));
                }

                entries = EntryManager.SortEntries(entries, orderBy);

                var siblingType = FileUtility.GetFileTypeByFileName(file.Title);

                var result = new ItemDictionary<String, String>();
                FileSecurity.FilterRead(entries)
                            .OfType<File>()
                            .Where(f => siblingType.Equals(FileUtility.GetFileTypeByFileName(f.Title)))
                            .ToList()
                            .ForEach(f => result.Add(f.ID.ToString(), f.Version + "&" + f.Title));

                return new KeyValuePair<string, ItemDictionary<string, string>>(folderId.ToString(), result);
            }
        }
コード例 #12
0
        public DataWrapper GetFolderItems(String parentId, String sfrom, String scount, String sfilter, OrderBy orderBy, String ssubject, String searchText)
        {
            var from = Convert.ToInt32(sfrom);
            var count = Convert.ToInt32(scount);
            var filter = (FilterType)Convert.ToInt32(sfilter);
            var subjectId = string.IsNullOrEmpty(ssubject) ? Guid.Empty : new Guid(ssubject);

            using (var folderDao = GetFolderDao())
            {
                Folder parent;
                try
                {
                    parent = folderDao.GetFolder(parentId);
                }
                catch(Exception e)
                {
                    throw GenerateException(e);
                }

                ErrorIf(parent == null, FilesCommonResource.ErrorMassage_FolderNotFound);
                ErrorIf(!FileSecurity.CanRead(parent), FilesCommonResource.ErrorMassage_SecurityException_ViewFolder);
                ErrorIf(parent.RootFolderType == FolderType.TRASH && !Equals(parent.ID, Global.FolderTrash), FilesCommonResource.ErrorMassage_ViewTrashItem);

                if (Equals(parent.ID, Global.FolderShare))
                    orderBy = new OrderBy(SortedByType.New, false);
                else if (orderBy.SortedBy == SortedByType.New)
                    orderBy = new OrderBy(SortedByType.DateAndTime, true);

                int total;
                IEnumerable<FileEntry> entries;
                try
                {
                    entries = EntryManager.GetEntries(folderDao, parent, filter, subjectId, orderBy, searchText, from, count, out total);
                }
                catch(Exception e)
                {
                    throw GenerateException(e);
                }

                var breadCrumbs = EntryManager.GetBreadCrumbs(parentId, folderDao);

                var prevVisible = breadCrumbs.ElementAtOrDefault(breadCrumbs.Count() - 2);
                if (prevVisible != null)
                {
                    parent.ParentFolderID = prevVisible.ID;
                }

                parent.Shareable = FileSharing.CanSetAccess(parent) || parent.FolderType == FolderType.SHARE;

                entries = entries.Where(x =>
                    {
                        if (x is Folder) return true;

                        var file = (File)x;

                        return (file.FileStatus & FileStatus.IsConverting) != FileStatus.IsConverting;
                    });

                var result = new DataWrapper
                    {
                        Total = total,
                        Entries = entries.ToList(),
                        FolderPathParts = new ItemList<object>(breadCrumbs.Select(f => f.ID)),
                        FolderInfo = parent,
                        RootFoldersIdMarkedAsNew = new ItemDictionary<object, int>(FileMarker.GetRootFoldersIdMarkedAsNew())
                    };

                return result;
            }
        }
コード例 #13
0
        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;
        }
コード例 #14
0
        public static IEnumerable<FileEntry> SortEntries(IEnumerable<FileEntry> entries, OrderBy orderBy)
        {
            Comparison<FileEntry> sorter;

            if (orderBy == null) orderBy = new OrderBy(SortedByType.DateAndTime, false);

            var c = orderBy.IsAsc ? 1 : -1;
            switch (orderBy.SortedBy)
            {
                case SortedByType.Type:
                    sorter = (x, y) =>
                                 {
                                     var cmp = 0;
                                     if (x is File && y is File)
                                         cmp = c*(FileUtility.GetFileExtension((x.Title)).CompareTo(FileUtility.GetFileExtension(y.Title)));
                                     return cmp == 0 ? x.Title.CompareTo(y.Title) : cmp;
                                 };
                    break;
                case SortedByType.Author:
                    sorter = (x, y) =>
                                 {
                                     var cmp = c*string.Compare(x.ModifiedByString, y.ModifiedByString);
                                     return cmp == 0 ? x.Title.CompareTo(y.Title) : cmp;
                                 };
                    break;
                case SortedByType.Size:
                    sorter = (x, y) =>
                                 {
                                     var cmp = 0;
                                     if (x is File && y is File)
                                         cmp = c*((File)x).ContentLength.CompareTo(((File)y).ContentLength);
                                     return cmp == 0 ? x.Title.CompareTo(y.Title) : cmp;
                                 };
                    break;
                case SortedByType.AZ:
                    sorter = (x, y) => c*x.Title.CompareTo(y.Title);
                    break;
                case SortedByType.DateAndTime:
                    sorter = (x, y) =>
                                 {
                                     var cmp = c*DateTime.Compare(x.ModifiedOn, y.ModifiedOn);
                                     return cmp == 0 ? x.Title.CompareTo(y.Title) : cmp;
                                 };
                    break;
                case SortedByType.New:
                    sorter = (x, y) =>
                                 {
                                     var isNew = new Func<FileEntry, int>(
                                         val => val is File
                                                    ? ((((File)val).FileStatus & FileStatus.IsNew) == FileStatus.IsNew ? 1 : 0)
                                                    : ((Folder)val).NewForMe);

                                     var isNewSortResult = c*isNew(x).CompareTo(isNew(y));

                                     if (isNewSortResult == 0)
                                     {
                                         var dataTimeSortResult = (-1)*DateTime.Compare(x.ModifiedOn, y.ModifiedOn);

                                         return dataTimeSortResult == 0
                                                    ? x.Title.CompareTo(y.Title)
                                                    : dataTimeSortResult;
                                     }

                                     return isNewSortResult;
                                 };
                    break;
                default:
                    sorter = (x, y) => c*x.Title.CompareTo(y.Title);
                    break;
            }

            if (orderBy.SortedBy != SortedByType.New)
            {
                // folders on top
                var folders = entries.OfType<Folder>().Cast<FileEntry>().ToList();
                var files = entries.OfType<File>().Cast<FileEntry>().ToList();
                folders.Sort(sorter);
                files.Sort(sorter);

                return folders.Concat(files);
            }

            var result = entries.ToList();

            result.Sort(sorter);

            return result;
        }