Beispiel #1
0
        protected override SubscribeResults InternalPerformSubscribe(MailboxSession mailboxSession, SharingContext context)
        {
            ADRecipient      mailboxOwner             = DirectoryHelper.ReadADRecipient(mailboxSession.MailboxOwner.MailboxInfo.MailboxGuid, mailboxSession.MailboxOwner.MailboxInfo.IsArchive, mailboxSession.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid));
            SharedFolderData matchingSharedFolderData = this.GetMatchingSharedFolderData(context, mailboxOwner);

            if (context.InitiatorSmtpAddress == null)
            {
                throw new InvalidSharingDataException("InitiatorSmtpAddress", string.Empty);
            }
            IdAndName     idAndName     = null;
            StoreObjectId storeObjectId = null;

            using (SharingSubscriptionManager sharingSubscriptionManager = new SharingSubscriptionManager(mailboxSession))
            {
                SharingSubscriptionData sharingSubscriptionData = this.CreateSubscriptionData(mailboxOwner, context, matchingSharedFolderData);
                SharingFolderManager    sharingFolderManager    = new SharingFolderManager(mailboxSession);
                SharingSubscriptionData existing = sharingSubscriptionManager.GetExisting(sharingSubscriptionData.Key);
                if (existing != null)
                {
                    existing.CopyFrom(sharingSubscriptionData);
                }
                SharingSubscriptionData sharingSubscriptionData2 = existing ?? sharingSubscriptionData;
                idAndName = sharingFolderManager.EnsureFolder(sharingSubscriptionData2);
                if (sharingSubscriptionData2.LocalFolderId == null || !sharingSubscriptionData2.LocalFolderId.Equals(idAndName.Id))
                {
                    storeObjectId = (sharingSubscriptionData2.LocalFolderId = idAndName.Id);
                }
                SharingSubscriptionData sharingSubscriptionData3 = sharingSubscriptionManager.CreateOrUpdate(sharingSubscriptionData2, false);
                if (!sharingSubscriptionData2.LocalFolderId.Equals(sharingSubscriptionData3.LocalFolderId))
                {
                    idAndName = sharingFolderManager.GetFolder(sharingSubscriptionData3);
                }
            }
            return(new SubscribeResultsExternal(context.DataType, context.InitiatorSmtpAddress, context.InitiatorName, context.FolderName, matchingSharedFolderData.FolderId, idAndName.Id, storeObjectId != null, idAndName.Name));
        }
Beispiel #2
0
        private void AddServerManifestEntry(IStorePropertyBag propertyBag, bool excludeHiddenFolders, Dictionary <StoreObjectId, FolderStateEntry> serverFolders, ISyncLogger syncLogger)
        {
            SharingSubscriptionData[] array = null;
            bool flag = false;

            if (FolderHierarchySync.TryGetPropertyFromBag <bool>(propertyBag, InternalSchema.IsHidden, syncLogger, out flag) && excludeHiddenFolders && flag)
            {
                return;
            }
            VersionedId   versionedId;
            StoreObjectId parentId;

            byte[] array2;
            if (!FolderHierarchySync.TryGetPropertyFromBag <VersionedId>(propertyBag, FolderSchema.Id, syncLogger, out versionedId) || !FolderHierarchySync.TryGetPropertyFromBag <StoreObjectId>(propertyBag, StoreObjectSchema.ParentItemId, syncLogger, out parentId) || !FolderHierarchySync.TryGetPropertyFromBag <byte[]>(propertyBag, StoreObjectSchema.ChangeKey, syncLogger, out array2))
            {
                ExTraceGlobals.SyncTracer.Information((long)this.GetHashCode(), "Storage.FolderHierarchySync.AddServerManifestEntry. \nFolder is missing properties. Id , ParentId or ChangeKey");
                return;
            }
            int num = -1;

            serverFolders[versionedId.ObjectId] = null;
            FolderStateEntry folderStateEntry;

            if (this.ClientState.TryGetValue(versionedId.ObjectId, out folderStateEntry) && ArrayComparer <byte> .Comparer.Equals(folderStateEntry.ChangeKey, array2))
            {
                return;
            }
            if (this.changeTrackingDelegate != null)
            {
                num = this.changeTrackingDelegate(this.storeSession, versionedId.ObjectId, propertyBag);
                if (folderStateEntry != null && num == folderStateEntry.ChangeTrackingHash)
                {
                    folderStateEntry.ChangeKey = array2;
                    return;
                }
            }
            FolderManifestEntry folderManifestEntry = new FolderManifestEntry(versionedId.ObjectId);
            string className;

            FolderHierarchySync.TryGetPropertyFromBag <string>(propertyBag, StoreObjectSchema.ContainerClass, syncLogger, out className);
            folderManifestEntry.ChangeType         = ((folderStateEntry != null) ? ChangeType.Change : ChangeType.Add);
            folderManifestEntry.ChangeKey          = array2;
            folderManifestEntry.ParentId           = parentId;
            folderManifestEntry.ChangeTrackingHash = num;
            folderManifestEntry.Hidden             = flag;
            folderManifestEntry.ClassName          = className;
            if (folderManifestEntry.ClassName == null)
            {
                folderManifestEntry.ClassName = string.Empty;
            }
            folderManifestEntry.DisplayName = (propertyBag[FolderSchema.DisplayName] as string);
            if (folderManifestEntry.DisplayName == null)
            {
                folderManifestEntry.DisplayName = string.Empty;
            }
            int num2;

            if (!FolderHierarchySync.TryGetPropertyFromBag <int>(propertyBag, FolderSchema.ExtendedFolderFlags, syncLogger, out num2))
            {
                num2 = 0;
            }
            bool flag2 = (num2 & 1073741824) != 0;

            if (flag2)
            {
                if (array == null)
                {
                    using (SharingSubscriptionManager sharingSubscriptionManager = new SharingSubscriptionManager(this.storeSession))
                    {
                        array = sharingSubscriptionManager.GetAll();
                    }
                }
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i].LocalFolderId.Equals(folderManifestEntry.ItemId))
                    {
                        folderManifestEntry.Permissions = SyncPermissions.Readonly;
                        folderManifestEntry.Owner       = array[i].SharerIdentity;
                        break;
                    }
                }
            }
            this.ServerManifest.Add(folderManifestEntry.ItemId, folderManifestEntry);
        }