// Token: 0x06001996 RID: 6550 RVA: 0x0006AD10 File Offset: 0x00068F10
        protected void CreateDirectoryIfNecessary(string directoryPath)
        {
            Exception ex = DirectoryOperations.TryCreateDirectory(directoryPath);

            if (ex != null)
            {
                this.LogError(ReplayStrings.SeederFailedToCreateDirectory(directoryPath, ex.ToString()));
            }
        }
 protected void SetupWatcher()
 {
     DirectoryOperations.ProbeDirectory(this.m_sourceDir);
     this.m_fileWatcher.Database            = this;
     this.m_fileWatcher.Path                = this.m_sourceDir;
     this.m_fileWatcher.Filter              = this.m_logPrefix + '*' + this.m_logSuffix;
     this.m_fileWatcher.NotifyFilter        = (NotifyFilters.FileName | NotifyFilters.LastWrite);
     this.m_fileWatcher.Created            += MonitoredDatabase.DirectoryChangeEvent;
     this.m_fileWatcher.Renamed            += new RenamedEventHandler(MonitoredDatabase.DirectoryChangeEvent);
     this.m_fileWatcher.EnableRaisingEvents = true;
 }
        // Token: 0x06000A21 RID: 2593 RVA: 0x0002F2C0 File Offset: 0x0002D4C0
        public static void MoveLogFiles(ReplayConfiguration config, FileState fileState, ISetBroken setBroken, long corruptLogGen)
        {
            string    text = Path.Combine(config.E00LogBackupPath, "SkippedLogs");
            Exception ex   = DirectoryOperations.TryCreateDirectory(text);

            if (ex != null)
            {
                setBroken.SetBroken(FailureTag.Configuration, ReplayEventLogConstants.Tuple_FailedToCreateDirectory, ex, new string[]
                {
                    text,
                    ex.ToString()
                });
                return;
            }
            string currentDateString = FileOperations.GetCurrentDateString();
            string text2             = Path.Combine(text, currentDateString);

            ex = DirectoryOperations.TryCreateDirectory(text2);
            if (ex != null)
            {
                setBroken.SetBroken(FailureTag.Configuration, ReplayEventLogConstants.Tuple_FailedToCreateDirectory, ex, new string[]
                {
                    text2,
                    ex.ToString()
                });
                return;
            }
            string destinationLogPath = config.DestinationLogPath;
            string text3 = string.Empty;
            string path  = string.Empty;

            try
            {
                ReplayEventLogConstants.Tuple_MovingFilesToRestartLogStream.LogEvent(null, new object[]
                {
                    config.DatabaseName,
                    EseHelper.MakeLogfileName(config.LogFilePrefix, config.LogFileSuffix, corruptLogGen),
                    text2
                });
                foreach (string text4 in Directory.GetFiles(destinationLogPath, "*." + config.LogExtension))
                {
                    text3 = text4;
                    path  = Path.GetFileName(text4);
                    long logfileGenerationFromFilePath = EseHelper.GetLogfileGenerationFromFilePath(text4, config.LogFilePrefix);
                    if (logfileGenerationFromFilePath >= fileState.LowestGenerationRequired)
                    {
                        ExTraceGlobals.ReplicaInstanceTracer.TraceError <string>(0L, "MoveLogFiles(): Cannot move logfile '{0}' because it is required by the database.", text4);
                    }
                    else
                    {
                        File.Move(text4, Path.Combine(text2, path));
                    }
                }
                foreach (string text5 in Directory.GetFiles(destinationLogPath, "*.jsl"))
                {
                    text3 = text5;
                    path  = Path.GetFileName(text5);
                    File.Move(text5, Path.Combine(text2, path));
                }
                ExTraceGlobals.ReplicaInstanceTracer.TraceError <string>(0L, "Moved log files successfully from '{0}'", config.DestinationLogPath);
            }
            catch (IOException ex2)
            {
                ExTraceGlobals.ReplicaInstanceTracer.TraceError <string, string, IOException>(0L, "Moving file '{0}' to '{1}' failed with exception: {2}", text3, text2, ex2);
                setBroken.SetBroken(ReplicaInstance.IOExceptionToFailureTag(ex2), ReplayEventLogConstants.Tuple_CouldNotDeleteLogFile, ex2, new string[]
                {
                    text3,
                    ex2.ToString()
                });
            }
            catch (UnauthorizedAccessException ex3)
            {
                ExTraceGlobals.ReplicaInstanceTracer.TraceError <string, string, UnauthorizedAccessException>(0L, "Moving file '{0}' to '{1}' failed with exception: {2}", text3, text2, ex3);
                setBroken.SetBroken(FailureTag.AlertOnly, ReplayEventLogConstants.Tuple_CouldNotDeleteLogFile, ex3, new string[]
                {
                    text3,
                    ex3.ToString()
                });
            }
        }
        // Token: 0x06000A20 RID: 2592 RVA: 0x0002F20C File Offset: 0x0002D40C
        public static void DeleteSkippedLogs(string ignoredLogsDirectory, string databaseName, bool deleteAllFiles)
        {
            string text = Path.Combine(ignoredLogsDirectory, "SkippedLogs");

            if (!Directory.Exists(text))
            {
                ExTraceGlobals.ReplicaInstanceTracer.TraceDebug <string, string>(0L, "DeleteSkippedLogs(): Skipped logs directory '{0}' for database '{1}' doesn't exist.", text, databaseName);
                return;
            }
            foreach (string path in Directory.GetDirectories(text))
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(path);
                if ((deleteAllFiles || DateTime.UtcNow.Subtract(directoryInfo.CreationTimeUtc) > TimeSpan.FromSeconds((double)RegistryParameters.SkippedLogsDeleteAfterAgeInSecs)) && DirectoryOperations.TryDeleteDirectoryRecursively(directoryInfo) == null)
                {
                    ReplayEventLogConstants.Tuple_DeletedSkippedLogsDirectory.LogEvent(null, new object[]
                    {
                        databaseName,
                        directoryInfo.FullName
                    });
                }
            }
        }
        public MonitoredDatabaseInitException StartMonitoring()
        {
            Exception ex = null;

            MonitoredDatabase.Tracer.TraceDebug <string, Guid>((long)this.GetHashCode(), "StartMonitoring: '{0}' {1}", this.DatabaseName, this.DatabaseGuid);
            try
            {
                if (!this.m_fPassive)
                {
                    this.SetupWatcher();
                }
                ExTraceGlobals.FaultInjectionTracer.TraceTest(2294689085U);
                TimeSpan invokeTimeout = TimeSpan.FromSeconds((double)RegistryParameters.StartupLogScanTimeoutInSec);
                InvokeWithTimeout.Invoke(delegate()
                {
                    this.DetermineEndOfLog();
                }, invokeTimeout);
                if (!this.m_fPassive)
                {
                    this.m_selfCheckEnabled = true;
                }
                MonitoredDatabase.Tracer.TraceDebug <string, long>((long)this.GetHashCode(), "Monitoring database {0}. EOL=0x{1:x}", this.m_config.DatabaseName, this.m_currentEndOfLog.Generation);
            }
            catch (TimeoutException ex2)
            {
                ex = ex2;
            }
            catch (ArgumentException ex3)
            {
                ex = ex3;
            }
            catch (IOException ex4)
            {
                ex = ex4;
            }
            catch (UnauthorizedAccessException ex5)
            {
                ex = ex5;
            }
            catch (EsentErrorException ex6)
            {
                ex = ex6;
            }
            if (ex != null)
            {
                string text = string.Format("0x{0:X}", ex.HResult);
                MonitoredDatabase.Tracer.TraceError <string, string, Exception>((long)this.GetHashCode(), "StartMonitoring database {0} failed with HRESULT {1} exception {2}", this.m_config.DatabaseName, text, ex);
                ReplayCrimsonEvents.MonitoredDBFailedToStart.LogPeriodic <Guid, string, string, string, string, string>(this.DatabaseName, DiagCore.DefaultEventSuppressionInterval, this.DatabaseGuid, this.DatabaseName, ex.Message, text, ex.ToString(), this.m_sourceDir);
                if (this.IsPassiveCopy)
                {
                    ReplayEventLogConstants.Tuple_PassiveMonitoredDBFailedToStart.LogEvent(this.Identity, new object[]
                    {
                        this.DatabaseName,
                        ex.ToString()
                    });
                }
                else
                {
                    FailureTag  failureTag = FailureTag.MonitoredDatabaseFailed;
                    IOException ex7        = ex as IOException;
                    if (ex7 != null && DirectoryOperations.IsPathOnLockedVolume(this.m_sourceDir))
                    {
                        failureTag = FailureTag.LockedVolume;
                    }
                    ReplayEventLogConstants.Tuple_ActiveMonitoredDBFailedToStart.LogEvent(this.Identity, new object[]
                    {
                        this.DatabaseName,
                        ex.ToString()
                    });
                    FailureItemPublisherHelper.PublishAction(failureTag, this.DatabaseGuid, this.DatabaseName);
                }
                this.StopMonitoring();
                return(new MonitoredDatabaseInitException(this.DatabaseName, ex.Message, ex));
            }
            return(null);
        }