public static List <Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao)
        {
            if (folderId == null)
            {
                return(new List <Folder>());
            }
            var breadCrumbs = Global.GetFilesSecurity().FilterRead(folderDao.GetParentFolders(folderId)).ToList();

            var firstVisible = breadCrumbs.ElementAtOrDefault(0);

            object rootId = null;

            if (firstVisible == null)
            {
                rootId = Global.FolderShare;
            }
            else
            {
                switch (firstVisible.FolderType)
                {
                case FolderType.DEFAULT:
                    if (!firstVisible.ProviderEntry)
                    {
                        rootId = Global.FolderShare;
                    }
                    else
                    {
                        switch (firstVisible.RootFolderType)
                        {
                        case FolderType.USER:
                            rootId = SecurityContext.CurrentAccount.ID == firstVisible.RootFolderCreator
                                        ? Global.FolderMy
                                        : Global.FolderShare;
                            break;

                        case FolderType.COMMON:
                            rootId = Global.FolderCommon;
                            break;
                        }
                    }
                    break;

                case FolderType.BUNCH:
                    rootId = Global.FolderProjects;
                    break;
                }
            }

            if (rootId != null)
            {
                breadCrumbs.Insert(0, folderDao.GetFolder(rootId));
            }

            return(breadCrumbs);
        }
Пример #2
0
        public static List <Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao)
        {
            var breadCrumbs = GetFilesSecurity().FilterRead(folderDao.GetParentFolders(folderId)).ToList();

            var firstVisible = breadCrumbs.ElementAtOrDefault(0);

            if (firstVisible != null && firstVisible.FolderType == FolderType.DEFAULT) //not first level
            {
                Folder root = null;

                if (string.IsNullOrEmpty(firstVisible.ProviderName))
                {
                    root = folderDao.GetFolder(folderDao.GetFolderIDShare(false));
                }
                else
                {
                    switch (firstVisible.RootFolderType)
                    {
                    case FolderType.USER:
                        root = folderDao.GetFolder(folderDao.GetFolderIDUser(false));
                        break;

                    case FolderType.COMMON:
                        root = folderDao.GetFolder(folderDao.GetFolderIDCommon(false));
                        break;
                    }
                }
                if (root != null)
                {
                    firstVisible.ParentFolderID = root.ID;
                    breadCrumbs.Insert(0, root);
                }
            }

            return(breadCrumbs);
        }
Пример #3
0
        public static IEnumerable <FileEntry> SetTagsNew(IFolderDao folderDao, Folder parent, IEnumerable <FileEntry> entries)
        {
            using (var tagDao = Global.DaoFactory.GetTagDao())
            {
                var totalTags = tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, parent, false).ToList();

                if (totalTags.Any())
                {
                    var parentFolderTag = Equals(Global.FolderShare, parent.ID)
                                              ? tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, folderDao.GetFolder(Global.FolderShare)).FirstOrDefault()
                                              : totalTags.FirstOrDefault(tag => tag.EntryType == FileEntryType.Folder && Equals(tag.EntryId, parent.ID));

                    totalTags.Remove(parentFolderTag);
                    var countSubNew = 0;
                    totalTags.ForEach(tag => countSubNew += tag.Count);

                    if (parentFolderTag == null)
                    {
                        parentFolderTag    = Tag.New(SecurityContext.CurrentAccount.ID, parent, 0);
                        parentFolderTag.Id = -1;
                    }

                    if (parentFolderTag.Count != countSubNew)
                    {
                        if (countSubNew > 0)
                        {
                            var diff = parentFolderTag.Count - countSubNew;

                            parentFolderTag.Count -= diff;
                            if (parentFolderTag.Id == -1)
                            {
                                tagDao.SaveTags(parentFolderTag);
                            }
                            else
                            {
                                tagDao.UpdateNewTags(parentFolderTag);
                            }

                            var cacheFolderId = parent.ID;
                            var parentsList   = folderDao.GetParentFolders(parent.ID);
                            parentsList.Reverse();
                            parentsList.Remove(parent);

                            if (parentsList.Any())
                            {
                                var    rootFolder   = parentsList.Last();
                                object rootFolderId = null;
                                cacheFolderId = rootFolder.ID;
                                if (rootFolder.RootFolderType == FolderType.BUNCH)
                                {
                                    cacheFolderId = rootFolderId = Global.FolderProjects;
                                }
                                else if (rootFolder.RootFolderType == FolderType.USER && !Equals(rootFolder.RootFolderId, Global.FolderMy))
                                {
                                    cacheFolderId = rootFolderId = Global.FolderShare;
                                }

                                if (rootFolderId != null)
                                {
                                    parentsList.Add(folderDao.GetFolder(rootFolderId));
                                }

                                var fileSecurity = Global.GetFilesSecurity();

                                foreach (var folderFromList in parentsList)
                                {
                                    var parentTreeTag = tagDao.GetNewTags(SecurityContext.CurrentAccount.ID, folderFromList).FirstOrDefault();

                                    if (parentTreeTag == null)
                                    {
                                        if (fileSecurity.CanRead(folderFromList))
                                        {
                                            tagDao.SaveTags(Tag.New(SecurityContext.CurrentAccount.ID, folderFromList, -diff));
                                        }
                                    }
                                    else
                                    {
                                        parentTreeTag.Count -= diff;
                                        tagDao.UpdateNewTags(parentTreeTag);
                                    }
                                }
                            }

                            if (cacheFolderId != null)
                            {
                                RemoveFromCahce(cacheFolderId);
                            }
                        }
                        else
                        {
                            RemoveMarkAsNew(parent);
                        }
                    }

                    entries.ToList().ForEach(
                        entry =>
                    {
                        var curTag = totalTags.FirstOrDefault(tag => tag.EntryType == entry.FileEntryType && tag.EntryId.Equals(entry.ID));

                        if (entry.FileEntryType == FileEntryType.Folder)
                        {
                            ((Folder)entry).NewForMe = curTag != null ? curTag.Count : 0;
                        }
                        else if (curTag != null)
                        {
                            entry.IsNew = true;
                        }
                    });
                }
            }

            return(entries);
        }
