// Token: 0x06001250 RID: 4688 RVA: 0x000696B4 File Offset: 0x000678B4
        private ADUser GetOrganizationalMailboxFromAD(ADSessionSettings sessionSettings, Guid mailboxGuid)
        {
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 733, "GetOrganizationalMailboxFromAD", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\OABGenerator\\OABGeneratorAssistant.cs");
            ADRecipient       adrecipient;

            try
            {
                adrecipient = tenantOrRootOrgRecipientSession.FindByExchangeGuid(mailboxGuid);
            }
            catch (NonUniqueRecipientException)
            {
                OABGeneratorAssistant.Tracer.TraceError <Guid>((long)this.GetHashCode(), "OABGeneratorAssistant.GetOrganizationalMailboxFromAD: multiple mailboxes have ExchangeGuid={0}", mailboxGuid);
                OABLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_OrganizationalMailboxGuidIsNotUnique, new object[]
                {
                    mailboxGuid
                });
                return(null);
            }
            if (adrecipient == null)
            {
                OABGeneratorAssistant.Tracer.TraceError <Guid>((long)this.GetHashCode(), "OABGeneratorAssistant.GetOrganizationalMailboxFromAD: unable to find user object with ExchangeGuid={0}", mailboxGuid);
                return(null);
            }
            ADUser aduser = adrecipient as ADUser;

            if (aduser == null)
            {
                OABGeneratorAssistant.Tracer.TraceError <Guid>((long)this.GetHashCode(), "OABGeneratorAssistant.GetOrganizationalMailboxFromAD: unknown organization mailbox: {0}", mailboxGuid);
                return(null);
            }
            return(aduser);
        }
        // Token: 0x0600124D RID: 4685 RVA: 0x000694E0 File Offset: 0x000676E0
        public AssistantTaskContext FinishProcessingOAB(AssistantTaskContext assistantTaskContext)
        {
            OABGeneratorTaskContext oabgeneratorTaskContext = assistantTaskContext as OABGeneratorTaskContext;

            OABLogger.LogRecord(TraceType.FunctionTrace, "OABGeneratorAssistant.FinishProcessingOAB: start", new object[0]);
            try
            {
                OABLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_OABGenerationCompletedGeneration, new object[]
                {
                    oabgeneratorTaskContext.CurrentOAB.ToString(),
                    oabgeneratorTaskContext.CurrentOAB.DistinguishedName,
                    oabgeneratorTaskContext.CurrentOAB.Id.ObjectGuid,
                    (oabgeneratorTaskContext.OABGenerator.Stats != null) ? oabgeneratorTaskContext.OABGenerator.Stats.GetStringForLogging() : string.Empty
                });
            }
            finally
            {
                if (oabgeneratorTaskContext.Cleanup != null)
                {
                    oabgeneratorTaskContext.Cleanup(oabgeneratorTaskContext);
                }
                oabgeneratorTaskContext.ClearPerOABData();
                OABLogger.LogRecord(TraceType.FunctionTrace, "OABGeneratorAssistant.FinishProcessingOAB: finish", new object[0]);
            }
            if (oabgeneratorTaskContext.OABsToGenerate != null && oabgeneratorTaskContext.OABsToGenerate.Count > 0)
            {
                oabgeneratorTaskContext.CurrentOAB = oabgeneratorTaskContext.OABsToGenerate.Dequeue();
                oabgeneratorTaskContext.OABStep    = new AssistantStep(this.BeginProcessingOAB);
                return(OABGeneratorTaskContext.FromOABGeneratorTaskContext(oabgeneratorTaskContext));
            }
            return(null);
        }
        // Token: 0x0600124C RID: 4684 RVA: 0x00069300 File Offset: 0x00067500
        public AssistantTaskContext BeginProcessingOAB(AssistantTaskContext assistantTaskContext)
        {
            OABGeneratorTaskContext oabgeneratorTaskContext = assistantTaskContext as OABGeneratorTaskContext;
            AssistantStep           assistantStep           = null;

            OABLogger.LogRecord(TraceType.FunctionTrace, "OABGeneratorAssistant.BeginProcessingOAB: start", new object[0]);
            OABGeneratorMailboxData oabgeneratorMailboxData = (OABGeneratorMailboxData)oabgeneratorTaskContext.Args.MailboxData;

            try
            {
                lock (this.currentOABsInProcessing)
                {
                    if (this.currentOABsInProcessing.Contains(oabgeneratorTaskContext.CurrentOAB.Id.ObjectGuid))
                    {
                        OABGeneratorAssistant.Tracer.TraceDebug <ADObjectId>((long)this.GetHashCode(), "OABGeneratorAssistant.BeginProcessingOAB: ignoring on-demand request requested OAB is already in processing: {0}.", oabgeneratorTaskContext.CurrentOAB.Id);
                        return(null);
                    }
                    this.currentOABsInProcessing.Add(oabgeneratorTaskContext.CurrentOAB.Id.ObjectGuid);
                }
                OABGeneratorTaskContext oabgeneratorTaskContext2 = oabgeneratorTaskContext;
                oabgeneratorTaskContext2.Cleanup     = (Action <OABGeneratorTaskContext>)Delegate.Combine(oabgeneratorTaskContext2.Cleanup, new Action <OABGeneratorTaskContext>(this.RemoveCurrentOABFromInProcessingList));
                oabgeneratorTaskContext.OABGenerator = new OABGenerator(oabgeneratorTaskContext.PerOrgAdSystemConfigSession, oabgeneratorTaskContext.CurrentOAB, oabgeneratorMailboxData.MailboxSid, oabgeneratorMailboxData.MailboxDomain, new Action(this.AbortProcessingOnShutdown));
                OABLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_OABGenerationStartGeneration, new object[]
                {
                    oabgeneratorTaskContext.CurrentOAB,
                    oabgeneratorTaskContext.CurrentOAB.DistinguishedName,
                    oabgeneratorTaskContext.CurrentOAB.Id.ObjectGuid
                });
                oabgeneratorTaskContext.OABGenerator.Initialize();
                oabgeneratorTaskContext.ReturnStep.Push(new AssistantStep(this.FinishProcessingOAB));
                assistantStep = new AssistantStep(oabgeneratorTaskContext.OABGenerator.PrepareFilesForOABGeneration);
            }
            finally
            {
                OABLogger.LogRecord(TraceType.FunctionTrace, "OABGeneratorAssistant.BeginProcessingOAB: finish", new object[0]);
                if (assistantStep != null)
                {
                    oabgeneratorTaskContext.OABStep = assistantStep;
                }
            }
            return(OABGeneratorTaskContext.FromOABGeneratorTaskContext(oabgeneratorTaskContext));
        }
        // Token: 0x06001254 RID: 4692 RVA: 0x00069B14 File Offset: 0x00067D14
        private bool OABAddressListsAreValid(OfflineAddressBook oab)
        {
            bool       flag       = true;
            ADObjectId adobjectId = null;

            foreach (ADObjectId adobjectId2 in oab.AddressLists)
            {
                if (string.IsNullOrEmpty(adobjectId2.DistinguishedName))
                {
                    flag       = false;
                    adobjectId = adobjectId2;
                    OABLogger.LogRecord(TraceType.ErrorTrace, "Address list id {0} is not valid because it does not have a DN", new object[]
                    {
                        adobjectId2
                    });
                    break;
                }
                if (!ADObjectId.IsValidDistinguishedName(adobjectId2.DistinguishedName))
                {
                    flag       = false;
                    adobjectId = adobjectId2;
                    OABLogger.LogRecord(TraceType.ErrorTrace, "Address list id {0} is not valid because the DN is not validly formed", new object[]
                    {
                        adobjectId2.DistinguishedName
                    });
                    break;
                }
                if (adobjectId2.IsDeleted)
                {
                    flag       = false;
                    adobjectId = adobjectId2;
                    OABLogger.LogRecord(TraceType.ErrorTrace, "Address list id {0} is not valid because it is a deleted object", new object[]
                    {
                        adobjectId2.DistinguishedName
                    });
                    break;
                }
                bool flag2 = adobjectId2.DistinguishedName.IndexOf(",CN=LostAndFound,DC=", StringComparison.OrdinalIgnoreCase) != -1;
                bool flag3 = adobjectId2.DistinguishedName.IndexOf(",CN=LostAndFoundConfig,CN=Configuration,DC=", StringComparison.OrdinalIgnoreCase) != -1;
                if (flag2 || flag3)
                {
                    flag       = false;
                    adobjectId = adobjectId2;
                    OABLogger.LogRecord(TraceType.ErrorTrace, "Address list id {0} is not valid because it is a deleted object", new object[]
                    {
                        adobjectId2.DistinguishedName
                    });
                    break;
                }
                bool flag4 = adobjectId2.DistinguishedName.IndexOf(GlobalAddressList.RdnGalContainerToOrganization.DistinguishedName, StringComparison.OrdinalIgnoreCase) > 0;
                bool flag5 = adobjectId2.DistinguishedName.IndexOf(AddressList.RdnAlContainerToOrganization.DistinguishedName, StringComparison.OrdinalIgnoreCase) > 0;
                if (!flag4 && !flag5)
                {
                    flag       = false;
                    adobjectId = adobjectId2;
                    OABLogger.LogRecord(TraceType.ErrorTrace, "Address list id {0} is not valid because it is not a child or descendant of either the All Global Address Lists or All Address Lists container", new object[]
                    {
                        adobjectId2.DistinguishedName
                    });
                    break;
                }
            }
            if (!flag && adobjectId != null)
            {
                OABLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_OABNotProcessedBecauseAddressListIsInvalid, new object[]
                {
                    oab.Identity,
                    string.IsNullOrEmpty(adobjectId.DistinguishedName) ? adobjectId.ToString() : adobjectId.DistinguishedName
                });
                OABLogger.LogRecord(TraceType.ErrorTrace, "Address list errors found in OAB {0}, address list {1}", new object[]
                {
                    oab.Id,
                    string.IsNullOrEmpty(adobjectId.DistinguishedName) ? adobjectId.ToString() : adobjectId.DistinguishedName
                });
            }
            return(flag);
        }
        // Token: 0x0600124B RID: 4683 RVA: 0x00069084 File Offset: 0x00067284
        public AssistantTaskContext InitializeOABGeneration(AssistantTaskContext assistantTaskContext)
        {
            OABGeneratorTaskContext oabgeneratorTaskContext = assistantTaskContext as OABGeneratorTaskContext;
            AssistantStep           oabstep = new AssistantStep(this.BeginProcessingOAB);

            OABLogger.LogRecord(TraceType.FunctionTrace, "OABGeneratorAssistant.InitialStep: start", new object[0]);
            OABGeneratorMailboxData oabgeneratorMailboxData = (OABGeneratorMailboxData)oabgeneratorTaskContext.Args.MailboxData;

            try
            {
                OrganizationId organizationId = oabgeneratorMailboxData.OrganizationId;
                if (organizationId == null)
                {
                    throw new ArgumentException("unable to determine organization Id");
                }
                oabgeneratorTaskContext.PerOrgAdSystemConfigSession = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(false, ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(organizationId), 502, "InitializeOABGeneration", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\OABGenerator\\OABGeneratorAssistant.cs");
                if (oabgeneratorMailboxData.OfflineAddressBook == Guid.Empty)
                {
                    OABLogger.LogRecord(TraceType.InfoTrace, "OABGenerator invoked for scheduled generation of OABs for Org '{0}' on DatabaseGuid={1}", new object[]
                    {
                        organizationId,
                        oabgeneratorTaskContext.Args.MailboxData.DatabaseGuid
                    });
                    oabgeneratorTaskContext.OABsToGenerate = this.GetOABsFromAD(oabgeneratorTaskContext, Guid.Empty);
                }
                else
                {
                    OABLogger.LogRecord(TraceType.InfoTrace, "OABGenerator invoked {0} for on-demand generation of OAB {1} for Org {2} DatabaseGuid={3}, MailboxGuid={4}", new object[]
                    {
                        oabgeneratorMailboxData.JobDescription,
                        oabgeneratorMailboxData.OfflineAddressBook,
                        organizationId,
                        oabgeneratorTaskContext.Args.MailboxData.DatabaseGuid,
                        oabgeneratorMailboxData.MailboxGuid
                    });
                    oabgeneratorTaskContext.OABsToGenerate = this.GetOABsFromAD(oabgeneratorTaskContext, oabgeneratorMailboxData.OfflineAddressBook);
                    if (oabgeneratorTaskContext.OABsToGenerate == null || oabgeneratorTaskContext.OABsToGenerate.Count != 1)
                    {
                        OABLogger.LogEvent(InfoWorkerEventLogConstants.Tuple_CannotFindOAB, new object[]
                        {
                            oabgeneratorMailboxData.OfflineAddressBook
                        });
                    }
                }
                if (oabgeneratorTaskContext.OABsToGenerate == null || oabgeneratorTaskContext.OABsToGenerate.Count == 0)
                {
                    OABLogger.LogRecord(TraceType.InfoTrace, "InvokeInternal. No OABs found to generate for DatabaseGuid={0}, MailboxGuid={1}", new object[]
                    {
                        oabgeneratorMailboxData.DatabaseGuid,
                        oabgeneratorMailboxData.MailboxGuid.ToString(),
                        oabgeneratorMailboxData.Guid
                    });
                    if (oabgeneratorTaskContext.Cleanup != null)
                    {
                        oabgeneratorTaskContext.Cleanup(oabgeneratorTaskContext);
                    }
                    return(null);
                }
                OABLogger.LogRecord(TraceType.InfoTrace, "Found {0} OAB(s) to generate", new object[]
                {
                    oabgeneratorTaskContext.OABsToGenerate.Count
                });
                oabgeneratorTaskContext.CurrentOAB = oabgeneratorTaskContext.OABsToGenerate.Dequeue();
            }
            finally
            {
                OABLogger.LogRecord(TraceType.FunctionTrace, "OABGeneratorAssistant.InitialStep: finish", new object[0]);
                oabgeneratorTaskContext.OABStep = oabstep;
            }
            return(OABGeneratorTaskContext.FromOABGeneratorTaskContext(oabgeneratorTaskContext));
        }