Example #1
0
 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;
 }
Example #2
0
        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));
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        public static CalendarGroupEntry Bind(MailboxSession session, StoreId storeId, ICollection <PropertyDefinition> propsToReturn = null)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(storeId, "storeId");
            CalendarGroupEntry calendarGroupEntry = ItemBuilder.ItemBind <CalendarGroupEntry>(session, storeId, CalendarGroupEntrySchema.Instance, propsToReturn);

            calendarGroupEntry.MailboxSession = session;
            return(calendarGroupEntry);
        }
Example #6
0
        internal static CalendarGroupEntry Create(MailboxSession session, Guid parentGroupClassId, string parentGroupName)
        {
            Util.ThrowOnNullArgument(session, "session");
            CalendarGroupEntry calendarGroupEntry = ItemBuilder.CreateNewItem <CalendarGroupEntry>(session, session.GetDefaultFolderId(DefaultFolderType.CommonViews), ItemCreateInfo.CalendarGroupEntryInfo, CreateMessageType.Associated);

            calendarGroupEntry.MailboxSession     = session;
            calendarGroupEntry.ParentGroupClassId = parentGroupClassId;
            calendarGroupEntry.ParentGroupName    = parentGroupName;
            return(calendarGroupEntry);
        }
Example #7
0
        public ICalendarGroupEntry BindToCalendarGroupEntry(IMailboxSession session, StoreId id)
        {
            StoreObjectId storeObjectId = StoreId.GetStoreObjectId(id);

            if (!storeObjectId.IsFolderId)
            {
                return(CalendarGroupEntry.Bind((MailboxSession)session, id, null));
            }
            return(CalendarGroupEntry.BindFromCalendarFolder((MailboxSession)session, storeObjectId));
        }
Example #8
0
        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);
        }
Example #9
0
        internal static CalendarGroupEntry Create(MailboxSession session, StoreObjectId calendarFolderId, Guid parentGroupClassId, string parentGroupName)
        {
            Util.ThrowOnNullArgument(calendarFolderId, "calendarFolderId");
            if (calendarFolderId.ObjectType != StoreObjectType.CalendarFolder)
            {
                throw new NotSupportedException("A calendar group entry can only be associated with a storeobject of type calendar folder.");
            }
            CalendarGroupEntry calendarGroupEntry = CalendarGroupEntry.Create(session, parentGroupClassId, parentGroupName);

            calendarGroupEntry.CalendarId   = calendarFolderId;
            calendarGroupEntry.StoreEntryId = Microsoft.Exchange.Data.Storage.StoreEntryId.ToProviderStoreEntryId(session.MailboxOwner);
            return(calendarGroupEntry);
        }
Example #10
0
        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);
        }
Example #11
0
        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);
        }
Example #12
0
 public CalendarGroupEntryInfo GetCalendarGroupEntryInfo()
 {
     return(CalendarGroupEntry.GetCalendarGroupEntryInfoFromRow(this));
 }
Example #13
0
 public ICalendarGroupEntry CreateCalendarGroupEntry(IMailboxSession session, StoreObjectId calendarFolderId, ICalendarGroup parentGroup)
 {
     return(CalendarGroupEntry.Create((MailboxSession)session, calendarFolderId, (CalendarGroup)parentGroup));
 }
Example #14
0
 public ICalendarGroupEntry CreateCalendarGroupEntry(IMailboxSession session, string legacyDistinguishedName, ICalendarGroup parentGroup)
 {
     return(CalendarGroupEntry.Create((MailboxSession)session, legacyDistinguishedName, (CalendarGroup)parentGroup));
 }