private bool EnsureMapiManifest(MailboxSyncWatermark minWatermark, int numOperations, Dictionary <ISyncItemId, ServerManifestEntry> newServerManifest)
        {
            MemoryStream memoryStream = null;
            MapiFolder   mapiFolder   = this.folder.MapiFolder;

            if (this.manifest != null)
            {
                if (MailboxSyncProvider.IcsStateEquals(this.icsState, minWatermark.IcsState))
                {
                    if (this.extraServerManifestEntry != null)
                    {
                        if (numOperations == 0)
                        {
                            return(true);
                        }
                        newServerManifest.Add(this.extraServerManifestEntry.Id, this.extraServerManifestEntry);
                        if (this.extraServerManifestEntry.Watermark != null)
                        {
                            minWatermark.ChangeNumber = ((MailboxSyncWatermark)this.extraServerManifestEntry.Watermark).ChangeNumber;
                        }
                        this.SyncLogger.Information <ISyncItemId>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "MailboxSyncProvider::EnsureMapiManifest Adding cached change, id = {0}", this.extraServerManifestEntry.Id);
                        this.extraServerManifestEntry = null;
                    }
                    this.icsCallback.Bind(minWatermark, numOperations, newServerManifest);
                    this.SyncLogger.Information <int, int>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "MailboxSyncProvider::EnsureMapiManifest Reusing ICS manifest, numOperations = {0}, newServerManifest.Count = {1}", numOperations, newServerManifest.Count);
                    return(false);
                }
                this.manifest.Dispose();
                this.manifest = null;
                this.SyncLogger.Information <int, int>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "MailboxSyncProvider::EnsureMapiManifest Tossed old ICS manifest, numOperations = {0}, newServerManifest.Count = {1}", numOperations, newServerManifest.Count);
            }
            try
            {
                memoryStream     = ((minWatermark.IcsState == null) ? new MemoryStream() : new MemoryStream(minWatermark.IcsState));
                this.manifest    = mapiFolder.CreateExportManifest();
                this.icsCallback = new IcsCallback(this, newServerManifest, numOperations, minWatermark);
                Restriction restriction = (this.icsPropertyGroupFilter == null) ? null : FilterRestrictionConverter.CreateRestriction(this.folder.Session, this.folder.Session.ExTimeZone, this.folder.MapiFolder, this.icsPropertyGroupFilter);
                this.manifest.Configure(this.GetConfigFlags(), restriction, memoryStream, this.icsCallback, IcsCallback.PropTags);
                this.SyncLogger.Information <int, int>(ExTraceGlobals.SyncProcessTracer, (long)this.GetHashCode(), "MailboxSyncProvider::EnsureMapiManifest Created new ICS manifest, numOperations = {0}, newServerManifest.Count = {1}", numOperations, newServerManifest.Count);
            }
            finally
            {
                Util.DisposeIfPresent(memoryStream);
            }
            return(false);
        }
        private byte[] CatchUpIcsState(MailboxSyncWatermark currentWatermark)
        {
            byte[]       result        = null;
            MapiFolder   mapiFolder    = this.folder.MapiFolder;
            MemoryStream memoryStream  = null;
            MemoryStream memoryStream2 = null;

            try
            {
                if (currentWatermark.IcsState == null)
                {
                    memoryStream = new MemoryStream();
                }
                else
                {
                    memoryStream = new MemoryStream(currentWatermark.IcsState);
                }
                StoreSession session = this.folder.Session;
                bool         flag    = false;
                try
                {
                    if (session != null)
                    {
                        session.BeginMapiCall();
                        session.BeginServerHealthCall();
                        flag = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    try
                    {
                        using (MapiManifest mapiManifest = mapiFolder.CreateExportManifest())
                        {
                            IcsCallback iMapiManifestCallback = new IcsCallback(this, null, 0, null);
                            mapiManifest.Configure(this.GetConfigFlags() | ManifestConfigFlags.Catchup, null, memoryStream, iMapiManifestCallback, IcsCallback.PropTags);
                            mapiManifest.Synchronize();
                            memoryStream2 = new MemoryStream();
                            mapiManifest.GetState(memoryStream2);
                            result = memoryStream2.ToArray();
                        }
                    }
                    catch (MapiExceptionCorruptData innerException)
                    {
                        throw new CorruptSyncStateException(ServerStrings.ExSyncStateCorrupted("ICS"), innerException);
                    }
                    catch (CorruptDataException innerException2)
                    {
                        throw new CorruptSyncStateException(ServerStrings.ExSyncStateCorrupted("ICS"), innerException2);
                    }
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ICSSynchronizationFailed, ex, session, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MailboxSyncProvider::CatchUpIcsState()", new object[0]),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.ICSSynchronizationFailed, ex2, session, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MailboxSyncProvider::CatchUpIcsState()", new object[0]),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (session != null)
                        {
                            session.EndMapiCall();
                            if (flag)
                            {
                                session.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
            }
            finally
            {
                Util.DisposeIfPresent(memoryStream);
                Util.DisposeIfPresent(memoryStream2);
            }
            return(result);
        }