From 3ceb01eba755ebddb99e73ee8f53c51bc4be0478 Mon Sep 17 00:00:00 2001 From: Luiz Zen Date: Tue, 3 Oct 2023 21:18:03 -0300 Subject: [PATCH] Paths as string using Directory.EnumerateFiles() --- .../ILiveProjectFileExtractionHandler.cs | 2 +- .../Interfaces/ILiveProjectFileSystem.cs | 4 +-- .../Services/LiveProjectAsyncService.cs | 11 ++++---- .../FileSystem/LiveProjectFileSystem.cs | 25 +++++++++---------- .../LiveProjectFileExtractionHandler.cs | 10 +++++--- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/als-tools.core/Interfaces/ILiveProjectFileExtractionHandler.cs b/src/als-tools.core/Interfaces/ILiveProjectFileExtractionHandler.cs index 3899617..50793e4 100644 --- a/src/als-tools.core/Interfaces/ILiveProjectFileExtractionHandler.cs +++ b/src/als-tools.core/Interfaces/ILiveProjectFileExtractionHandler.cs @@ -4,5 +4,5 @@ namespace AlsTools.Core.Interfaces; public interface ILiveProjectFileExtractionHandler { - LiveProject ExtractProjectFromFile(FileInfo file); + LiveProject ExtractProjectFromFile(string projectFileFullPath); } diff --git a/src/als-tools.core/Interfaces/ILiveProjectFileSystem.cs b/src/als-tools.core/Interfaces/ILiveProjectFileSystem.cs index e898f5f..ba5452d 100644 --- a/src/als-tools.core/Interfaces/ILiveProjectFileSystem.cs +++ b/src/als-tools.core/Interfaces/ILiveProjectFileSystem.cs @@ -2,7 +2,7 @@ namespace AlsTools.Core.Interfaces; public interface ILiveProjectFileSystem { - IReadOnlyList LoadProjectFilesFromDirectories(IEnumerable folderPaths, bool includeBackupFolder); + IReadOnlyList GetProjectFilesFullPathFromDirectories(IEnumerable folderPaths, bool includeBackupFolder); - IReadOnlyList LoadProjectFilesFromSetFiles(IEnumerable setFilePaths); + IReadOnlyList GetProjectFilesFullPathFromSetFiles(IEnumerable setFilePaths); } diff --git a/src/als-tools.core/Services/LiveProjectAsyncService.cs b/src/als-tools.core/Services/LiveProjectAsyncService.cs index 881d6e7..a816731 100644 --- a/src/als-tools.core/Services/LiveProjectAsyncService.cs +++ b/src/als-tools.core/Services/LiveProjectAsyncService.cs @@ -1,7 +1,6 @@ using AlsTools.Core.Entities; using AlsTools.Core.Enums; using AlsTools.Core.Interfaces; -using AlsTools.Core.ValueObjects; using AlsTools.Core.ValueObjects.Devices; namespace AlsTools.Core.Services; @@ -113,25 +112,25 @@ public async Task> GetPluginUsageResults(IList LoadProjectsFromSetFiles(IEnumerable filePaths) { - var files = fs.LoadProjectFilesFromSetFiles(filePaths); + var files = fs.GetProjectFilesFullPathFromSetFiles(filePaths); return ExtractProjectsFromFiles(files); } private IReadOnlyList LoadProjectsFromDirectories(IEnumerable folderPaths, bool includeBackupFolder) { - var files = fs.LoadProjectFilesFromDirectories(folderPaths, includeBackupFolder); + var files = fs.GetProjectFilesFullPathFromDirectories(folderPaths, includeBackupFolder); return ExtractProjectsFromFiles(files); } - private IReadOnlyList ExtractProjectsFromFiles(IEnumerable files) + private IReadOnlyList ExtractProjectsFromFiles(IEnumerable filePaths) { var projects = new List(); - foreach (var f in files) + foreach (var filePath in filePaths) { - var project = extractor.ExtractProjectFromFile(f); + var project = extractor.ExtractProjectFromFile(filePath); projects.Add(project); } diff --git a/src/als-tools.infrastructure/FileSystem/LiveProjectFileSystem.cs b/src/als-tools.infrastructure/FileSystem/LiveProjectFileSystem.cs index 1b65531..d2d26d4 100644 --- a/src/als-tools.infrastructure/FileSystem/LiveProjectFileSystem.cs +++ b/src/als-tools.infrastructure/FileSystem/LiveProjectFileSystem.cs @@ -10,43 +10,42 @@ public LiveProjectFileSystem(UserFolderHandler userFolderHandler) { this.userFolderHandler = userFolderHandler; } - - public IReadOnlyList LoadProjectFilesFromDirectories(IEnumerable folderPaths, bool includeBackupFolder) + + public IReadOnlyList GetProjectFilesFullPathFromDirectories(IEnumerable folderPaths, bool includeBackupFolder) { - var result = new List(); + var result = new List(); foreach (var folderPath in folderPaths) { - var files = GetProjectFilesFromSingleDirectory(folderPath, includeBackupFolder); - result.AddRange(files); + var fileFullPaths = GetProjectFilesFullPathFromSingleDirectory(folderPath, includeBackupFolder); + result.AddRange(fileFullPaths); } return result; } - public IReadOnlyList LoadProjectFilesFromSetFiles(IEnumerable setFilePaths) + public IReadOnlyList GetProjectFilesFullPathFromSetFiles(IEnumerable setFilePaths) { - var result = new List(); + var result = new List(); foreach (var filePath in setFilePaths) { var file = GetProjectFileFromSetFile(filePath); - result.Add(file); + result.Add(file.FullName); } return result; } - private IReadOnlyCollection GetProjectFilesFromSingleDirectory(string folderPath, bool includeBackupFolder) + private IReadOnlyCollection GetProjectFilesFullPathFromSingleDirectory(string folderPath, bool includeBackupFolder) { var path = userFolderHandler.GetFullPath(folderPath); - var dirInfo = new DirectoryInfo(path); - var files = dirInfo.GetFiles("*.als", new EnumerationOptions() { RecurseSubdirectories = true }).AsEnumerable(); + var fullPaths = Directory.EnumerateFiles(path, "*.als", SearchOption.AllDirectories); if (!includeBackupFolder) - files = files.Where(x => !x.FullName.Contains(@"/Backup/", StringComparison.InvariantCultureIgnoreCase)); + fullPaths = fullPaths.Where(path => !path.Contains(@"/Backup/", StringComparison.InvariantCultureIgnoreCase)); - return files.ToList(); + return fullPaths.ToList(); } private FileInfo GetProjectFileFromSetFile(string setFilePath) diff --git a/src/als-tools.infrastructure/Handlers/LiveProjectFileExtractionHandler.cs b/src/als-tools.infrastructure/Handlers/LiveProjectFileExtractionHandler.cs index 7a7948a..ff3a171 100644 --- a/src/als-tools.infrastructure/Handlers/LiveProjectFileExtractionHandler.cs +++ b/src/als-tools.infrastructure/Handlers/LiveProjectFileExtractionHandler.cs @@ -28,13 +28,14 @@ public LiveProjectFileExtractionHandler(ILogger