// Token: 0x06001190 RID: 4496 RVA: 0x00066CD0 File Offset: 0x00064ED0
        private AssistantTaskContext TrainStep(AssistantTaskContext context)
        {
            Guid guid = Guid.Empty;
            MailboxTrainingState     mailboxTrainingState     = null;
            MailboxTruthLoggingState mailboxTruthLoggingState = null;
            AssistantTaskContext     result;

            try
            {
                InferenceTrainingTaskContext assistantTaskContext = null;
                this.ValidateContext(context, delegate(AssistantTaskContext taskContext)
                {
                    assistantTaskContext = (taskContext as InferenceTrainingTaskContext);
                    ExAssert.RetailAssert(assistantTaskContext != null, "Assistant did not return InferenceTrainingTaskContext");
                });
                MailboxSession mailboxSession = assistantTaskContext.Args.StoreSession as MailboxSession;
                guid = assistantTaskContext.Args.StoreSession.MailboxGuid;
                mailboxTrainingState     = assistantTaskContext.MailboxTrainingState;
                mailboxTruthLoggingState = assistantTaskContext.MailboxTruthLoggingState;
                if (mailboxTrainingState.PrepareNextTrainingStep())
                {
                    this.DiagnosticsSession.TraceDebug <IExchangePrincipal>("{0}: Begin process mailbox for training", mailboxSession.MailboxOwner);
                    this.trainingFeeder.TrainMailbox(mailboxSession, mailboxTrainingState);
                    this.DiagnosticsSession.TraceDebug <IExchangePrincipal>("{0}: End process mailbox for training", mailboxSession.MailboxOwner);
                    mailboxTrainingState.MarkTrainingStepAsCompleted();
                    mailboxSession.Mailbox.Save();
                    result = new InferenceTrainingTaskContext(assistantTaskContext.MailboxData, assistantTaskContext.Job, new AssistantStep(this.TrainStep), mailboxTrainingState, mailboxTruthLoggingState);
                }
                else
                {
                    this.DiagnosticsSession.LogEvent(MSExchangeInferenceEventLogConstants.Tuple_TrainingStatisticsForMailbox, new object[]
                    {
                        mailboxSession.MailboxGuid.ToString()
                    });
                    result = new InferenceTrainingTaskContext(assistantTaskContext.MailboxData, assistantTaskContext.Job, new AssistantStep(this.TruthLogStep), mailboxTrainingState, mailboxTruthLoggingState);
                }
            }
            catch (Exception ex)
            {
                string text = string.Format("Reason=TrainStepFailed#Exception={0}", InferenceCommonUtility.StringizeException(ex));
                this.trainingStatusLogger.LogStatus(guid, 3, new DateTime?((mailboxTrainingState == null) ? DateTime.UtcNow : mailboxTrainingState.CurrentAttemptTimestamp), (mailboxTrainingState == null) ? null : mailboxTrainingState.LastAttemptTimestamp, (mailboxTrainingState == null) ? null : mailboxTrainingState.LastSuccessTimestamp, text);
                this.truthLabelsStatusLogger.LogStatus(guid, 3, new DateTime?((mailboxTruthLoggingState == null) ? DateTime.UtcNow : mailboxTruthLoggingState.CurrentAttemptTimestamp), (mailboxTruthLoggingState == null) ? null : mailboxTruthLoggingState.LastAttemptTimestamp, (mailboxTruthLoggingState == null) ? null : mailboxTruthLoggingState.LastSuccessTimestamp, text);
                this.groupingModelTrainingStatusLogger.LogStatus(guid, 3, text);
                if (ex is AbortOnProcessingRequestedException)
                {
                    result = null;
                }
                else
                {
                    if (!(ex is QuotaExceededException))
                    {
                        throw;
                    }
                    result = null;
                }
            }
            return(result);
        }
        // Token: 0x06001192 RID: 4498 RVA: 0x00067194 File Offset: 0x00065394
        private AssistantTaskContext GroupingModelTrainingStep(AssistantTaskContext context)
        {
            Guid guid = Guid.Empty;

            try
            {
                InferenceTrainingTaskContext assistantTaskContext = null;
                this.ValidateContext(context, delegate(AssistantTaskContext taskContext)
                {
                    assistantTaskContext = (taskContext as InferenceTrainingTaskContext);
                    ExAssert.RetailAssert(assistantTaskContext != null, "Assistant did not return InferenceTrainingTaskContext");
                });
                MailboxSession       mailboxSession       = assistantTaskContext.Args.StoreSession as MailboxSession;
                MailboxTrainingState mailboxTrainingState = assistantTaskContext.MailboxTrainingState;
                guid = assistantTaskContext.Args.StoreSession.MailboxGuid;
                if (mailboxTrainingState.FlightFeatures.Inference.InferenceGroupingModel.Enabled)
                {
                    this.DiagnosticsSession.TraceDebug <IExchangePrincipal>("{0}: Begin process mailbox for grouping model", mailboxSession.MailboxOwner);
                    GroupingModelVersionSelector groupingModelVersionSelector = new GroupingModelVersionSelector(InferenceTrainingAssistant.HookableGroupingModelConfiguration.Value);
                    GroupingModelTrainingContext groupingModelTrainingContext = new GroupingModelTrainingContext
                    {
                        ModelVersion = groupingModelVersionSelector.GetModelVersionToTrain()
                    };
                    this.groupingModelTrainingPipeline.TrainGroupingModel(mailboxSession, groupingModelTrainingContext);
                    this.DiagnosticsSession.TraceDebug <IExchangePrincipal>("{0}: End process mailbox for grouping model", mailboxSession.MailboxOwner);
                }
                else
                {
                    this.groupingModelTrainingStatusLogger.LogStatus(guid, 4, "User is not a member of grouping model flight");
                }
            }
            catch (Exception ex)
            {
                string text = string.Format("Reason=GroupingModelTrainingStepFailed#Exception={0}", InferenceCommonUtility.StringizeException(ex));
                this.groupingModelTrainingStatusLogger.LogStatus(guid, 3, text);
                if (ex is OutOfMemoryException || ex is StackOverflowException || ex is AccessViolationException)
                {
                    throw;
                }
                if (ex is QuotaExceededException)
                {
                    return(null);
                }
            }
            return(null);
        }
        // Token: 0x06001191 RID: 4497 RVA: 0x00066F64 File Offset: 0x00065164
        private AssistantTaskContext TruthLogStep(AssistantTaskContext context)
        {
            Guid guid = Guid.Empty;
            MailboxTruthLoggingState mailboxTruthLoggingState = null;
            AssistantTaskContext     result;

            try
            {
                InferenceTrainingTaskContext assistantTaskContext = null;
                this.ValidateContext(context, delegate(AssistantTaskContext taskContext)
                {
                    assistantTaskContext = (taskContext as InferenceTrainingTaskContext);
                    ExAssert.RetailAssert(assistantTaskContext != null, "Assistant did not return InferenceTrainingTaskContext");
                });
                MailboxSession       mailboxSession       = assistantTaskContext.Args.StoreSession as MailboxSession;
                MailboxTrainingState mailboxTrainingState = assistantTaskContext.MailboxTrainingState;
                mailboxTruthLoggingState = assistantTaskContext.MailboxTruthLoggingState;
                guid = assistantTaskContext.Args.StoreSession.MailboxGuid;
                if (this.isTruthLabelsLoggingEnabled)
                {
                    this.DiagnosticsSession.TraceDebug <IExchangePrincipal>("{0}: Begin process mailbox for truth labels logging", mailboxSession.MailboxOwner);
                    this.trainingFeeder.LogTruthLabels(mailboxSession, mailboxTruthLoggingState);
                    mailboxSession.Mailbox.Save();
                    this.DiagnosticsSession.TraceDebug <IExchangePrincipal>("{0}: End process mailbox for truth labels logging", mailboxSession.MailboxOwner);
                }
                else
                {
                    this.truthLabelsStatusLogger.LogStatus(guid, 5, new DateTime?((mailboxTruthLoggingState == null) ? DateTime.UtcNow : mailboxTruthLoggingState.CurrentAttemptTimestamp), (mailboxTruthLoggingState == null) ? null : mailboxTruthLoggingState.LastAttemptTimestamp, (mailboxTruthLoggingState == null) ? null : mailboxTruthLoggingState.LastSuccessTimestamp, "Truth labels logging is disabled");
                }
                result = new InferenceTrainingTaskContext(assistantTaskContext.MailboxData, assistantTaskContext.Job, new AssistantStep(this.GroupingModelTrainingStep), mailboxTrainingState, mailboxTruthLoggingState);
            }
            catch (Exception ex)
            {
                string text = string.Format("Reason=TruthLogStepFailed#Exception={0}", InferenceCommonUtility.StringizeException(ex));
                this.truthLabelsStatusLogger.LogStatus(guid, 3, new DateTime?((mailboxTruthLoggingState == null) ? DateTime.UtcNow : mailboxTruthLoggingState.CurrentAttemptTimestamp), (mailboxTruthLoggingState == null) ? null : mailboxTruthLoggingState.LastAttemptTimestamp, (mailboxTruthLoggingState == null) ? null : mailboxTruthLoggingState.LastSuccessTimestamp, text);
                this.groupingModelTrainingStatusLogger.LogStatus(guid, 3, text);
                if (ex is OutOfMemoryException || ex is StackOverflowException || ex is AccessViolationException)
                {
                    throw;
                }
                result = null;
            }
            return(result);
        }
        // Token: 0x0600118E RID: 4494 RVA: 0x000668D4 File Offset: 0x00064AD4
        public override AssistantTaskContext InitialStep(AssistantTaskContext context)
        {
            DateTime             utcNow    = DateTime.UtcNow;
            DateTime?            dateTime  = null;
            DateTime?            dateTime2 = null;
            DateTime?            dateTime3 = null;
            DateTime?            dateTime4 = null;
            Guid                 guid      = Guid.Empty;
            AssistantTaskContext result;

            try
            {
                this.ValidateContext(context);
                guid = context.Args.StoreSession.MailboxGuid;
                ExDateTime?valueOrDefault = context.Args.StoreSession.Mailbox.GetValueOrDefault <ExDateTime?>(MailboxSchema.InferenceTrainingLastAttemptTimestamp, null);
                if (valueOrDefault != null)
                {
                    dateTime = new DateTime?(valueOrDefault.Value.UniversalTime);
                }
                valueOrDefault = context.Args.StoreSession.Mailbox.GetValueOrDefault <ExDateTime?>(MailboxSchema.InferenceTrainingLastSuccessTimestamp, null);
                if (valueOrDefault != null)
                {
                    dateTime2 = new DateTime?(valueOrDefault.Value.UniversalTime);
                }
                valueOrDefault = context.Args.StoreSession.Mailbox.GetValueOrDefault <ExDateTime?>(MailboxSchema.InferenceTruthLoggingLastAttemptTimestamp, null);
                if (valueOrDefault != null)
                {
                    dateTime3 = new DateTime?(valueOrDefault.Value.UniversalTime);
                }
                valueOrDefault = context.Args.StoreSession.Mailbox.GetValueOrDefault <ExDateTime?>(MailboxSchema.InferenceTruthLoggingLastSuccessTimestamp, null);
                if (valueOrDefault != null)
                {
                    dateTime4 = new DateTime?(valueOrDefault.Value.UniversalTime);
                }
                MailboxSession mailboxSession = context.Args.StoreSession as MailboxSession;
                if (mailboxSession == null)
                {
                    string text = "Reason=NonMailboxSession";
                    this.trainingStatusLogger.LogStatus(guid, 4, new DateTime?(utcNow), dateTime, dateTime2, text);
                    this.truthLabelsStatusLogger.LogStatus(mailboxSession.MailboxGuid, 4, new DateTime?(utcNow), dateTime3, dateTime4, text);
                    this.groupingModelTrainingStatusLogger.LogStatus(guid, 4, text);
                    result = null;
                }
                else if (mailboxSession.MailboxOwner.RecipientTypeDetails != RecipientTypeDetails.UserMailbox && mailboxSession.MailboxOwner.RecipientTypeDetails != RecipientTypeDetails.LinkedMailbox)
                {
                    string text2 = string.Format("Reason=NonUserMailbox#Name={0}#Type={1}", mailboxSession.MailboxOwner.MailboxInfo.DisplayName, mailboxSession.MailboxOwner.RecipientTypeDetails.ToString());
                    this.trainingStatusLogger.LogStatus(mailboxSession.MailboxGuid, 4, new DateTime?(utcNow), dateTime, dateTime2, text2);
                    this.truthLabelsStatusLogger.LogStatus(mailboxSession.MailboxGuid, 4, new DateTime?(utcNow), dateTime3, dateTime4, text2);
                    this.groupingModelTrainingStatusLogger.LogStatus(mailboxSession.MailboxGuid, 4, text2);
                    result = null;
                }
                else
                {
                    VariantConfigurationSnapshot flightFeatures = FlightModule.GetFlightFeatures(mailboxSession);
                    Exception           ex;
                    OrganizationContext organizationInformation = this.orgContentExtractor.GetOrganizationInformation(mailboxSession.MailboxOwner, new ADRecipientInfo.TraceDelegate(this.DiagnosticsSession.TraceDebug), new ADRecipientInfo.TraceDelegate(this.DiagnosticsSession.TraceError), ref ex);
                    FolderDataSelectionConfig.RefreshSettings();
                    List <Exception> list = new List <Exception>();
                    if (ex != null)
                    {
                        list.Add(ex);
                    }
                    OutlookActivityManager.SafeProcess(mailboxSession);
                    ActivityHistory      activityHistory      = new ActivityHistory(mailboxSession, utcNow);
                    ModelVersionSelector modelVersionSelector = InferenceXsoUtil.CreateModelVersionSelector(ServerModelConfigurationWrapper.CurrentWrapper, mailboxSession, delegate(string str)
                    {
                        this.DiagnosticsSession.TraceDebug(str, new object[0]);
                    });
                    result = new InferenceTrainingTaskContext(context.MailboxData, context.Job, new AssistantStep(this.TrainStep), new MailboxTrainingState(modelVersionSelector, organizationInformation, activityHistory, utcNow, dateTime, dateTime2, flightFeatures, list), new MailboxTruthLoggingState(utcNow, dateTime3, dateTime4, activityHistory));
                }
            }
            catch (Exception ex2)
            {
                string text3 = string.Format("Reason=InitialStepFailed#Exception={0}", InferenceCommonUtility.StringizeException(ex2));
                this.trainingStatusLogger.LogStatus(guid, 3, new DateTime?(utcNow), dateTime, dateTime2, text3);
                this.truthLabelsStatusLogger.LogStatus(guid, 3, new DateTime?(utcNow), dateTime3, dateTime4, text3);
                this.groupingModelTrainingStatusLogger.LogStatus(guid, 3, text3);
                throw;
            }
            return(result);
        }