Example #1
0
        private static NavigationTree[] CreateNavigationTreeByFolderLists(UserContext userContext, FolderList[] folderLists, params NavigationNodeCollection[] collections)
        {
            if (folderLists == null || folderLists.Length == 0)
            {
                throw new ArgumentNullException("folderLists");
            }
            if (collections.Length == 0)
            {
                return(new NavigationTree[0]);
            }
            string[]        array  = new string[collections.Length];
            StoreObjectId[] array2 = new StoreObjectId[collections.Length];
            for (int i = 0; i < collections.Length; i++)
            {
                array[i] = NavigationNode.GetFolderClass(collections[i].GroupSection);
                if (ObjectClass.IsOfClass(array[i], "IPF.Note"))
                {
                    throw new ArgumentException("Invalid group section. Can only be Calendar, Contact, Task");
                }
                switch (collections[i].GroupSection)
                {
                case NavigationNodeGroupSection.Calendar:
                    array2[i] = Utilities.TryGetDefaultFolderId(userContext.MailboxSession, DefaultFolderType.Calendar);
                    break;

                case NavigationNodeGroupSection.Contacts:
                    array2[i] = Utilities.TryGetDefaultFolderId(userContext.MailboxSession, DefaultFolderType.Contacts);
                    break;

                case NavigationNodeGroupSection.Tasks:
                    array2[i] = Utilities.TryGetDefaultFolderId(userContext.MailboxSession, DefaultFolderType.Tasks);
                    break;

                default:
                    throw new ArgumentException("Invalid group section. Can only be Calendar, Contact, Task");
                }
            }
            Dictionary <string, StoreObjectId>[] array3 = new Dictionary <string, StoreObjectId> [collections.Length];
            for (int j = 0; j < array.Length; j++)
            {
                array3[j] = new Dictionary <string, StoreObjectId>();
            }
            foreach (FolderList folderList in folderLists)
            {
                foreach (StoreObjectId storeObjectId in folderList.GetFolderIds())
                {
                    string itemClass = folderList.GetFolderProperty(storeObjectId, StoreObjectSchema.ContainerClass) as string;
                    for (int m = 0; m < array.Length; m++)
                    {
                        if (ObjectClass.IsOfClass(itemClass, array[m]))
                        {
                            string key = folderList.MailboxSession.MailboxOwnerLegacyDN.ToLowerInvariant() + storeObjectId.ToString();
                            array3[m][key] = storeObjectId;
                            break;
                        }
                    }
                }
            }
            bool flag = false;

            NavigationNodeGroupSection[] array4 = new NavigationNodeGroupSection[collections.Length];
            StoreObjectId storeObjectId2        = userContext.TryGetMyDefaultFolderId(DefaultFolderType.ToDoSearch);
            List <NavigationNodeFolder> list    = new List <NavigationNodeFolder>();

            for (int n = 0; n < collections.Length; n++)
            {
                list.Clear();
                bool flag2 = false;
                bool flag3 = false;
                NavigationNodeCollection   navigationNodeCollection   = collections[n];
                NavigationNodeGroupSection navigationNodeGroupSection = navigationNodeCollection.GroupSection;
                array4[n] = navigationNodeGroupSection;
                foreach (NavigationNodeGroup navigationNodeGroup in navigationNodeCollection)
                {
                    foreach (NavigationNodeFolder navigationNodeFolder in navigationNodeGroup.Children)
                    {
                        if (navigationNodeFolder.IsValid && navigationNodeFolder.FolderId != null && !navigationNodeFolder.IsFlagSet(NavigationNodeFlags.PublicFolderFavorite))
                        {
                            bool flag4 = false;
                            foreach (FolderList folderList2 in folderLists)
                            {
                                if (navigationNodeFolder.IsFolderInSpecificMailboxSession(folderList2.MailboxSession))
                                {
                                    flag4 = true;
                                    break;
                                }
                            }
                            if (flag4)
                            {
                                string key2 = navigationNodeFolder.MailboxLegacyDN.ToLowerInvariant() + navigationNodeFolder.FolderId.ToString();
                                if (!array3[n].Remove(key2))
                                {
                                    if (navigationNodeGroupSection == NavigationNodeGroupSection.Tasks && storeObjectId2 != null && storeObjectId2.Equals(navigationNodeFolder.FolderId))
                                    {
                                        flag3 = true;
                                    }
                                    else
                                    {
                                        list.Add(navigationNodeFolder);
                                    }
                                }
                                if (navigationNodeFolder.FolderId.Equals(array2[n]))
                                {
                                    foreach (FolderList folderList3 in folderLists)
                                    {
                                        if (navigationNodeFolder.IsFolderInSpecificMailboxSession(folderList3.MailboxSession))
                                        {
                                            string text    = (string)folderList3.GetFolderProperty(navigationNodeFolder.FolderId, FolderSchema.DisplayName);
                                            string subject = navigationNodeFolder.Subject;
                                            if (text != null && !text.Equals(subject))
                                            {
                                                navigationNodeFolder.Subject = text;
                                                flag2 = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (navigationNodeGroupSection == NavigationNodeGroupSection.Tasks && !flag3 && storeObjectId2 != null)
                {
                    navigationNodeCollection.InsertToDoFolderToGroup(userContext);
                    flag2 = true;
                }
                if (array3[n].Count > 0)
                {
                    foreach (KeyValuePair <string, StoreObjectId> keyValuePair in array3[n])
                    {
                        StoreObjectId value = keyValuePair.Value;
                        string        key3  = keyValuePair.Key;
                        string        y     = key3.Substring(0, key3.LastIndexOf(value.ToString()));
                        foreach (FolderList folderList4 in folderLists)
                        {
                            if (StringComparer.OrdinalIgnoreCase.Equals(folderList4.MailboxSession.MailboxOwnerLegacyDN, y))
                            {
                                navigationNodeCollection.AddMyFolderToGroup(userContext, folderList4.MailboxSession, folderList4.GetFolderProperties(value), folderList4.QueryPropertyMap);
                                break;
                            }
                        }
                    }
                    flag2 = true;
                }
                if (list.Count > 0)
                {
                    foreach (NavigationNodeFolder navigationNodeFolder2 in list)
                    {
                        navigationNodeCollection.RemoveFolderOrGroupByNodeId(navigationNodeFolder2.NavigationNodeId.ObjectId);
                    }
                    flag2 = true;
                }
                if (flag2)
                {
                    navigationNodeCollection.Save(userContext.MailboxSession);
                    flag = true;
                }
            }
            if (flag)
            {
                collections = NavigationNodeCollection.TryCreateNavigationNodeCollections(userContext, userContext.MailboxSession, array4);
            }
            NavigationTree[] array5 = new NavigationTree[collections.Length];
            for (int num4 = 0; num4 < collections.Length; num4++)
            {
                NavigationNodeCollection navigationNodeCollection2 = collections[num4];
                NavigationTree           navigationTree            = new NavigationTree(userContext, new InvisibleRootTreeNode(userContext), navigationNodeCollection2.GroupSection);
                foreach (NavigationNodeGroup navigationNodeGroup2 in navigationNodeCollection2)
                {
                    if (!navigationNodeGroup2.IsNew)
                    {
                        if ((navigationNodeCollection2.GroupSection == NavigationNodeGroupSection.Contacts || navigationNodeCollection2.GroupSection == NavigationNodeGroupSection.Tasks) && NavigationNodeCollection.PeoplesFoldersClassId.Equals(navigationNodeGroup2.NavigationNodeGroupClassId))
                        {
                            bool flag5 = false;
                            foreach (NavigationNodeFolder navigationNodeFolder3 in navigationNodeGroup2.Children)
                            {
                                if (navigationNodeFolder3.NavigationNodeType != NavigationNodeType.SharedFolder)
                                {
                                    flag5 = true;
                                    break;
                                }
                            }
                            if (!flag5)
                            {
                                continue;
                            }
                        }
                        NavigationGroupHeaderTreeNode navigationGroupHeaderTreeNode = new NavigationGroupHeaderTreeNode(userContext, navigationNodeGroup2);
                        foreach (NavigationNodeFolder navigationNodeFolder4 in navigationNodeGroup2.Children)
                        {
                            if (((navigationNodeCollection2.GroupSection != NavigationNodeGroupSection.Contacts && navigationNodeCollection2.GroupSection != NavigationNodeGroupSection.Tasks) || navigationNodeFolder4.NavigationNodeType != NavigationNodeType.SharedFolder) && navigationNodeFolder4.IsValid && (navigationNodeFolder4.IsGSCalendar || navigationNodeFolder4.FolderId != null))
                            {
                                NavigationFolderTreeNode navigationFolderTreeNode = null;
                                foreach (FolderList folderList5 in folderLists)
                                {
                                    object[] array6 = null;
                                    if (navigationNodeFolder4.FolderId != null)
                                    {
                                        array6 = folderList5.GetFolderProperties(navigationNodeFolder4.FolderId);
                                    }
                                    if (array6 != null)
                                    {
                                        navigationFolderTreeNode = new NavigationFolderTreeNode(userContext, navigationNodeFolder4, null, array6, folderList5.QueryPropertyMap);
                                        break;
                                    }
                                }
                                if (navigationFolderTreeNode == null && (!navigationNodeFolder4.IsFolderInSpecificMailboxSession(userContext.MailboxSession) || (navigationNodeFolder4.FolderId != null && Utilities.IsDefaultFolderId(userContext.MailboxSession, navigationNodeFolder4.FolderId, DefaultFolderType.ToDoSearch))))
                                {
                                    navigationFolderTreeNode = new NavigationFolderTreeNode(userContext, navigationNodeFolder4);
                                }
                                if (navigationFolderTreeNode != null)
                                {
                                    navigationGroupHeaderTreeNode.AddChild(navigationFolderTreeNode);
                                }
                            }
                        }
                        navigationTree.RootNode.AddChild(navigationGroupHeaderTreeNode);
                    }
                }
                array5[num4] = navigationTree;
            }
            return(array5);
        }