private static Exception ReseedCatalog(CatalogAutoReseedWorkflow workflow)
        {
            Exception result = null;

            using (SeederClient seederClient = SeederClient.Create(workflow.Context.TargetServerName.Fqdn, workflow.Context.Database.Name, null, workflow.Context.TargetServer.AdminDisplayVersion))
            {
                bool flag = false;
                for (int i = 0; i <= 1; i++)
                {
                    result = null;
                    try
                    {
                        if (flag)
                        {
                            seederClient.EndDbSeed(workflow.Context.Database.Guid);
                        }
                        AutoReseedWorkflow.Tracer.TraceDebug((long)workflow.GetHashCode(), "CatalogAutoReseedWorkflow: Attempt({0}) to reseed catalog for database copy '{1}\\{2}' from {3}.", new object[]
                        {
                            i,
                            workflow.Context.Database.Name,
                            workflow.Context.TargetServerName,
                            string.IsNullOrEmpty(workflow.sourceName) ? "Active" : workflow.sourceName
                        });
                        SeederRpcFlags reseedRPCReason = CatalogAutoReseedWorkflow.GetReseedRPCReason(workflow.catalogReseedReason);
                        seederClient.PrepareDbSeedAndBegin(workflow.Context.Database.Guid, false, false, false, false, false, true, string.Empty, null, workflow.sourceName, null, null, reseedRPCReason);
                        break;
                    }
                    catch (SeederInstanceAlreadyInProgressException ex)
                    {
                        result = ex;
                        break;
                    }
                    catch (SeederInstanceAlreadyFailedException ex2)
                    {
                        result = ex2;
                        flag   = true;
                    }
                    catch (SeederServerException ex3)
                    {
                        result = ex3;
                    }
                    catch (SeederServerTransientException ex4)
                    {
                        result = ex4;
                    }
                    if (!string.IsNullOrEmpty(workflow.sourceName))
                    {
                        workflow.sourceName = string.Empty;
                    }
                }
            }
            return(result);
        }
        // Token: 0x060018F9 RID: 6393 RVA: 0x00066AF0 File Offset: 0x00064CF0
        private bool TryLaunchCatalogAutoReseedWorkflow(AutoReseedContext context, string dbName)
        {
            string text         = string.Empty;
            Trace  tracer       = AutoReseedWorkflowLauncher.Tracer;
            long   id           = (long)this.GetHashCode();
            string formatString = "AutoReseedWorkflowLauncher.TryLaunchCatalogAutoReseedWorkflow: Database '{0}' ContentIndexStatus is {1}, ContentIndexBacklog is {2}, ContentIndexRetryQueueSize is {3}, ContentIndexVersion is {4}, LatestQueryVersion is {5}, any target DB with version==LastQueryVersion is {6}.";

            object[] array = new object[7];
            array[0] = dbName;
            array[1] = context.TargetCopyStatus.CopyStatus.ContentIndexStatus;
            array[2] = context.TargetCopyStatus.CopyStatus.ContentIndexBacklog;
            array[3] = context.TargetCopyStatus.CopyStatus.ContentIndexRetryQueueSize;
            array[4] = context.TargetCopyStatus.CopyStatus.ContentIndexVersion;
            object[]    array2 = array;
            int         num    = 5;
            VersionInfo latest = VersionInfo.Latest;

            array2[num] = latest.QueryVersion;
            array[6]    = context.CopyStatusesForTargetDatabase.Any(delegate(CopyStatusClientCachedEntry status)
            {
                if (status.Result == CopyStatusRpcResult.Success && status.CopyStatus.ContentIndexVersion != null)
                {
                    int value3          = status.CopyStatus.ContentIndexVersion.Value;
                    VersionInfo latest4 = VersionInfo.Latest;
                    return(value3 == latest4.QueryVersion);
                }
                return(false);
            });
            tracer.TraceDebug(id, formatString, array);
            CatalogAutoReseedWorkflow.CatalogAutoReseedReason catalogAutoReseedReason;
            if (context.TargetCopyStatus.CopyStatus.ContentIndexStatus == ContentIndexStatusType.FailedAndSuspended)
            {
                if (context.TargetCopyStatus.CopyStatus.ContentIndexErrorCode != null)
                {
                    catalogAutoReseedReason = this.MapErrorCodeToReseedReason(context.TargetCopyStatus.CopyStatus.ContentIndexErrorCode.Value);
                }
                else
                {
                    catalogAutoReseedReason = CatalogAutoReseedWorkflow.CatalogAutoReseedReason.Unknown;
                }
                text = context.TargetCopyStatus.CopyStatus.ContentIndexErrorMessage;
                AutoReseedWorkflowLauncher.Tracer.TraceDebug <string, CatalogAutoReseedWorkflow.CatalogAutoReseedReason, string>((long)this.GetHashCode(), "AutoReseedWorkflowLauncher.TryLaunchCatalogAutoReseedWorkflow: Database '{0}' has Failed and suspended catalog, will reseed with reason {1}, errorMessage is {2}.", dbName, catalogAutoReseedReason, text);
            }
            else if (context.TargetCopyStatus.CopyStatus.ContentIndexBacklog != null && context.TargetCopyStatus.CopyStatus.ContentIndexBacklog.Value > RegistryParameters.AutoReseedCiBehindBacklog)
            {
                catalogAutoReseedReason = CatalogAutoReseedWorkflow.CatalogAutoReseedReason.BehindBacklog;
                text = ReplayStrings.AutoReseedCatalogIsBehindBacklog(context.TargetCopyStatus.CopyStatus.ContentIndexBacklog.GetValueOrDefault());
                AutoReseedWorkflowLauncher.Tracer.TraceDebug <string, int, string>((long)this.GetHashCode(), "AutoReseedWorkflowLauncher.TryLaunchCatalogAutoReseedWorkflow: Database '{0}' will reseed. Reason is BehindBacklog, AutoReseedCiBehindBacklog is {1}, errorMessage is {2}.", dbName, RegistryParameters.AutoReseedCiBehindBacklog, text);
            }
            else
            {
                if (context.TargetCopyStatus.CopyStatus.ContentIndexRetryQueueSize == null || context.TargetCopyStatus.CopyStatus.ContentIndexRetryQueueSize.Value <= RegistryParameters.AutoReseedCiBehindRetryCount)
                {
                    if (context.TargetCopyStatus.CopyStatus.ContentIndexVersion != null)
                    {
                        int         value   = context.TargetCopyStatus.CopyStatus.ContentIndexVersion.Value;
                        VersionInfo latest2 = VersionInfo.Latest;
                        if (value < latest2.QueryVersion)
                        {
                            if (context.CopyStatusesForTargetDatabase.Any(delegate(CopyStatusClientCachedEntry status)
                            {
                                if (status.Result == CopyStatusRpcResult.Success && status.CopyStatus.ContentIndexVersion != null)
                                {
                                    int value3 = status.CopyStatus.ContentIndexVersion.Value;
                                    VersionInfo latest4 = VersionInfo.Latest;
                                    return(value3 == latest4.QueryVersion);
                                }
                                return(false);
                            }))
                            {
                                catalogAutoReseedReason = CatalogAutoReseedWorkflow.CatalogAutoReseedReason.Upgrade;
                                int         value2  = context.TargetCopyStatus.CopyStatus.ContentIndexVersion.Value;
                                VersionInfo latest3 = VersionInfo.Latest;
                                text = ReplayStrings.AutoReseedCatalogToUpgrade(value2, latest3.QueryVersion);
                                AutoReseedWorkflowLauncher.Tracer.TraceDebug <string, string>((long)this.GetHashCode(), "AutoReseedWorkflowLauncher.TryLaunchCatalogAutoReseedWorkflow: Database '{0}' will reseed with reason Upgrade, errorMessage is {1}", dbName, text);
                                goto IL_330;
                            }
                        }
                    }
                    AutoReseedWorkflowLauncher.Tracer.TraceDebug <string>((long)this.GetHashCode(), "AutoReseedWorkflowLauncher.TryLaunchCatalogAutoReseedWorkflow: Database '{0}' has no reason to reseed.", dbName);
                    return(false);
                }
                catalogAutoReseedReason = CatalogAutoReseedWorkflow.CatalogAutoReseedReason.BehindRetry;
                text = ReplayStrings.AutoReseedCatalogIsBehindRetry(context.TargetCopyStatus.CopyStatus.ContentIndexRetryQueueSize.GetValueOrDefault());
                AutoReseedWorkflowLauncher.Tracer.TraceDebug <string, int, string>((long)this.GetHashCode(), "AutoReseedWorkflowLauncher.TryLaunchCatalogAutoReseedWorkflow: Database '{0}' will reseed. Reason is BehindBacklog, AutoReseedCiBehindBacklog is {1}, errorMessage is {2}.", dbName, RegistryParameters.AutoReseedCiBehindBacklog, text);
            }
IL_330:
            AutoReseedWorkflowLauncher.Tracer.TraceDebug((long)this.GetHashCode(), "AutoReseedWorkflowLauncher.BeginAutoReseedIfNecessary: AutoReseed workflow launcher detected a {0} catalog for database '{1}' [{2}]: {3}.", new object[]
            {
                context.TargetCopyStatus.CopyStatus.CopyStatus,
                context.Database.Name,
                context.Database.Guid,
                text
            });
            ReplayCrimsonEvents.AutoReseedWorkflowDetectedFailedCatalog.Log <string, Guid, string, string>(context.Database.Name, context.Database.Guid, "CatalogAutoReseedWorkflow", text);
            if (this.m_suppression.ReportWorkflowLaunchConditionMet(AutoReseedWorkflowType.CatalogAutoReseed, context.Database.Guid, catalogAutoReseedReason, context.TargetCopyStatus.CopyStatus.ActivationPreference))
            {
                AutoReseedWorkflowLauncher.Tracer.TraceDebug((long)this.GetHashCode(), "AutoReseedWorkflowLauncher.BeginAutoReseedIfNecessary: Database copy '{0}\\{1}' has catalog in {2} state for at least {3}. Launching the recovery workflow. Reason is {4}, ActivationPreference is {5}.", new object[]
                {
                    context.Database.Name,
                    context.TargetServerName,
                    context.TargetCopyStatus.CopyStatus.CopyStatus,
                    AutoReseedWorkflowSuppression.s_ciReseedSuppresionInterval,
                    catalogAutoReseedReason,
                    context.TargetCopyStatus.CopyStatus.ActivationPreference
                });
                CatalogAutoReseedWorkflow catalogAutoReseedWorkflow = new CatalogAutoReseedWorkflow(context, catalogAutoReseedReason, text);
                catalogAutoReseedWorkflow.Execute();
            }
            else
            {
                AutoReseedWorkflowLauncher.Tracer.TraceDebug((long)this.GetHashCode(), "AutoReseedWorkflowLauncher.BeginAutoReseedIfNecessary: Database copy '{0}\\{1}' has catalog in {2} state but launching the recovery workflow is being skipped due to either initial suppression of {3}, or periodic suppression of {4}. Reason is {5}, ActivationPreference is {6}", new object[]
                {
                    context.Database.Name,
                    context.TargetServerName,
                    context.TargetCopyStatus.CopyStatus.CopyStatus,
                    AutoReseedWorkflowSuppression.s_ciReseedSuppresionInterval,
                    AutoReseedWorkflowSuppression.s_ciReseedRetryInterval,
                    catalogAutoReseedReason,
                    context.TargetCopyStatus.CopyStatus.ActivationPreference
                });
            }
            return(true);
        }