private StoreSession OpenMailboxSession(StoreMailboxData mailbox) { Guid activityId = (ActivityContext.ActivityId != null) ? ActivityContext.ActivityId.Value : Guid.Empty; AssistantBase assistant = this.Assistant as AssistantBase; string nonLocalizedName = this.Assistant.NonLocalizedName; Guid mailboxGuid = mailbox.MailboxGuid; StoreSession result; try { ExchangePrincipal exchangePrincipal; if (mailbox.TenantPartitionHint != null) { ADSessionSettings adSettings = ADSessionSettings.FromTenantPartitionHint(mailbox.TenantPartitionHint); exchangePrincipal = ExchangePrincipal.FromLocalServerMailboxGuid(adSettings, this.DatabaseInfo.Guid, mailbox.Guid); } else { exchangePrincipal = ExchangePrincipal.FromMailboxData(mailbox.Guid, this.DatabaseInfo.Guid, mailbox.OrganizationId ?? OrganizationId.ForestWideOrgId, Array <CultureInfo> .Empty); } if (mailbox.IsPublicFolderMailbox) { StoreSession storeSession = PublicFolderSession.OpenAsAdmin(null, exchangePrincipal, null, CultureInfo.InstalledUICulture, string.Format("{0};Action={1}", "Client=TBA", this.Assistant.GetType().Name), null); AssistantsLog.LogMailboxSucceedToOpenStoreSessionEvent(activityId, nonLocalizedName, assistant, mailboxGuid, mailbox.DisplayName, this); result = storeSession; } else { bool flag = false; MailboxSession mailbox2 = this.DatabaseInfo.GetMailbox(exchangePrincipal, ClientType.TimeBased, this.Assistant.GetType().Name); try { mailbox2.ReconstructExchangePrincipal(); mailbox2.ExTimeZone = ExTimeZone.CurrentTimeZone; flag = true; AssistantsLog.LogMailboxSucceedToOpenStoreSessionEvent(activityId, nonLocalizedName, assistant, mailboxGuid, mailbox.DisplayName, this); result = mailbox2; } finally { if (!flag) { mailbox2.Dispose(); } } } } catch (ObjectNotFoundException ex) { string text = "MailboxNotFound"; string message = string.Format("{0}: {1}", this, text); string value = string.Format("{0}:{1}", text, mailbox.MailboxGuid); ExTraceGlobals.TimeBasedDatabaseJobTracer.TraceError((long)this.GetHashCode(), message); AssistantsLog.LogMailboxFailedToOpenStoreSessionEvent(activityId, nonLocalizedName, assistant, ex, mailboxGuid, mailbox.DisplayName, this); throw new SkipException(new LocalizedString(value), ex); } catch (StorageTransientException ex2) { string message2 = string.Format("{0}: Could not open mailbox store session due to storage transient error: {1}", this, ex2.Message); ExTraceGlobals.TimeBasedDatabaseJobTracer.TraceError((long)this.GetHashCode(), message2); AssistantsLog.LogMailboxFailedToOpenStoreSessionEvent(activityId, nonLocalizedName, assistant, ex2, mailboxGuid, mailbox.DisplayName, this); Interlocked.Increment(ref this.mailboxesFailedToOpenStoreSessionCount); throw; } catch (Exception ex3) { string message3 = string.Format("{0}: Could not open mailbox store session due to error: {1}", this, ex3.Message); ExTraceGlobals.TimeBasedDatabaseJobTracer.TraceError((long)this.GetHashCode(), message3); AssistantsLog.LogMailboxFailedToOpenStoreSessionEvent(activityId, nonLocalizedName, assistant, ex3, mailboxGuid, mailbox.DisplayName, this); Interlocked.Increment(ref this.mailboxesFailedToOpenStoreSessionCount); throw; } return(result); }