Example #1
0
        internal DelegateSessionEntry GetDelegateSessionEntry(IExchangePrincipal principal, OpenBy openBy)
        {
            MailboxSession       mailboxSession       = null;
            DelegateSessionEntry delegateSessionEntry = null;
            bool flag = false;

            try
            {
                if (!this.DelegateSessionCacheInstance.TryGet(principal, openBy, out delegateSessionEntry))
                {
                    mailboxSession       = MailboxSession.InternalOpenDelegateAccess(this.masterMailboxSession, principal);
                    delegateSessionEntry = this.DelegateSessionCacheInstance.Add(new DelegateSessionEntry(mailboxSession, openBy));
                }
                if (!delegateSessionEntry.IsConnected)
                {
                    delegateSessionEntry.Connect();
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (delegateSessionEntry != null)
                    {
                        this.DelegateSessionCacheInstance.RemoveEntry(delegateSessionEntry);
                    }
                    else if (mailboxSession != null)
                    {
                        mailboxSession.CanDispose = true;
                        mailboxSession.Dispose();
                        mailboxSession = null;
                    }
                }
            }
            return(delegateSessionEntry);
        }