示例#1
0
 internal HierarchySyncOperations(FolderHierarchySync folderHierarchySync, IDictionary changes, bool moreAvailable)
 {
     this.moreAvailable = moreAvailable;
     this.changes       = new List <HierarchySyncOperation>(changes.Keys.Count);
     foreach (object obj in changes.Values)
     {
         FolderManifestEntry    manifestEntry          = (FolderManifestEntry)obj;
         HierarchySyncOperation hierarchySyncOperation = new HierarchySyncOperation();
         hierarchySyncOperation.Bind(folderHierarchySync, manifestEntry);
         this.changes.Add(hierarchySyncOperation);
     }
 }
示例#2
0
 internal Folder GetFolder(FolderManifestEntry serverManifestEntry, params PropertyDefinition[] prefetchProperties)
 {
     if (ChangeType.Delete != serverManifestEntry.ChangeType)
     {
         PropertyDefinition[] array;
         if (prefetchProperties != null)
         {
             array = new PropertyDefinition[prefetchProperties.Length + 1];
             prefetchProperties.CopyTo(array, 1);
         }
         else
         {
             array = new PropertyDefinition[1];
         }
         array[0] = InternalSchema.ChangeKey;
         Folder folder = Folder.Bind(this.storeSession, serverManifestEntry.ItemId, array);
         serverManifestEntry.ChangeKey = folder.GetValueOrDefault <byte[]>(InternalSchema.ChangeKey);
         return(folder);
     }
     throw new InvalidOperationException("Cannot GetFolder() on an folder that has been deleted");
 }
