public void UpdateRecipientSyncStateValue(RecipientSyncOperation operation)
        {
            Dictionary <string, HashSet <string> > dictionary = new Dictionary <string, HashSet <string> >(MserveTargetConnection.ReplicationAddressAttributes.Length, StringComparer.OrdinalIgnoreCase);

            foreach (string text in MserveTargetConnection.ReplicationAddressAttributes)
            {
                string recipientSyncStateAttribute = MserveTargetConnection.GetRecipientSyncStateAttribute(operation.RecipientSyncState, text);
                dictionary[text] = RecipientSyncState.AddressHashSetFromConcatStringValue(recipientSyncStateAttribute);
            }
            foreach (OperationType key in operation.PendingSyncStateCommitEntries.Keys)
            {
                foreach (string text2 in operation.PendingSyncStateCommitEntries[key])
                {
                    string key2 = null;
                    if (!operation.AddressTypeTable.TryGetValue(text2, out key2))
                    {
                        throw new InvalidOperationException(text2 + " is not in AddressTypeTable");
                    }
                    switch (key)
                    {
                    case OperationType.Add:
                        if (!dictionary[key2].Contains(text2))
                        {
                            dictionary[key2].Add(text2);
                        }
                        break;

                    case OperationType.Delete:
                        if (dictionary[key2].Contains(text2))
                        {
                            dictionary[key2].Remove(text2);
                        }
                        break;
                    }
                }
            }
            foreach (string text3 in MserveTargetConnection.ReplicationAddressAttributes)
            {
                MserveTargetConnection.SetRecipientSyncStateAttribute(operation.RecipientSyncState, text3, RecipientSyncState.AddressHashSetToConcatStringValue(dictionary[text3]));
            }
        }
        private static void OnAddressChange(DirectoryAttribute attribute, RecipientSyncOperation operation)
        {
            HashSet <string> hashSet = RecipientSyncState.AddressHashSetFromConcatStringValue(MserveTargetConnection.GetRecipientSyncStateAttribute(operation.RecipientSyncState, attribute.Name));

            foreach (object obj in attribute)
            {
                string text = (string)obj;
                string text2;
                if (text.StartsWith("smtp:", StringComparison.OrdinalIgnoreCase))
                {
                    text2 = text.Substring(5);
                }
                else if (text.StartsWith("meum:", StringComparison.OrdinalIgnoreCase))
                {
                    text2 = text.Substring(5);
                }
                else
                {
                    text2 = text;
                }
                if (!hashSet.Contains(text2))
                {
                    operation.AddedEntries.Add(text2);
                    operation.AddressTypeTable[text2] = attribute.Name;
                    ExTraceGlobals.TargetConnectionTracer.TraceDebug <string>(0L, "Add {0} to AddedEntries", text2);
                }
                else
                {
                    hashSet.Remove(text2);
                }
            }
            foreach (string text3 in hashSet)
            {
                operation.RemovedEntries.Add(text3);
                operation.AddressTypeTable[text3] = attribute.Name;
                ExTraceGlobals.TargetConnectionTracer.TraceDebug <string>(0L, "Add {0} to RemovedEntries", text3);
            }
        }
        protected List <RecipientSyncOperation> GetRecipientSyncOperation(ExSearchResultEntry entry)
        {
            List <RecipientSyncOperation> list = new List <RecipientSyncOperation>();

            ExTraceGlobals.TargetConnectionTracer.TraceDebug <string>(0L, "Try to GetRecipientSyncOperation for {0}", entry.DistinguishedName);
            RecipientSyncState recipientSyncState = null;

            if (entry.Attributes.ContainsKey("msExchExternalSyncState"))
            {
                byte[] bytes = Encoding.ASCII.GetBytes((string)entry.Attributes["msExchExternalSyncState"][0]);
                recipientSyncState = RecipientSyncState.DeserializeRecipientSyncState(bytes);
                ExTraceGlobals.TargetConnectionTracer.TraceDebug <string>(0L, "{0} has existing syncState", entry.DistinguishedName);
            }
            if (recipientSyncState == null)
            {
                if (entry.IsDeleted)
                {
                    ExTraceGlobals.TargetConnectionTracer.TraceDebug <string>(0L, "{0} is deleted entry without syncState. Ignore the entry", entry.DistinguishedName);
                    return(list);
                }
                ExTraceGlobals.TargetConnectionTracer.TraceDebug <string>(0L, "{0} is a normal entry without syncState. Creating one", entry.DistinguishedName);
                recipientSyncState = new RecipientSyncState();
            }
            if (!entry.IsDeleted)
            {
                int partnerId = MserveSynchronizationProvider.PartnerId;
                if (partnerId == -1)
                {
                    ExTraceGlobals.TargetConnectionTracer.TraceError <string>(0L, "Failed the sync because we could not get the partner Id for {0}", entry.DistinguishedName);
                    throw new ExDirectoryException(new ArgumentException("Failed the sync because we could not get the partner Id for " + entry.DistinguishedName));
                }
                int num = (recipientSyncState.PartnerId != 0) ? recipientSyncState.PartnerId : partnerId;
                recipientSyncState.PartnerId = partnerId;
                if (num != partnerId)
                {
                    ExTraceGlobals.TargetConnectionTracer.TraceDebug <string, int, int>(0L, "{0}'s partnerId changed from {1} to {2}", entry.DistinguishedName, num, partnerId);
                    base.LogSession.LogEvent(EdgeSyncLoggingLevel.Low, EdgeSyncEvent.TargetConnection, entry.DistinguishedName, "Warning: Changing partner ID from " + num.ToString() + " to " + partnerId.ToString());
                }
                else
                {
                    RecipientSyncOperation recipientSyncOperation = new RecipientSyncOperation(entry.DistinguishedName, partnerId, recipientSyncState, false);
                    ExTraceGlobals.TargetConnectionTracer.TraceDebug <int>(0L, "Create new operation with partner Id {0}", partnerId);
                    foreach (string key in MserveTargetConnection.ReplicationAddressAttributes)
                    {
                        if (entry.Attributes.ContainsKey(key))
                        {
                            MserveTargetConnection.OnAddressChange(entry.Attributes[key], recipientSyncOperation);
                        }
                    }
                    if (recipientSyncOperation.RemovedEntries.Count != 0 || recipientSyncOperation.AddedEntries.Count != 0)
                    {
                        list.Add(recipientSyncOperation);
                    }
                }
            }
            else
            {
                int partnerId2 = recipientSyncState.PartnerId;
                if (partnerId2 != 0)
                {
                    RecipientSyncOperation recipientSyncOperation2 = new RecipientSyncOperation(entry.DistinguishedName, partnerId2, null, true);
                    ExTraceGlobals.TargetConnectionTracer.TraceDebug <int>(0L, "Create remove operation with partner Id {0}", partnerId2);
                    foreach (string text in MserveTargetConnection.ReplicationAddressAttributes)
                    {
                        string recipientSyncStateAttribute = MserveTargetConnection.GetRecipientSyncStateAttribute(recipientSyncState, text);
                        if (recipientSyncStateAttribute != null)
                        {
                            List <string> list2 = RecipientSyncState.AddressToList(recipientSyncStateAttribute);
                            if (this.CanRemove(entry.DistinguishedName, text, list2))
                            {
                                foreach (string text2 in list2)
                                {
                                    recipientSyncOperation2.RemovedEntries.Add(text2);
                                    ExTraceGlobals.TargetConnectionTracer.TraceDebug <string>(0L, "Add {0} to RemovedEntries", text2);
                                }
                            }
                        }
                    }
                    if (recipientSyncOperation2.RemovedEntries.Count != 0)
                    {
                        list.Add(recipientSyncOperation2);
                    }
                }
                else
                {
                    ExTraceGlobals.TargetConnectionTracer.TraceDebug(0L, "No partner Id present on syncState. Skip the recipient");
                }
            }
            return(list);
        }