Пример #4
0
        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;
        }
Пример #5
0
        public static List<Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao)
        {
            var breadCrumbs = GetFilesSecurity().FilterRead(folderDao.GetParentFolders(folderId)).ToList();

            var firstVisible = breadCrumbs.ElementAtOrDefault(0);

            if (firstVisible != null && firstVisible.FolderType == FolderType.DEFAULT) //not first level
            {
                Folder root = null;

                if (string.IsNullOrEmpty(firstVisible.ProviderName))
                {
                    root = folderDao.GetFolder(folderDao.GetFolderIDShare(false));
                }
                else
                {
                    switch (firstVisible.RootFolderType)
                    {
                        case FolderType.USER:
                            root = folderDao.GetFolder(folderDao.GetFolderIDUser(false));
                            break;
                        case FolderType.COMMON:
                            root = folderDao.GetFolder(folderDao.GetFolderIDCommon(false));
                            break;
                    }
                }
                if (root != null)
                {
                    firstVisible.ParentFolderID = root.ID;
                    breadCrumbs.Insert(0, root);
                }
            }

            return breadCrumbs;
        }
Пример #6
0
        public static List<Folder> GetBreadCrumbs(object folderId, IFolderDao folderDao)
        {
            var breadCrumbs = Global.GetFilesSecurity().FilterRead(folderDao.GetParentFolders(folderId)).ToList();

            var firstVisible = breadCrumbs.ElementAtOrDefault(0);

            object rootId = null;
            if (firstVisible == null)
            {
                rootId = Global.FolderShare;
            }
            else
            {
                switch (firstVisible.FolderType)
                {
                    case FolderType.DEFAULT:
                        if (!firstVisible.ProviderEntry)
                        {
                            rootId = Global.FolderShare;
                        }
                        else
                        {
                            switch (firstVisible.RootFolderType)
                            {
                                case FolderType.USER:
                                    rootId = SecurityContext.CurrentAccount.ID == firstVisible.RootFolderCreator
                                                 ? Global.FolderMy
                                                 : Global.FolderShare;
                                    break;
                                case FolderType.COMMON:
                                    rootId = Global.FolderCommon;
                                    break;
                            }
                        }
                        break;

                    case FolderType.BUNCH:
                        rootId = Global.FolderProjects;
                        break;
                }
            }

            if (rootId != null)
            {
                breadCrumbs.Insert(0, folderDao.GetFolder(rootId));
            }

            return breadCrumbs;
        }