示例#3
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);
        }
        private Dictionary <string, StoreObjectId> ProcessCommand(Dictionary <string, FolderNode> folders, Dictionary <string, StoreObjectType> contentTypeTable)
        {
            HierarchySyncOperations hierarchySyncOperations = this.folderHierarchySync.EnumerateServerOperations();

            if (hierarchySyncOperations == null)
            {
                throw new ApplicationException("EnumerateServerOperations returned null!");
            }
            this.serverManifest = ((GenericDictionaryData <StoreObjectIdData, StoreObjectId, FolderManifestEntry>) this.syncState[SyncStateProp.CurServerManifest]).Data;
            if (this.serverManifest == null)
            {
                throw new ApplicationException("Server Manifest returned null!");
            }
            Dictionary <string, StoreObjectId> dictionary = new Dictionary <string, StoreObjectId>();

            if (folders != null)
            {
                for (int i = 0; i < hierarchySyncOperations.Count; i++)
                {
                    HierarchySyncOperation hierarchySyncOperation = hierarchySyncOperations[i];
                    using (Folder folder = hierarchySyncOperation.GetFolder())
                    {
                        string oldIdFromNewId = FolderSyncUpgrade.GetOldIdFromNewId(folder.Id.ObjectId.ProviderLevelItemId);
                        if (oldIdFromNewId == null)
                        {
                            throw new ApplicationException("The new Id is invalid!");
                        }
                        FolderNode folderNode;
                        if (folders.TryGetValue(oldIdFromNewId, out folderNode))
                        {
                            FolderSyncUpgrade.StoreType(folderNode, folder.Id.ObjectId, contentTypeTable);
                            folders.Remove(oldIdFromNewId);
                            dictionary.Add(folderNode.ServerId, folder.Id.ObjectId);
                            FolderManifestEntry folderManifestEntry = this.serverManifest[folder.Id.ObjectId];
                            if (FolderSyncUpgrade.GetOldIdFromNewId(folderManifestEntry.ParentId.ProviderLevelItemId).CompareTo(this.PadOldId(folderNode.ParentId)) != 0 || folder.DisplayName.CompareTo(folderNode.DisplayName) != 0)
                            {
                                folderManifestEntry.ChangeKey = new byte[]
                                {
                                    1
                                };
                            }
                        }
                        else
                        {
                            if (FolderSyncUpgrade.GetOldIdFromNewId(folder.Id.ObjectId.ProviderLevelItemId) == null)
                            {
                                throw new ApplicationException("The new Id is invalid!");
                            }
                            string key = this.DepadNewId(FolderSyncUpgrade.GetOldIdFromNewId(folder.Id.ObjectId.ProviderLevelItemId));
                            dictionary.Add(key, folder.Id.ObjectId);
                            if (folder.ClassName.Equals("IPF.Appointment"))
                            {
                                contentTypeTable[key] = StoreObjectType.CalendarFolder;
                            }
                            else if (folder.ClassName.Equals("IPF.Contact"))
                            {
                                contentTypeTable[key] = StoreObjectType.ContactsFolder;
                            }
                            else
                            {
                                contentTypeTable[key] = StoreObjectType.Folder;
                            }
                            this.serverManifest.Remove(folder.Id.ObjectId);
                        }
                    }
                }
                IEnumerator enumerator = folders.GetEnumerator();
                enumerator.Reset();
                while (enumerator.MoveNext())
                {
                    object          obj             = enumerator.Current;
                    FolderNode      value           = ((KeyValuePair <string, FolderNode>)obj).Value;
                    UnicodeEncoding unicodeEncoding = new UnicodeEncoding();
                    byte[]          bytes           = unicodeEncoding.GetBytes(this.PadOldId(value.ServerId));
                    StoreObjectId   storeObjectId   = StoreObjectId.FromProviderSpecificId(bytes, StoreObjectType.Mailbox);
                    dictionary.Add(value.ServerId, storeObjectId);
                    FolderSyncUpgrade.StoreType(value, storeObjectId, contentTypeTable);
                    FolderManifestEntry folderManifestEntry2 = new FolderManifestEntry(storeObjectId);
                    folderManifestEntry2.ChangeKey = new byte[]
                    {
                        1
                    };
                    folderManifestEntry2.ChangeType = ChangeType.Add;
                    StoreObjectId storeObjectId2;
                    dictionary.TryGetValue(value.ParentId, out storeObjectId2);
                    if (storeObjectId2 == null)
                    {
                        if (value.ParentId.CompareTo("0") == 0)
                        {
                            folderManifestEntry2.ParentId = this.rootId;
                        }
                        else
                        {
                            folderManifestEntry2.ParentId = StoreObjectId.FromProviderSpecificId(unicodeEncoding.GetBytes(this.PadOldId(value.ParentId)));
                        }
                    }
                    else
                    {
                        folderManifestEntry2.ParentId = storeObjectId2;
                    }
                    this.serverManifest[storeObjectId] = folderManifestEntry2;
                }
            }
            else
            {
                for (int j = 0; j < hierarchySyncOperations.Count; j++)
                {
                    HierarchySyncOperation hierarchySyncOperation2 = hierarchySyncOperations[j];
                    using (Folder folder2 = hierarchySyncOperation2.GetFolder())
                    {
                        string oldIdFromNewId2 = FolderSyncUpgrade.GetOldIdFromNewId(folder2.Id.ObjectId.ProviderLevelItemId);
                        if (oldIdFromNewId2 == null)
                        {
                            throw new ApplicationException("The new Id is invalid!");
                        }
                        string key2 = this.DepadNewId(oldIdFromNewId2);
                        dictionary.Add(key2, folder2.Id.ObjectId);
                        if (folder2.ClassName.Equals("IPF.Appointment"))
                        {
                            contentTypeTable[key2] = StoreObjectType.CalendarFolder;
                        }
                        else if (folder2.ClassName.Equals("IPF.Contact"))
                        {
                            contentTypeTable[key2] = StoreObjectType.ContactsFolder;
                        }
                        else
                        {
                            contentTypeTable[key2] = StoreObjectType.Folder;
                        }
                    }
                }
            }
            return(dictionary);
        }
 internal void Bind(FolderHierarchySync folderHierarchySync, FolderManifestEntry manifestEntry)
 {
     this.manifestEntry       = manifestEntry;
     this.folderHierarchySync = folderHierarchySync;
 }