public static CalendarGroupInfoList GetCalendarGroupsView(MailboxSession session) { bool flag = false; bool flag2 = true; Dictionary <Guid, CalendarGroupInfo> guidToGroupMapping = new Dictionary <Guid, CalendarGroupInfo>(); Dictionary <StoreObjectId, LocalCalendarGroupEntryInfo> dictionary = new Dictionary <StoreObjectId, LocalCalendarGroupEntryInfo>(); List <FolderTreeDataInfo> duplicateNodes = new List <FolderTreeDataInfo>(); Dictionary <CalendarGroupType, CalendarGroupInfo> defaultGroups = new Dictionary <CalendarGroupType, CalendarGroupInfo>(); CalendarGroupInfoList calendarGroupInfoList = new CalendarGroupInfoList(duplicateNodes, defaultGroups, dictionary); using (Folder folder = Folder.Bind(session, DefaultFolderType.CommonViews)) { using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.Associated, null, CalendarGroup.CalendarGroupViewSortOrder, CalendarGroup.CalendarInfoProperties)) { queryResult.SeekToCondition(SeekReference.OriginBeginning, CalendarGroup.CalendarSectionFilter); while (flag2) { IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(10000); if (propertyBags.Length == 0) { break; } foreach (IStorePropertyBag storePropertyBag in propertyBags) { if (!CalendarGroup.IsCalendarSection(storePropertyBag)) { flag2 = false; break; } if (CalendarGroup.IsFolderTreeData(storePropertyBag)) { if (CalendarGroup.IsCalendarGroup(storePropertyBag)) { if (flag) { ExTraceGlobals.StorageTracer.TraceDebug <VersionedId, string>(0L, "Unexpected processing calendar group out of order. ItemId: {0}, Subject: {1}", (VersionedId)storePropertyBag.TryGetProperty(ItemSchema.Id), storePropertyBag.GetValueOrDefault <string>(ItemSchema.Subject, string.Empty)); } else { CalendarGroup.AddGroupToList(storePropertyBag, guidToGroupMapping, calendarGroupInfoList); } } else if (CalendarGroup.IsCalendarGroupEntry(storePropertyBag)) { flag = true; CalendarGroup.AddCalendarToList(storePropertyBag, guidToGroupMapping, dictionary, calendarGroupInfoList); } } } } } } return(calendarGroupInfoList); }
private static void AddGroupToList(IStorePropertyBag row, Dictionary <Guid, CalendarGroupInfo> guidToGroupMapping, CalendarGroupInfoList calendarGroups) { CalendarGroupInfo calendarGroupInfoFromRow = CalendarGroup.GetCalendarGroupInfoFromRow(row); if (calendarGroupInfoFromRow == null) { return; } CalendarGroupInfo calendarGroupInfo; if (guidToGroupMapping.TryGetValue(calendarGroupInfoFromRow.GroupClassId, out calendarGroupInfo)) { if (calendarGroupInfo.LastModifiedTime.CompareTo(calendarGroupInfoFromRow.LastModifiedTime) > 0) { calendarGroups.DuplicateNodes.Add(calendarGroupInfoFromRow); return; } guidToGroupMapping[calendarGroupInfoFromRow.GroupClassId] = calendarGroupInfoFromRow; calendarGroups.DuplicateNodes.Add(calendarGroupInfo); calendarGroups.Remove(calendarGroupInfo); if (calendarGroups.DefaultGroups.ContainsKey(calendarGroupInfoFromRow.GroupType)) { calendarGroups.DefaultGroups[calendarGroupInfoFromRow.GroupType] = calendarGroupInfoFromRow; } } else { guidToGroupMapping.Add(calendarGroupInfoFromRow.GroupClassId, calendarGroupInfoFromRow); if (calendarGroupInfoFromRow.GroupType != CalendarGroupType.Normal) { calendarGroups.DefaultGroups.Add(calendarGroupInfoFromRow.GroupType, calendarGroupInfoFromRow); } } calendarGroups.Add(calendarGroupInfoFromRow); }
private static void AddCalendarToList(IStorePropertyBag row, Dictionary <Guid, CalendarGroupInfo> guidToGroupMapping, Dictionary <StoreObjectId, LocalCalendarGroupEntryInfo> calendarIdToGroupEntryMapping, CalendarGroupInfoList calendarGroups) { CalendarGroupEntryInfo calendarGroupEntryInfoFromRow = CalendarGroupEntry.GetCalendarGroupEntryInfoFromRow(row); if (calendarGroupEntryInfoFromRow == null) { return; } CalendarGroupInfo calendarGroupInfo; if (!guidToGroupMapping.TryGetValue(calendarGroupEntryInfoFromRow.ParentGroupClassId, out calendarGroupInfo)) { ExTraceGlobals.StorageTracer.TraceDebug <string, Guid, VersionedId>(0L, "Found a calendar group entry with an invalid parent id. CalendarName: {0}, ParentId: {1}, ItemId: {2}", calendarGroupEntryInfoFromRow.CalendarName, calendarGroupEntryInfoFromRow.ParentGroupClassId, calendarGroupEntryInfoFromRow.Id); return; } LocalCalendarGroupEntryInfo localCalendarGroupEntryInfo = calendarGroupEntryInfoFromRow as LocalCalendarGroupEntryInfo; if (calendarGroupEntryInfoFromRow != null && calendarGroupEntryInfoFromRow.CalendarId != null && calendarGroupEntryInfoFromRow.CalendarId.IsPublicFolderType()) { foreach (CalendarGroupEntryInfo calendarGroupEntryInfo in calendarGroupInfo.Calendars) { if (calendarGroupEntryInfo.CalendarId != null && calendarGroupEntryInfo.CalendarId.Equals(calendarGroupEntryInfoFromRow.CalendarId)) { return; } } } if (localCalendarGroupEntryInfo != null) { LocalCalendarGroupEntryInfo localCalendarGroupEntryInfo2; if (calendarIdToGroupEntryMapping.TryGetValue(localCalendarGroupEntryInfo.CalendarId, out localCalendarGroupEntryInfo2)) { if (localCalendarGroupEntryInfo2.LastModifiedTime.CompareTo(localCalendarGroupEntryInfo.LastModifiedTime) > 0) { calendarGroups.DuplicateNodes.Add(localCalendarGroupEntryInfo); return; } calendarGroups.DuplicateNodes.Add(localCalendarGroupEntryInfo2); guidToGroupMapping[localCalendarGroupEntryInfo2.ParentGroupClassId].Calendars.Remove(localCalendarGroupEntryInfo2); calendarIdToGroupEntryMapping[localCalendarGroupEntryInfo.CalendarId] = localCalendarGroupEntryInfo; } else { calendarIdToGroupEntryMapping.Add(localCalendarGroupEntryInfo.CalendarId, localCalendarGroupEntryInfo); } } calendarGroupInfo.Calendars.Add(calendarGroupEntryInfoFromRow); }