protected override SubscribeResults InternalPerformSubscribe(MailboxSession mailboxSession, SharingContext context) { NetID netID = new NetID(context.MailboxId); long num = checked ((long)netID.ToUInt64()); if (num == 0L) { throw new InvalidOperationException("Invitation does not contain the owner ID."); } Guid guid; if (!Guid.TryParse(context.FolderEwsId, out guid)) { throw new InvalidOperationException("Invitation does not contain the calendar ID."); } using (Folder folder = Folder.Bind(mailboxSession, DefaultFolderType.Root)) { StoreObjectId defaultFolderId = mailboxSession.GetDefaultFolderId(DefaultFolderType.DeletedItems); QueryFilter queryFilter = QueryFilter.AndTogether(new QueryFilter[] { new ComparisonFilter(ComparisonOperator.Equal, CalendarFolderSchema.ConsumerCalendarGuid, guid), new ComparisonFilter(ComparisonOperator.Equal, CalendarFolderSchema.ConsumerCalendarOwnerId, num) }); using (IQueryResult queryResult = folder.IFolderQuery(FolderQueryFlags.DeepTraversal, queryFilter, null, new PropertyDefinition[] { FolderSchema.Id, FolderSchema.DisplayName, StoreObjectSchema.ParentItemId })) { bool flag = true; while (flag) { object[][] rows = queryResult.GetRows(100, out flag); if (rows == null || rows.Length == 0) { break; } foreach (object[] array2 in rows) { StoreObjectId storeObjectId = StoreId.GetStoreObjectId((StoreId)array2[2]); if (!defaultFolderId.Equals(storeObjectId)) { return(new SubscribeResults(context.DataType, context.InitiatorSmtpAddress, context.InitiatorName, context.FolderName, StoreId.GetStoreObjectId((StoreId)rows[0][0]), false, (string)rows[0][1])); } } } } } SubscribeResults result; using (CalendarFolder calendarFolder = CalendarFolder.Create(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Root), StoreObjectType.CalendarFolder)) { calendarFolder[FolderSchema.ExtendedFolderFlags] = (ExtendedFolderFlags.SharedIn | ExtendedFolderFlags.ExclusivelyBound | ExtendedFolderFlags.ExchangeConsumerShareFolder); calendarFolder.DisplayName = (context.FolderName ?? context.InitiatorSmtpAddress); calendarFolder.ConsumerCalendarGuid = guid; calendarFolder.ConsumerCalendarOwnerId = num; calendarFolder.SaveWithUniqueDisplayName(50); calendarFolder.Load(); result = new SubscribeResults(context.DataType, context.InitiatorSmtpAddress, context.InitiatorName, context.FolderName, StoreId.GetStoreObjectId(calendarFolder.Id), true, calendarFolder.DisplayName); } return(result); }