public static CalendarGroupEntry BindFromCalendarFolder(MailboxSession session, StoreObjectId calendarFolderObjectId) { Util.ThrowOnNullArgument(session, "session"); Util.ThrowOnNullArgument(calendarFolderObjectId, "calendarFolderObjectId"); if (calendarFolderObjectId.ObjectType != StoreObjectType.CalendarFolder && calendarFolderObjectId.ObjectType != StoreObjectType.Folder) { throw new ArgumentException("StoreObject is not a calendar folder.", "calendarFolderObjectId"); } VersionedId groupEntryIdFromFolderId = CalendarGroupEntry.GetGroupEntryIdFromFolderId(session, calendarFolderObjectId); if (groupEntryIdFromFolderId == null) { if (calendarFolderObjectId.Equals(session.GetDefaultFolderId(DefaultFolderType.Calendar))) { using (CalendarGroup calendarGroup = CalendarGroup.Bind(session, FolderTreeData.MyFoldersClassId)) { ReadOnlyCollection <CalendarGroupEntryInfo> childCalendars = calendarGroup.GetChildCalendars(); foreach (CalendarGroupEntryInfo calendarGroupEntryInfo in childCalendars) { LocalCalendarGroupEntryInfo localCalendarGroupEntryInfo = calendarGroupEntryInfo as LocalCalendarGroupEntryInfo; if (localCalendarGroupEntryInfo != null && calendarFolderObjectId.Equals(localCalendarGroupEntryInfo.CalendarId)) { return(CalendarGroupEntry.Bind(session, calendarGroupEntryInfo.Id, null)); } } } } throw new ObjectNotFoundException(ServerStrings.ExItemNotFound); } return(CalendarGroupEntry.Bind(session, groupEntryIdFromFolderId, null)); }
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); }