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); }
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 CalendarGroup CreateMyCalendarsGroup(MailboxSession session) { CalendarGroup calendarGroup = null; using (DisposeGuard disposeGuard = default(DisposeGuard)) { calendarGroup = CalendarGroup.InternalCreateGroup(session, CalendarGroupType.MyCalendars); disposeGuard.Add <CalendarGroup>(calendarGroup); using (CalendarGroupEntry calendarGroupEntry = CalendarGroupEntry.Create(session, session.GetDefaultFolderId(DefaultFolderType.Calendar), FolderTreeData.MyFoldersClassId, calendarGroup.GroupName)) { calendarGroupEntry.CalendarName = ClientStrings.Calendar.ToString(session.InternalCulture); ConflictResolutionResult conflictResolutionResult = calendarGroupEntry.Save(SaveMode.NoConflictResolution); if (conflictResolutionResult.SaveStatus != SaveResult.Success) { ExTraceGlobals.StorageTracer.TraceWarning <SmtpAddress>(0L, "Unable to associate default calendar with the MyCalendars group for user: {0}. Attempting to delete default calendars group.", session.MailboxOwner.MailboxInfo.PrimarySmtpAddress); AggregateOperationResult aggregateOperationResult = session.Delete(DeleteItemFlags.HardDelete, new StoreId[] { calendarGroup.Id }); if (aggregateOperationResult.OperationResult != OperationResult.Succeeded) { ExTraceGlobals.StorageTracer.TraceWarning <SmtpAddress>(0L, "Unable to delete default calendar group after failing to add the default calendar to it. User: {0}", session.MailboxOwner.MailboxInfo.PrimarySmtpAddress); } throw new DefaultCalendarNodeCreationException(); } } disposeGuard.Success(); } return(calendarGroup); }
private void LoadChildNodesCollection(IStorePropertyBag[] rows, int startIndex) { for (int i = startIndex; i < rows.Length; i++) { IStorePropertyBag storePropertyBag = rows[i]; if (CalendarGroup.IsCalendarSection(storePropertyBag) && CalendarGroup.IsFolderTreeData(storePropertyBag) && CalendarGroup.IsCalendarGroupEntry(storePropertyBag)) { byte[] valueOrDefault = storePropertyBag.GetValueOrDefault <byte[]>(FolderTreeDataSchema.ParentGroupClassId, null); if (valueOrDefault == null || valueOrDefault.Length != 16) { ExTraceGlobals.StorageTracer.TraceDebug <int>(0L, "Found CalendarGroupEntry with invalid parent group id. ArrayLength: {0}", (valueOrDefault == null) ? -1 : valueOrDefault.Length); } else { Guid g = new Guid(valueOrDefault); if (this.groupClassId.Equals(g)) { CalendarGroupEntryInfo calendarGroupEntryInfoFromRow = CalendarGroupEntry.GetCalendarGroupEntryInfoFromRow(storePropertyBag); if (calendarGroupEntryInfoFromRow != null) { this.children.Add(calendarGroupEntryInfoFromRow); } } } } } this.hasLoadedCalendarsCollection = true; }
public static CalendarGroup Create(MailboxSession session) { Util.ThrowOnNullArgument(session, "session"); CalendarGroup calendarGroup = ItemBuilder.CreateNewItem <CalendarGroup>(session, session.GetDefaultFolderId(DefaultFolderType.CommonViews), ItemCreateInfo.CalendarGroupInfo, CreateMessageType.Associated); calendarGroup.MailboxSession = session; return(calendarGroup); }
public static CalendarGroup Bind(MailboxSession session, StoreId storeId, ICollection <PropertyDefinition> propsToReturn = null) { Util.ThrowOnNullArgument(session, "session"); Util.ThrowOnNullArgument(storeId, "storeId"); CalendarGroup calendarGroup = ItemBuilder.ItemBind <CalendarGroup>(session, storeId, CalendarGroupSchema.Instance, propsToReturn); calendarGroup.MailboxSession = session; return(calendarGroup); }
public static CalendarGroup Bind(MailboxSession session, CalendarGroupType defaultGroupType) { EnumValidator.ThrowIfInvalid <CalendarGroupType>(defaultGroupType, new CalendarGroupType[] { CalendarGroupType.MyCalendars, CalendarGroupType.OtherCalendars, CalendarGroupType.PeoplesCalendars }); return(CalendarGroup.Bind(session, CalendarGroup.GetGroupGuidFromType(defaultGroupType))); }
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); }
protected override void OnBeforeSave() { base.OnBeforeSave(); if (base.IsNew) { bool flag; byte[] nodeBefore = FolderTreeData.GetOrdinalValueOfFirstMatchingNode(base.MailboxSession, CalendarGroup.FindLastGroupOrdinalSortOrder, (IStorePropertyBag row) => CalendarGroup.IsFolderTreeData(row) && CalendarGroup.IsCalendarSection(row) && CalendarGroup.IsCalendarGroup(row), CalendarGroup.CalendarInfoProperties, out flag); if (flag && !FolderTreeData.MyFoldersClassId.Equals(this.GroupClassId)) { using (CalendarGroup calendarGroup = CalendarGroup.CreateMyCalendarsGroup(base.MailboxSession)) { nodeBefore = calendarGroup.NodeOrdinal; } } base.SetNodeOrdinalInternal(nodeBefore, null); } }
private static CalendarGroupInfo GetCalendarGroupInfoFromRow(IStorePropertyBag row) { VersionedId id = (VersionedId)row.TryGetProperty(ItemSchema.Id); byte[] valueOrDefault = row.GetValueOrDefault <byte[]>(CalendarGroupSchema.GroupClassId, null); string valueOrDefault2 = row.GetValueOrDefault <string>(ItemSchema.Subject, string.Empty); byte[] valueOrDefault3 = row.GetValueOrDefault <byte[]>(FolderTreeDataSchema.Ordinal, null); ExDateTime valueOrDefault4 = row.GetValueOrDefault <ExDateTime>(StoreObjectSchema.LastModifiedTime, ExDateTime.MinValue); Guid safeGuidFromByteArray = FolderTreeData.GetSafeGuidFromByteArray(valueOrDefault); if (safeGuidFromByteArray.Equals(Guid.Empty)) { ExTraceGlobals.StorageTracer.TraceDebug <int>(0L, "Found calendar group with invalid group class id. ArrayLength: {0}", (valueOrDefault == null) ? -1 : valueOrDefault.Length); return(null); } return(new CalendarGroupInfo(valueOrDefault2, id, safeGuidFromByteArray, CalendarGroup.GetGroupTypeFromGuid(safeGuidFromByteArray), valueOrDefault3, valueOrDefault4)); }
private static CalendarGroup InternalCreateGroup(MailboxSession session, CalendarGroupType groupType) { CalendarGroup calendarGroup; using (DisposeGuard disposeGuard = default(DisposeGuard)) { calendarGroup = CalendarGroup.CreateDefaultGroup(groupType, session); disposeGuard.Add <CalendarGroup>(calendarGroup); ConflictResolutionResult conflictResolutionResult = calendarGroup.Save(SaveMode.NoConflictResolution); if (conflictResolutionResult.SaveStatus != SaveResult.Success) { ExTraceGlobals.StorageTracer.TraceWarning <CalendarGroupType, SmtpAddress>(0L, "Unable to create group of type {0} for user: {1}", groupType, session.MailboxOwner.MailboxInfo.PrimarySmtpAddress); throw new DefaultCalendarGroupCreationException(groupType.ToString()); } calendarGroup.Load(); disposeGuard.Success(); } return(calendarGroup); }
private static CalendarGroup CreateDefaultGroup(CalendarGroupType groupType, MailboxSession session) { CalendarGroup calendarGroup = CalendarGroup.Create(session); Guid groupGuidFromType = CalendarGroup.GetGroupGuidFromType(groupType); string groupName = string.Empty; switch (groupType) { case CalendarGroupType.MyCalendars: groupName = ClientStrings.MyCalendars.ToString(session.InternalPreferedCulture); break; case CalendarGroupType.OtherCalendars: groupName = ClientStrings.OtherCalendars.ToString(session.InternalPreferedCulture); break; case CalendarGroupType.PeoplesCalendars: groupName = ClientStrings.PeoplesCalendars.ToString(session.InternalPreferedCulture); break; } calendarGroup.GroupClassId = groupGuidFromType; calendarGroup.GroupName = groupName; return(calendarGroup); }
internal static bool IsCalendarGroupEntryForCalendar(IStorePropertyBag row, StoreObjectId calendarId) { byte[] valueOrDefault = row.GetValueOrDefault <byte[]>(CalendarGroupEntrySchema.NodeEntryId, null); return(CalendarGroup.IsCalendarGroupEntry(row) && Util.CompareByteArray(calendarId.ProviderLevelItemId, valueOrDefault)); }
internal static bool IsCalendarGroup(IStorePropertyBag row, Guid groupId) { byte[] valueOrDefault = row.GetValueOrDefault <byte[]>(CalendarGroupSchema.GroupClassId, null); return(CalendarGroup.IsCalendarGroup(row) && Util.CompareByteArray(groupId.ToByteArray(), valueOrDefault)); }
public static VersionedId GetGroupEntryIdFromFolderId(MailboxSession session, StoreObjectId calendarFolderObjectId) { return(FolderTreeData.FindFirstRowMatchingFilter(session, CalendarGroup.CalendarInfoProperties, (IStorePropertyBag row) => CalendarGroup.IsFolderTreeData(row) && CalendarGroup.IsCalendarSection(row) && CalendarGroup.IsCalendarGroupEntryForCalendar(row, calendarFolderObjectId))); }
public ICalendarGroup CreateCalendarGroup(IMailboxSession session) { return(CalendarGroup.Create((MailboxSession)session)); }
public static CalendarGroupEntry Create(MailboxSession session, StoreObjectId calendarFolderId, CalendarGroup parentGroup) { Util.ThrowOnNullArgument(parentGroup, "parentGroup"); CalendarGroupEntry calendarGroupEntry = CalendarGroupEntry.Create(session, calendarFolderId, parentGroup.GroupClassId, parentGroup.GroupName); calendarGroupEntry.parentGroup = parentGroup; return(calendarGroupEntry); }
public static CalendarGroupEntry Create(MailboxSession session, CalendarFolder calendarFolder, CalendarGroup parentGroup) { Util.ThrowOnNullArgument(parentGroup, "parentGroup"); Util.ThrowOnNullArgument(calendarFolder, "calendarFolder"); CalendarGroupEntry calendarGroupEntry = CalendarGroupEntry.Create(session, calendarFolder.Id.ObjectId, parentGroup.GroupClassId, parentGroup.GroupName); FolderTreeDataFlags folderTreeDataFlags = CalendarGroupEntry.ReadSharingFlags(calendarFolder); bool flag = !session.MailboxGuid.Equals(((MailboxSession)calendarFolder.Session).MailboxGuid); if (flag) { calendarGroupEntry[FolderTreeDataSchema.Type] = FolderTreeDataType.SharedFolder; calendarGroupEntry.StoreEntryId = Microsoft.Exchange.Data.Storage.StoreEntryId.ToProviderStoreEntryId(((MailboxSession)calendarFolder.Session).MailboxOwner); calendarGroupEntry.CalendarRecordKey = (byte[])calendarFolder.TryGetProperty(StoreObjectSchema.RecordKey); } else { folderTreeDataFlags |= FolderTreeDataFlags.IsDefaultStore; } calendarGroupEntry[FolderTreeDataSchema.FolderTreeDataFlags] = folderTreeDataFlags; return(calendarGroupEntry); }
public static CalendarGroupEntry Create(MailboxSession session, string legacyDistinguishedName, CalendarGroup parentGroup) { Util.ThrowOnNullOrEmptyArgument(legacyDistinguishedName, "legacyDistinguishedName"); CalendarGroupEntry calendarGroupEntry = CalendarGroupEntry.Create(session, parentGroup.GroupClassId, parentGroup.GroupName); calendarGroupEntry[FolderTreeDataSchema.Type] = FolderTreeDataType.SharedFolder; calendarGroupEntry[FolderTreeDataSchema.FolderTreeDataFlags] = 0; calendarGroupEntry.SharerAddressBookEntryId = AddressBookEntryId.MakeAddressBookEntryID(legacyDistinguishedName, false); calendarGroupEntry.UserAddressBookStoreEntryId = Microsoft.Exchange.Data.Storage.StoreEntryId.ToProviderStoreEntryId(session.MailboxOwner); return(calendarGroupEntry); }
protected override void OnBeforeSave() { base.OnBeforeSave(); if (base.IsNew) { if (Guid.Empty.Equals(this.ParentGroupClassId)) { throw new NotSupportedException("A new calendar group entry needs to have its ParentGroupClassId set."); } byte[] nodeBefore = null; if (this.parentGroup != null) { ReadOnlyCollection <CalendarGroupEntryInfo> childCalendars = this.parentGroup.GetChildCalendars(); if (childCalendars.Count > 0) { nodeBefore = childCalendars[childCalendars.Count - 1].Ordinal; } } else { bool flag; nodeBefore = FolderTreeData.GetOrdinalValueOfFirstMatchingNode(base.MailboxSession, CalendarGroupEntry.FindLastCalendarOrdinalSortOrder, (IStorePropertyBag row) => CalendarGroup.IsFolderTreeData(row) && CalendarGroup.IsCalendarSection(row) && CalendarGroup.IsCalendarInGroup(row, this.ParentGroupClassId), CalendarGroup.CalendarInfoProperties, out flag); } base.SetNodeOrdinalInternal(nodeBefore, null); } }
public CalendarGroupInfo GetCalendarGroupInfo() { return(CalendarGroup.GetCalendarGroupInfoFromRow(this)); }
internal static bool IsCalendarInGroup(IStorePropertyBag row, Guid groupClassId) { byte[] valueOrDefault = row.GetValueOrDefault <byte[]>(FolderTreeDataSchema.ParentGroupClassId, null); return(CalendarGroup.IsCalendarGroupEntry(row) && Util.CompareByteArray(groupClassId.ToByteArray(), valueOrDefault)); }
public ICalendarGroup BindToCalendarGroup(IMailboxSession session, Guid groupClassId) { return(CalendarGroup.Bind((MailboxSession)session, groupClassId)); }
public ICalendarGroup BindToCalendarGroup(IMailboxSession session, CalendarGroupType defaultGroupType) { return(CalendarGroup.Bind((MailboxSession)session, defaultGroupType)); }
public ICalendarGroup BindToCalendarGroup(IMailboxSession session, StoreId storeId, ICollection <PropertyDefinition> propsToReturn = null) { return(CalendarGroup.Bind((MailboxSession)session, storeId, propsToReturn)); }
public static CalendarGroup Bind(MailboxSession session, Guid groupClassId) { Util.ThrowOnNullArgument(session, "session"); Util.ThrowOnNullArgument(groupClassId, "groupClassId"); if (groupClassId.Equals(Guid.Empty)) { throw new ArgumentException("Invalid GroupClassId", "groupClassId"); } CalendarGroup calendarGroup = null; bool flag = true; bool flag2 = false; CalendarGroup result; 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 (flag) { IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(10000); if (propertyBags.Length == 0) { break; } for (int i = 0; i < propertyBags.Length; i++) { IStorePropertyBag storePropertyBag = propertyBags[i]; if (!CalendarGroup.IsCalendarSection(storePropertyBag)) { flag = false; break; } if (CalendarGroup.IsFolderTreeData(storePropertyBag)) { if (!flag2 && CalendarGroup.IsCalendarGroup(storePropertyBag, groupClassId)) { flag2 = true; VersionedId storeId = (VersionedId)storePropertyBag.TryGetProperty(ItemSchema.Id); calendarGroup = CalendarGroup.Bind(session, storeId, null); } if (flag2) { calendarGroup.LoadChildNodesCollection(propertyBags, i); break; } } } } if (flag2) { result = calendarGroup; } else if (FolderTreeData.MyFoldersClassId.Equals(groupClassId)) { result = CalendarGroup.CreateMyCalendarsGroup(session); } else { if (!FolderTreeData.OtherFoldersClassId.Equals(groupClassId)) { throw new ObjectNotFoundException(ServerStrings.ExItemNotFound); } result = CalendarGroup.InternalCreateGroup(session, CalendarGroupType.OtherCalendars); } } } return(result); }
public CalendarGroupInfoList GetCalendarGroupsView(IMailboxSession session) { return(CalendarGroup.GetCalendarGroupsView((MailboxSession)session)); }