예제 #1
0
 public object GetRoot(int projectId)
 {
     return(FilesIntegration.RegisterBunch(Module, Bunch, projectId.ToString(CultureInfo.InvariantCulture)));
 }
        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);
        }
예제 #3
0
 public object GetRoot()
 {
     return(FilesIntegration.RegisterBunch("crm", "crm_common", ""));
 }
예제 #4
0
        public List <SearchGroup> Search(String searchText, int projectId)
        {
            var queryResult = _searchDao.Search(searchText, projectId);

            var groups = new Dictionary <int, SearchGroup>();

            foreach (var r in queryResult)
            {
                var        projId = 0;
                SearchItem item   = null;

                if (r is Project)
                {
                    var p = (Project)r;
                    if (ProjectSecurity.CanRead(p))
                    {
                        projId = p.ID;
                        if (!groups.ContainsKey(projId))
                        {
                            groups[projId] = new SearchGroup(projId, p.Title);
                        }
                        item = new SearchItem(EntityType.Project, p.ID, p.Title, p.Description, p.CreateOn);
                    }
                }
                else
                {
                    if (r is Milestone)
                    {
                        var m = (Milestone)r;
                        if (ProjectSecurity.CanRead(m))
                        {
                            projId = m.Project.ID;
                            if (!groups.ContainsKey(projId))
                            {
                                groups[projId] = new SearchGroup(projId, m.Project.Title);
                            }
                            item = new SearchItem(EntityType.Milestone, m.ID, m.Title, null, m.CreateOn);
                        }
                    }
                    else if (r is Message)
                    {
                        var m = (Message)r;
                        if (ProjectSecurity.CanReadMessages(m.Project))
                        {
                            projId = m.Project.ID;
                            if (!groups.ContainsKey(projId))
                            {
                                groups[projId] = new SearchGroup(projId, m.Project.Title);
                            }
                            item = new SearchItem(EntityType.Message, m.ID, m.Title, m.Content, m.CreateOn);
                        }
                    }
                    else if (r is Task)
                    {
                        var t = (Task)r;
                        if (ProjectSecurity.CanRead(t))
                        {
                            projId = t.Project.ID;
                            if (!groups.ContainsKey(projId))
                            {
                                groups[projId] = new SearchGroup(projId, t.Project.Title);
                            }
                            item = new SearchItem(EntityType.Task, t.ID, t.Title, t.Description, t.CreateOn);
                        }
                    }
                }
                if (0 < projId && item != null)
                {
                    groups[projId].Items.Add(item);
                }
            }

            try
            {
                // search in files
                var fileEntries = new List <Files.Core.FileEntry>();
                using (var folderDao = FilesIntegration.GetFolderDao())
                    using (var fileDao = FilesIntegration.GetFileDao())
                    {
                        fileEntries.AddRange(folderDao.Search(searchText, Files.Core.FolderType.BUNCH).Cast <Files.Core.FileEntry>());
                        fileEntries.AddRange(fileDao.Search(searchText, Files.Core.FolderType.BUNCH).Cast <Files.Core.FileEntry>());

                        var projectIds = projectId != 0
                                         ? new List <int> {
                            projectId
                        }
                                         : fileEntries.GroupBy(f => f.RootFolderId)
                        .Select(g => folderDao.GetFolder(g.Key))
                        .Select(f => f != null ? folderDao.GetBunchObjectID(f.RootFolderId).Split('/').Last() : null)
                        .Where(s => !string.IsNullOrEmpty(s))
                        .Select(s => int.Parse(s));

                        var rootProject = projectIds.ToDictionary(id => FilesIntegration.RegisterBunch("projects", "project", id.ToString()));
                        fileEntries.RemoveAll(f => !rootProject.ContainsKey(f.RootFolderId));

                        var security = FilesIntegration.GetFileSecurity();
                        fileEntries.RemoveAll(f => !security.CanRead(f));

                        foreach (var f in fileEntries)
                        {
                            var id = rootProject[f.RootFolderId];
                            if (!groups.ContainsKey(id))
                            {
                                var project = _projDao.GetById(id);
                                if (project != null && ProjectSecurity.CanRead(project) && ProjectSecurity.CanReadFiles(project))
                                {
                                    groups[id] = new SearchGroup(id, project.Title);
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            var item = new SearchItem
                            {
                                EntityType = EntityType.File,
                                ID         = f is Files.Core.File ? ((Files.Core.File)f).ViewUrl : string.Format("{0}tmdocs.aspx?prjID={1}#{2}", VirtualPathUtility.ToAbsolute("~/products/projects/"), id, f.ID),
                                Title      = f.Title,
                                CreateOn   = f.CreateOn,
                            };
                            groups[id].Items.Add(item);
                        }
                    }
            }
            catch (Exception err)
            {
                LogManager.GetLogger("ASC.Web").Error(err);
            }
            return(new List <SearchGroup>(groups.Values));
        }
예제 #5
0
 public int GetRoot()
 {
     return(_filesIntegration.RegisterBunch <int>("crm", "crm_common", ""));
 }
예제 #6
0
 public object GetMy()
 {
     return(FilesIntegration.RegisterBunch("files", "my", SecurityContext.CurrentAccount.ID.ToString()));
 }
예제 #7
0
        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);
        }
