public static void RemoveJsonLogs(this FolderConfig folderConfig) { Thread.Sleep(1000); GC.Collect(); GC.WaitForPendingFinalizers(); foreach (var filePath in folderConfig.GetFolderConfigJsonLogs()) { File.Delete(filePath); } }
private IEnumerable <(DateTime DateTime, IEnumerable <OperationEvent> OperationEvents)> GetOperationEventsFromFolderConfig(FolderConfig folderConfig) { bool isFirstTime = true; foreach (var filePath in folderConfig.GetFolderConfigJsonLogs()) { if (isFirstTime) { _logger.LogDebug("Getting OperationEvents from folder {folderPath}", folderConfig.FolderPath); isFirstTime = false; } string fileName = Path.GetFileName(filePath); var dateTime = fileName.GetCustomDateTime(); yield return(dateTime, _folderOperationEventsReader.ReadOperationEvents(filePath)); } }
/// <summary> /// Working on json files only /// </summary> /// <param name="folderConfig"></param> /// <param name="restorePointDirectoryPath"></param> /// <param name="logger"></param> public static void CreateRestorePoint(this FolderConfig folderConfig, string restorePointDirectoryPath, ILogger logger) { logger.LogDebug("Creating restore point for {folderConfig}", folderConfig.FolderPath); foreach (var filePath in folderConfig.GetFolderConfigJsonLogs()) { string path = Path.Combine(restorePointDirectoryPath, Path.GetFileName(filePath)); string destinationFilePath = path.Substring(0, path.Length - 5); int i = 1; while (File.Exists($"{ destinationFilePath }.json")) { destinationFilePath = $"{ path } { i++ }"; } File.Copy(filePath, $"{ destinationFilePath }.json"); logger.LogDebug("Copied {filePath} to {restorePointDirectoryPath}", filePath, restorePointDirectoryPath); } folderConfig.RemoveJsonLogContents(); logger.LogDebug("Removed json log file contents successfully"); }
public static void RemoveJsonLogContents(this FolderConfig folderConfig) { Thread.Sleep(1000); GC.Collect(); GC.WaitForPendingFinalizers(); foreach (var filePath in folderConfig.GetFolderConfigJsonLogs()) { if (Path.GetFileName(filePath).GetCustomDateTime() < DateTime.Now.Date) { File.Delete(filePath); } else { var fileStream = File.Open(filePath, FileMode.Open); fileStream.SetLength(0); fileStream.Close(); } } }