public ManifestCallbackStatus Change(byte[] entryId, byte[] sourceKey, byte[] changeKey, byte[] changeList, DateTime lastModifiedTime, ManifestChangeType changeType, bool associated, PropValue[] properties) { EnumValidator.ThrowIfInvalid <ManifestChangeType>(changeType, "changeType"); if (ExTraceGlobals.SyncTracer.IsTraceEnabled(TraceType.InfoTrace)) { this.TraceChangeChangeCallbackProps(entryId, sourceKey, changeKey, changeList, lastModifiedTime, changeType, associated, properties); } int? num = null; string text = null; bool read = false; ConversationId conversationId = null; bool firstMessageInConversation = false; ExDateTime? filterDate = null; foreach (PropValue propValue in properties) { if (!propValue.IsError()) { PropTag propTag = propValue.PropTag; if (propTag <= PropTag.MessageDeliveryTime) { if (propTag != PropTag.MessageClass) { ConversationIndex index; if (propTag != PropTag.ConversationIndex) { if (propTag == PropTag.MessageDeliveryTime) { if (propValue.PropType == PropType.SysTime) { filterDate = new ExDateTime?((ExDateTime)propValue.GetDateTime()); } } } else if (propValue.PropType == PropType.Binary && ConversationIndex.TryCreate(propValue.GetBytes(), out index) && index != ConversationIndex.Empty && index.Components != null && index.Components.Count == 1) { firstMessageInConversation = true; } } else if (propValue.PropType == PropType.String) { text = propValue.GetString(); } } else if (propTag != PropTag.MessageFlags) { if (propTag != PropTag.InternetArticleNumber) { if (propTag == PropTag.ConversationId) { if (propValue.PropType == PropType.Binary) { conversationId = ConversationId.Create(propValue.GetBytes()); } } } else { if (propValue.PropType != PropType.Int) { return(ManifestCallbackStatus.Continue); } num = new int?(propValue.GetInt()); } } else if (propValue.PropType == PropType.Int) { MessageFlags @int = (MessageFlags)propValue.GetInt(); read = ((@int & MessageFlags.IsRead) == MessageFlags.IsRead); } } } if (changeType == ManifestChangeType.Add || changeType == ManifestChangeType.Change) { if (num == null) { return(ManifestCallbackStatus.Continue); } StoreObjectId id = StoreObjectId.FromProviderSpecificId(entryId, (text == null) ? StoreObjectType.Unknown : ObjectClass.GetObjectType(text)); MailboxSyncItemId mailboxSyncItemId = MailboxSyncItemId.CreateForNewItem(id); MailboxSyncWatermark mailboxSyncWatermark = MailboxSyncWatermark.CreateForSingleItem(); mailboxSyncWatermark.UpdateWithChangeNumber(num.Value, read); ServerManifestEntry serverManifestEntry = this.mailboxSyncProvider.CreateItemChangeManifestEntry(mailboxSyncItemId, mailboxSyncWatermark); serverManifestEntry.IsNew = (changeType == ManifestChangeType.Add); serverManifestEntry.MessageClass = text; serverManifestEntry.ConversationId = conversationId; serverManifestEntry.FirstMessageInConversation = firstMessageInConversation; serverManifestEntry.FilterDate = filterDate; mailboxSyncItemId.ChangeKey = changeKey; this.lastServerManifestEntry = serverManifestEntry; } else { StoreObjectId id2 = StoreObjectId.FromProviderSpecificId(entryId, StoreObjectType.Unknown); MailboxSyncItemId mailboxSyncItemId2 = MailboxSyncItemId.CreateForExistingItem(this.mailboxSyncProvider.FolderSync, id2); if (mailboxSyncItemId2 == null) { return(ManifestCallbackStatus.Continue); } this.lastServerManifestEntry = MailboxSyncProvider.CreateItemDeleteManifestEntry(mailboxSyncItemId2); this.lastServerManifestEntry.ConversationId = conversationId; } return(this.CheckYieldOrStop()); }
private Dictionary <StoreObjectId, string> ProcessCommand(Dictionary <string, CommonNode> oldItems, Folder sourceFolder, MailboxSession mailboxSession) { if (oldItems == null) { throw new ArgumentNullException("items"); } Dictionary <StoreObjectId, string> dictionary = new Dictionary <StoreObjectId, string>(); if (oldItems.Count == 0) { return(dictionary); } GenericDictionaryData <DerivedData <ISyncItemId>, ISyncItemId, ClientManifestEntry> genericDictionaryData = (GenericDictionaryData <DerivedData <ISyncItemId>, ISyncItemId, ClientManifestEntry>) this.syncState[SyncStateProp.CumulativeClientManifest]; if (genericDictionaryData != null) { return(null); } genericDictionaryData = new GenericDictionaryData <DerivedData <ISyncItemId>, ISyncItemId, ClientManifestEntry>(); this.syncState[SyncStateProp.CumulativeClientManifest] = genericDictionaryData; this.clientManifest = genericDictionaryData.Data; this.clientManifest = new Dictionary <ISyncItemId, ClientManifestEntry>(); genericDictionaryData.Data = this.clientManifest; GenericDictionaryData <DerivedData <ISyncItemId>, ISyncItemId, FolderSync.ClientStateInformation> genericDictionaryData2 = (GenericDictionaryData <DerivedData <ISyncItemId>, ISyncItemId, FolderSync.ClientStateInformation>) this.syncState[SyncStateProp.ClientState]; if (genericDictionaryData2 != null) { return(null); } genericDictionaryData2 = new GenericDictionaryData <DerivedData <ISyncItemId>, ISyncItemId, FolderSync.ClientStateInformation>(); this.syncState[SyncStateProp.ClientState] = genericDictionaryData2; genericDictionaryData2.Data = new Dictionary <ISyncItemId, FolderSync.ClientStateInformation>(); MailboxSyncProviderFactory mailboxSyncProviderFactory = new MailboxSyncProviderFactory(mailboxSession, sourceFolder.StoreObjectId); ISyncProvider syncProvider = mailboxSyncProviderFactory.CreateSyncProvider(null); FolderSync folderSync = new FolderSync(syncProvider, this.syncState, ConflictResolutionPolicy.ServerWins, false); using (QueryResult queryResult = sourceFolder.ItemQuery(ItemQueryType.None, null, null, ItemSyncUpgrade.queryColumns)) { bool flag = false; while (!flag && oldItems.Count > 0) { object[][] rows = queryResult.GetRows(10000); flag = (rows.Length == 0); int num = 0; while (num < rows.Length && oldItems.Count > 0) { if (!(rows[num][0] is VersionedId) || !(rows[num][1] is int) || !(rows[num][2] is bool)) { throw new ApplicationException("The data returned from the query is unusable!"); } VersionedId versionedId = (VersionedId)rows[num][0]; StoreObjectId objectId = versionedId.ObjectId; int changeNumber = (int)rows[num][1]; string messageClass = rows[num][3] as string; string oldIdFromNewId = ItemSyncUpgrade.GetOldIdFromNewId(objectId.ProviderLevelItemId); if (oldIdFromNewId == null) { throw new ApplicationException("The new Id is invalid!"); } if (oldItems.ContainsKey(oldIdFromNewId)) { CommonNode commonNode = oldItems[oldIdFromNewId]; oldItems.Remove(oldIdFromNewId); dictionary.Add(objectId, commonNode.ServerId); ISyncItemId syncItemId = MailboxSyncItemId.CreateForNewItem(objectId); FolderSync.ClientStateInformation clientStateInformation = new FolderSync.ClientStateInformation(); clientStateInformation.ClientHasItem = true; genericDictionaryData2.Data[syncItemId] = clientStateInformation; if (!ItemSyncUpgrade.HasChanged(commonNode.VersionId, versionedId)) { bool read; if (commonNode.IsEmail && commonNode.Read != (bool)rows[num][2]) { folderSync.QueueDelayedServerOperation(new ServerManifestEntry(syncItemId) { ChangeType = ChangeType.ReadFlagChange }); read = commonNode.Read; } else { read = (bool)rows[num][2]; } ClientManifestEntry clientManifestEntry = new ClientManifestEntry(syncItemId); clientManifestEntry.Watermark = MailboxSyncWatermark.CreateForSingleItem(); clientManifestEntry.ClientAddId = "TiSyncStateUpgrade"; clientManifestEntry.ChangeType = ChangeType.Add; clientManifestEntry.MessageClass = messageClass; ((MailboxSyncWatermark)clientManifestEntry.Watermark).UpdateWithChangeNumber(changeNumber, read); this.clientManifest.Add(syncItemId, clientManifestEntry); } else { folderSync.QueueDelayedServerOperation(new ServerManifestEntry(syncItemId) { ChangeType = ChangeType.Change, MessageClass = messageClass }); } } num++; } } } if (oldItems.Count > 0) { foreach (KeyValuePair <string, CommonNode> keyValuePair in oldItems) { string key = keyValuePair.Key; CommonNode value = keyValuePair.Value; byte[] bytes = Encoding.Unicode.GetBytes(value.ServerId); StoreObjectId storeObjectId = StoreObjectId.FromProviderSpecificId(bytes, StoreObjectType.Mailbox); dictionary.Add(storeObjectId, value.ServerId); MailboxSyncItemId mailboxSyncItemId = MailboxSyncItemId.CreateForNewItem(storeObjectId); folderSync.QueueDelayedServerOperation(new ServerManifestEntry(mailboxSyncItemId) { ChangeType = ChangeType.Delete }); FolderSync.ClientStateInformation clientStateInformation2 = new FolderSync.ClientStateInformation(); clientStateInformation2.ClientHasItem = true; genericDictionaryData2.Data[mailboxSyncItemId] = clientStateInformation2; } } return(dictionary); }