示例#1
0
 public static Exception CleanupTemporaryFiles(string logFilePrefix, string destinationLogPath, out Exception exception)
 {
     exception = LastLogReplacer.HandleExceptions(delegate
     {
         string filter  = LastLogReplacer.BuildLogFileSearchPattern(logFilePrefix, ".ReplacementNew");
         string filter2 = LastLogReplacer.BuildLogFileSearchPattern(logFilePrefix, ".ReplacementOld");
         using (DirectoryEnumerator directoryEnumerator = new DirectoryEnumerator(new DirectoryInfo(destinationLogPath), false, false))
         {
             foreach (string path in directoryEnumerator.EnumerateFiles(filter, null))
             {
                 File.Delete(path);
             }
             foreach (string path2 in directoryEnumerator.EnumerateFiles(filter2, null))
             {
                 File.Delete(path2);
             }
         }
     });
     return(exception);
 }
示例#2
0
        internal static bool DoesContainAnyFiles(string directory, bool recurse, out Exception exception)
        {
            bool foundFiles = false;

            exception = MountPointUtil.HandleIOExceptions(delegate
            {
                DirectoryInfo path = new DirectoryInfo(directory);
                using (DirectoryEnumerator directoryEnumerator = new DirectoryEnumerator(path, recurse, false))
                {
                    IEnumerable <string> source = directoryEnumerator.EnumerateFiles("*", DirectoryEnumerator.ExcludeHiddenAndSystemFilter);
                    if (source.Any <string>())
                    {
                        foundFiles = true;
                    }
                }
            });
            return(foundFiles);
        }
示例#3
0
        public static bool AreTemporaryFilesPresent(string logFilePrefix, string destinationLogPath, out Exception exception)
        {
            bool fTempFilesPresent = false;

            exception = LastLogReplacer.HandleExceptions(delegate
            {
                string filter  = LastLogReplacer.BuildLogFileSearchPattern(logFilePrefix, ".ReplacementNew");
                string filter2 = LastLogReplacer.BuildLogFileSearchPattern(logFilePrefix, ".ReplacementOld");
                DirectoryInfo directoryInfo = new DirectoryInfo(destinationLogPath);
                if (!directoryInfo.Exists)
                {
                    fTempFilesPresent = false;
                    return;
                }
                using (DirectoryEnumerator directoryEnumerator = new DirectoryEnumerator(directoryInfo, false, false))
                {
                    fTempFilesPresent = (directoryEnumerator.EnumerateFiles(filter, null).Count <string>() > 0 || directoryEnumerator.EnumerateFiles(filter2, null).Count <string>() > 0);
                }
            });
            return(exception == null && fTempFilesPresent);
        }
示例#4
0
        public static void RollbackLastLogIfNecessary(IReplayConfiguration config)
        {
            Exception ex = LastLogReplacer.HandleExceptions(delegate
            {
                int num        = 0;
                int num2       = 0;
                string text    = null;
                string text2   = null;
                string text3   = EseHelper.MakeLogFilePath(config, 0L, config.DestinationLogPath);
                string filter  = LastLogReplacer.BuildLogFileSearchPattern(config.LogFilePrefix, ".ReplacementNew");
                string filter2 = LastLogReplacer.BuildLogFileSearchPattern(config.LogFilePrefix, ".ReplacementOld");
                using (DirectoryEnumerator directoryEnumerator = new DirectoryEnumerator(new DirectoryInfo(config.DestinationLogPath), false, false))
                {
                    foreach (string text4 in directoryEnumerator.EnumerateFiles(filter, null))
                    {
                        num++;
                        text = text4;
                    }
                    if (num > 1)
                    {
                        throw new LastLogReplacementTooManyTempFilesException(config.DisplayName, filter, num, config.DestinationLogPath);
                    }
                    foreach (string text5 in directoryEnumerator.EnumerateFiles(filter2, null))
                    {
                        num2++;
                        text2 = text5;
                    }
                    if (num2 > 1)
                    {
                        throw new LastLogReplacementTooManyTempFilesException(config.DisplayName, filter2, num2, config.DestinationLogPath);
                    }
                }
                if (num == 0 && num2 == 0)
                {
                    LastLogReplacer.Tracer.TraceDebug <string>(0L, "RollbackLastLogIfNecessary(): '{0}': Case 1: Nothing to do.", config.DisplayName);
                    return;
                }
                if (num == 1 && num2 == 0)
                {
                    LastLogReplacer.Tracer.TraceDebug <string, string>(0L, "RollbackLastLogIfNecessary(): '{0}': Case 2: Considering to delete temp new file: {1}", config.DisplayName, text);
                    LastLogReplacer.DeleteTempNewFile(config, text, text3);
                    return;
                }
                if (num == 1 && num2 == 1)
                {
                    LastLogReplacer.Tracer.TraceDebug(0L, "RollbackLastLogIfNecessary(): '{0}': Case 3: Rolling back temp file '{1}' to '{2}' and considering to delete temp new file: {3}", new object[]
                    {
                        config.DisplayName,
                        text2,
                        text3,
                        text
                    });
                    File.Move(text2, text3);
                    LastLogReplacer.DeleteTempNewFile(config, text, text3);
                    return;
                }
                if (num == 0 && num2 == 1)
                {
                    LastLogReplacer.Tracer.TraceDebug <string, string>(0L, "RollbackLastLogIfNecessary(): '{0}': Case 4: Considering moving out temp old file '{1}' to IgnoredLogs directory.", config.DisplayName, text2);
                    LastLogReplacer.DeleteTempOldFile(config, text2);
                    return;
                }
                LastLogReplacer.Tracer.TraceError <string, int, int>(0L, "RollbackLastLogIfNecessary(): '{0}': Unexpected temporary files found. tempOldFileCount={1}, tempNewFileCount={2}, e00Exists=false", config.DisplayName, num2, num);
                throw new LastLogReplacementUnexpectedTempFilesException(config.DisplayName, config.DestinationLogPath);
            });

            if (ex != null)
            {
                throw new LastLogReplacementRollbackFailedException(config.DisplayName, ex.Message, ex);
            }
        }