예제 #8
0
        public IEnumerable <SearchItem> Search(string searchText, int projectId = 0)
        {
            var queryResult = DaoFactory.SearchDao.Search(searchText, projectId);

            using (var scope = DIHelper.Resolve())
            {
                var projectSecurity = scope.Resolve <ProjectSecurity>();

                foreach (var r in queryResult)
                {
                    switch (r.EntityType)
                    {
                    case EntityType.Project:
                        var project = (Project)r;
                        if (projectSecurity.CanRead(project))
                        {
                            searchItems.Add(new SearchItem(project));
                        }
                        continue;

                    case EntityType.Milestone:
                        var milestone = (Milestone)r;
                        if (projectSecurity.CanRead(milestone))
                        {
                            searchItems.Add(new SearchItem(milestone));
                        }
                        continue;

                    case EntityType.Message:
                        var message = (Message)r;
                        if (projectSecurity.CanRead(message))
                        {
                            searchItems.Add(new SearchItem(message));
                        }
                        continue;

                    case EntityType.Task:
                        var task = (Task)r;
                        if (projectSecurity.CanRead(task))
                        {
                            searchItems.Add(new SearchItem(task));
                        }
                        continue;

                    case EntityType.Comment:
                        var comment = (Comment)r;
                        var entity  = CommentEngine.GetEntityByTargetUniqId(comment);
                        if (entity == null)
                        {
                            continue;
                        }

                        searchItems.Add(new SearchItem(comment.EntityType,
                                                       comment.ID.ToString(CultureInfo.InvariantCulture), HtmlUtil.GetText(comment.Content),
                                                       comment.CreateOn, new SearchItem(entity)));
                        continue;

                    case EntityType.SubTask:
                        var subtask    = (Subtask)r;
                        var parentTask = TaskEngine.GetByID(subtask.Task);
                        if (parentTask == null)
                        {
                            continue;
                        }

                        searchItems.Add(new SearchItem(subtask.EntityType,
                                                       subtask.ID.ToString(CultureInfo.InvariantCulture), subtask.Title, subtask.CreateOn,
                                                       new SearchItem(parentTask)));
                        continue;
                    }
                }
            }

            try
            {
                // search in files
                var fileEntries = new List <FileEntry>();
                using (var folderDao = FilesIntegration.GetFolderDao())
                    using (var fileDao = FilesIntegration.GetFileDao())
                    {
                        fileEntries.AddRange(folderDao.Search(searchText, true));
                        fileEntries.AddRange(fileDao.Search(searchText, true));

                        var projectIds = projectId != 0
                                         ? new List <int> {
                            projectId
                        }
                                         : fileEntries.GroupBy(f => f.RootFolderId)
                        .Select(g => folderDao.GetFolder(g.Key))
                        .Select(f => f != null ? folderDao.GetBunchObjectID(f.RootFolderId).Split('/').Last() : null)
                        .Where(s => !string.IsNullOrEmpty(s))
                        .Select(int.Parse);

                        var rootProject = projectIds.ToDictionary(id => FilesIntegration.RegisterBunch("projects", "project", id.ToString(CultureInfo.InvariantCulture)));
                        fileEntries.RemoveAll(f => !rootProject.ContainsKey(f.RootFolderId));

                        var security = FilesIntegration.GetFileSecurity();
                        fileEntries.RemoveAll(f => !security.CanRead(f));

                        foreach (var f in fileEntries)
                        {
                            var id      = rootProject[f.RootFolderId];
                            var project = DaoFactory.ProjectDao.GetById(id);

                            if (ProjectSecurity.CanReadFiles(project))
                            {
                                var itemId = f.FileEntryType == FileEntryType.File
                                             ? FilesLinkUtility.GetFileWebPreviewUrl(f.Title, f.ID)
                                             : Web.Files.Classes.PathProvider.GetFolderUrl((Folder)f, project.ID);
                                searchItems.Add(new SearchItem(EntityType.File, itemId, f.Title, f.CreateOn, new SearchItem(project), itemPath: "{2}"));
                            }
                        }
                    }
            }
            catch (Exception err)
            {
                LogManager.GetLogger("ASC").Error(err);
            }
            return(searchItems);
        }
예제 #9
0
 public object GetRoot(int projectId)
 {
     return(FilesIntegration.RegisterBunch("projects", "project", projectId.ToString()));
 }
예제 #10
0
 public static object GetFolderId(string eventId)
 {
     return(FilesIntegration.RegisterBunch(Module, Bunch, eventId));
 }
예제 #11
0
 public static object GetTmpFolderId()
 {
     return(FilesIntegration.RegisterBunch(Module, Bunch, Temp));
 }
예제 #12
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("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);
        }