public PublicFolderMailboxSynchronizerReference GetPublicFolderMailboxSynchronizer(IExchangePrincipal publicFolderMailboxPrincipal, bool onlyRefCounting, bool forHierarchyAccess)
        {
            PublicFolderMailboxSynchronizerReference result;

            lock (this.lockObject)
            {
                PublicFolderMailboxSynchronizerManager.PublicFolderMailboxSynchronizerAndReferenceCount publicFolderMailboxSynchronizerAndReferenceCount;
                if (!this.publicFolderMailboxSynchronizers.TryGetValue(publicFolderMailboxPrincipal.MailboxInfo.MailboxGuid, out publicFolderMailboxSynchronizerAndReferenceCount))
                {
                    PublicFolderMailboxSynchronizer publicFolderMailboxSynchronizer2 = new PublicFolderMailboxSynchronizer(publicFolderMailboxPrincipal.MailboxInfo.OrganizationId, publicFolderMailboxPrincipal.MailboxInfo.MailboxGuid, publicFolderMailboxPrincipal.MailboxInfo.Location.ServerFqdn, onlyRefCounting);
                    publicFolderMailboxSynchronizerAndReferenceCount = new PublicFolderMailboxSynchronizerManager.PublicFolderMailboxSynchronizerAndReferenceCount(publicFolderMailboxSynchronizer2);
                    this.publicFolderMailboxSynchronizers[publicFolderMailboxPrincipal.MailboxInfo.MailboxGuid] = publicFolderMailboxSynchronizerAndReferenceCount;
                }
                publicFolderMailboxSynchronizerAndReferenceCount.ReferenceCount++;
                if (forHierarchyAccess)
                {
                    publicFolderMailboxSynchronizerAndReferenceCount.HierarchyAccessReferenceCount++;
                }
                result = new PublicFolderMailboxSynchronizerReference(publicFolderMailboxSynchronizerAndReferenceCount.PublicFolderMailboxSynchronizer, delegate(PublicFolderMailboxSynchronizer publicFolderMailboxSynchronizer)
                {
                    this.OnReferenceDisposed(publicFolderMailboxSynchronizer, forHierarchyAccess);
                });
            }
            return(result);
        }
        private void OnReferenceDisposed(PublicFolderMailboxSynchronizer publicFolderMailboxSynchronizer, bool forHierarchyAccess)
        {
            bool flag = false;

            lock (this.lockObject)
            {
                PublicFolderMailboxSynchronizerManager.PublicFolderMailboxSynchronizerAndReferenceCount publicFolderMailboxSynchronizerAndReferenceCount;
                if (!this.publicFolderMailboxSynchronizers.TryGetValue(publicFolderMailboxSynchronizer.MailboxGuid, out publicFolderMailboxSynchronizerAndReferenceCount) || publicFolderMailboxSynchronizerAndReferenceCount.ReferenceCount == 0)
                {
                    throw new InvalidOperationException("The public folder mailbox synchronizer has already been removed. This should not happen. ReferenceCount = " + ((publicFolderMailboxSynchronizerAndReferenceCount == null) ? -1 : publicFolderMailboxSynchronizerAndReferenceCount.ReferenceCount));
                }
                publicFolderMailboxSynchronizerAndReferenceCount.ReferenceCount--;
                if (forHierarchyAccess)
                {
                    publicFolderMailboxSynchronizerAndReferenceCount.HierarchyAccessReferenceCount--;
                }
                if (publicFolderMailboxSynchronizerAndReferenceCount.ReferenceCount == 0)
                {
                    this.publicFolderMailboxSynchronizers.Remove(publicFolderMailboxSynchronizer.MailboxGuid);
                    flag = true;
                }
            }
            if (flag)
            {
                publicFolderMailboxSynchronizer.Dispose();
            }
        }
 public PublicFolderMailboxSynchronizerReference(PublicFolderMailboxSynchronizer publicFolderMailboxSynchronizer, Action <PublicFolderMailboxSynchronizer> onDispose)
 {
     this.publicFolderMailboxSynchronizer = publicFolderMailboxSynchronizer;
     this.onDispose = onDispose;
 }
 public PublicFolderMailboxSynchronizerAndReferenceCount(PublicFolderMailboxSynchronizer publicFolderMailboxSynchronizer)
 {
     this.PublicFolderMailboxSynchronizer = publicFolderMailboxSynchronizer;
 }