// Token: 0x06000011 RID: 17 RVA: 0x000024D8 File Offset: 0x000006D8
 private static MailboxConnectivity CheckMailboxConnectivity(MailboxConnectivity mailboxConnectivity)
 {
     try
     {
         mailboxConnectivity.Message = "Getting ADSessionSettings";
         ADSessionSettings adsessionSettings = ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(mailboxConnectivity.TenantAcceptedDomain);
         if (adsessionSettings == null)
         {
             mailboxConnectivity.Message = "ADSessionSettings were not found.";
             return(mailboxConnectivity);
         }
         mailboxConnectivity.Message = "Creating IRecipientSession";
         IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, true, ConsistencyMode.IgnoreInvalid, null, adsessionSettings, 223, "CheckMailboxConnectivity", "f:\\15.00.1497\\sources\\dev\\Management\\src\\ServiceHost\\Servicelets\\AuditLogSearch\\Program\\AuditLogSearchHealthHandler.cs");
         if (tenantOrRootOrgRecipientSession == null)
         {
             mailboxConnectivity.Message = "IRecipientSession was not found.";
             return(mailboxConnectivity);
         }
         bool   flag = mailboxConnectivity.ExchangeUserId.CompareTo(Guid.Empty) == 0;
         ADUser aduser;
         if (flag)
         {
             mailboxConnectivity.Message = "Getting OrganizationId";
             OrganizationId organizationId = OrganizationId.FromAcceptedDomain(mailboxConnectivity.TenantAcceptedDomain);
             mailboxConnectivity.Message = "Finding arbitration mailbox";
             aduser = AdminAuditLogHelper.GetTenantArbitrationMailbox(organizationId);
             mailboxConnectivity.ExchangeUserId = aduser.ExchangeGuid;
         }
         else
         {
             mailboxConnectivity.Message = "Finding ADRecipient";
             ADRecipient adrecipient = tenantOrRootOrgRecipientSession.FindByExchangeGuidIncludingAlternate(mailboxConnectivity.ExchangeUserId);
             aduser = (adrecipient as ADUser);
         }
         if (aduser == null)
         {
             mailboxConnectivity.Message = "ADUser was not found.";
             return(mailboxConnectivity);
         }
         mailboxConnectivity.Message = "Getting ExchangePrincipal";
         ExchangePrincipal principal = ExchangePrincipal.FromADUser(aduser, null);
         mailboxConnectivity.Message = "Creating EwsAuditClient";
         EwsAuditClient client = new EwsAuditClient(new EwsConnectionManager(principal, OpenAsAdminOrSystemServiceBudgetTypeType.Default, ExTraceGlobals.ServiceletTracer), TimeSpan.FromSeconds(5.0), ExTraceGlobals.ServiceletTracer);
         mailboxConnectivity.Message = "Checking connectivity";
         AuditLogSearchHealthHandler.CheckMailboxConnectivity(client, false);
         mailboxConnectivity.Message = "Checking connectivity (archive)";
         AuditLogSearchHealthHandler.CheckMailboxConnectivity(client, true);
         mailboxConnectivity.Message = "Ok";
         mailboxConnectivity.Success = true;
     }
     catch (Exception ex)
     {
         mailboxConnectivity.Message  += " FAILED.";
         mailboxConnectivity.Exception = ex.ToString();
     }
     return(mailboxConnectivity);
 }
        // Token: 0x0600000E RID: 14 RVA: 0x000022E8 File Offset: 0x000004E8
        internal override HealthHandlerResult GetExchangeDiagnosticsInfoData(DiagnosableParameters parameters)
        {
            string argument = parameters.Argument;

            if (string.IsNullOrWhiteSpace(argument))
            {
                return(this.AuditLogSearchHealth);
            }
            if (argument.Equals("/run", StringComparison.InvariantCultureIgnoreCase))
            {
                this.RunSearchNowEvent.Set();
                return(new HealthHandlerResult("Ok"));
            }
            if (argument.Equals("/check", StringComparison.InvariantCultureIgnoreCase))
            {
                Search search = (from s in this.AuditLogSearchHealth.Searches
                                 where s.ExceptionDetails != null
                                 select s).FirstOrDefault <Search>() ?? this.AuditLogSearchHealth.Searches.FirstOrDefault <Search>();
                if (search == null)
                {
                    return(new HealthHandlerResult("There are no faulted or any searches."));
                }
                MailboxConnectivity mailboxConnectivity = new MailboxConnectivity
                {
                    Message = string.Empty,
                    TenantAcceptedDomain = search.UserPrincipalName.Split(new char[]
                    {
                        '@'
                    }).LastOrDefault <string>(),
                    ExchangeUserId = (string.IsNullOrWhiteSpace(search.LastProcessedMailbox) ? Guid.Empty : Guid.Parse(search.LastProcessedMailbox))
                };
                return(AuditLogSearchHealthHandler.CheckMailboxConnectivity(mailboxConnectivity));
            }
            else
            {
                Match match = Regex.Match(argument, "^\\s* [/-]?check \\s* (?<org>\\S+) (\\s* [/\\s] \\s* (?<mailbox>\\S+))? \\s*$", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.CultureInvariant);
                if (match.Success)
                {
                    MailboxConnectivity mailboxConnectivity2 = new MailboxConnectivity
                    {
                        Exception = string.Empty,
                        Message   = string.Empty
                    };
                    string value  = match.Groups["org"].Value;
                    string value2 = match.Groups["mailbox"].Value;
                    Guid   empty  = Guid.Empty;
                    if (!string.IsNullOrEmpty(value) && (string.IsNullOrWhiteSpace(value2) || Guid.TryParse(value2, out empty)))
                    {
                        mailboxConnectivity2.TenantAcceptedDomain = value;
                        mailboxConnectivity2.ExchangeUserId       = empty;
                        mailboxConnectivity2 = AuditLogSearchHealthHandler.CheckMailboxConnectivity(mailboxConnectivity2);
                    }
                    else
                    {
                        mailboxConnectivity2.Message = "A domain name and a mailbox GUID are expected.";
                    }
                    return(mailboxConnectivity2);
                }
                return(new HealthHandlerResult("Invalid argument."));
            }
        }