예제 #1
0
    public Dictionary<long, string> GetFolderList(int rootFolder, bool showNameOnly)
    {
        Dictionary<long, string> folders = new Dictionary<long, string>();

        Ektron.Cms.Framework.Core.Folder.Folder folder = new Ektron.Cms.Framework.Core.Folder.Folder();
        Criteria<FolderProperty> criteria = new Criteria<FolderProperty>();
        criteria.AddFilter(FolderProperty.Id, CriteriaFilterOperator.EqualTo, rootFolder);
        criteria.PagingInfo.RecordsPerPage = int.MaxValue - 1;
        List<FolderData> folderList = folder.GetList(criteria);

        if (folderList == null || folderList.Count == 0)
            return folders;

        string root = folderList[0].NameWithPath;
        folders.Add(rootFolder, showNameOnly ? folderList[0].Name : "/");

        List<long> orderedFolders = new List<long>();
        orderedFolders.Add(rootFolder);
        AddFolders(new long[] { rootFolder }, root, showNameOnly, ref folders, ref orderedFolders);

        // Need to sort
        Dictionary<long, string> ordered = new Dictionary<long, string>();
        for (int i = 0; i < orderedFolders.Count; i++)
            if (!ordered.ContainsKey(orderedFolders[i]))
                ordered.Add(orderedFolders[i], folders[orderedFolders[i]]);

        return ordered;
    }
예제 #2
0
    private void AddFolders(long[] parentFolders, string topPath, bool showNameOnly, ref Dictionary<long, string> folders, ref List<long> orderedFolders)
    {
        List<FolderData> folderList = null;
        Ektron.Cms.Framework.Core.Folder.Folder folder = new Ektron.Cms.Framework.Core.Folder.Folder();
        Criteria<FolderProperty> criteria = new Criteria<FolderProperty>(FolderProperty.FolderPath, EkEnumeration.OrderByDirection.Ascending);
        if (parentFolders.Length > 0)
        {
            criteria.AddFilter(FolderProperty.ParentId, CriteriaFilterOperator.In, parentFolders);
            folderList = folder.GetList(criteria);
        }
        List<long> oldIds = new List<long>(orderedFolders);

        if (folderList == null || folderList.Count == 0)
            return;

        foreach (FolderData f in folderList)
        {
            if (!folders.ContainsKey(f.Id))
            {
                folders.Add(f.Id, showNameOnly ? f.Name : ("/" + f.NameWithPath.Substring(topPath.Length - 1)));
            }
        }

        // Add in the IDs for sorting
        List<long> ids;
        foreach (long parentId in parentFolders)
        {
            ids = folderList.Where(x => x.ParentId == parentId).Select<FolderData, long>(x => x.Id).ToList();
            orderedFolders.InsertRange(orderedFolders.IndexOf(parentId) + 1, ids);
        }

        ids = folderList.Select<FolderData, long>(x => x.Id).ToList();
        ids = ids.ToList().Where(x => !oldIds.Contains(x)).ToList();
        AddFolders(ids.ToArray(), topPath, showNameOnly, ref folders, ref orderedFolders);
    }