From ddbb5423aa6f2ce6b588ea32af2af236eade97f4 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Fri, 24 Oct 2025 21:10:52 +1000 Subject: [PATCH] another --- .../FileWatching/IdeFileExternalChangeHandler.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs index 488289f..1ba4c20 100644 --- a/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs +++ b/src/SharpIDE.Application/Features/FileWatching/IdeFileExternalChangeHandler.cs @@ -1,4 +1,5 @@ using Ardalis.GuardClauses; +using Microsoft.Extensions.Logging; using SharpIDE.Application.Features.Events; using SharpIDE.Application.Features.SolutionDiscovery; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; @@ -7,11 +8,13 @@ namespace SharpIDE.Application.Features.FileWatching; public class IdeFileExternalChangeHandler { + private readonly ILogger _logger; private readonly FileChangedService _fileChangedService; private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService; public SharpIdeSolutionModel SolutionModel { get; set; } = null!; - public IdeFileExternalChangeHandler(FileChangedService fileChangedService, SharpIdeSolutionModificationService sharpIdeSolutionModificationService) + public IdeFileExternalChangeHandler(FileChangedService fileChangedService, SharpIdeSolutionModificationService sharpIdeSolutionModificationService, ILogger logger) { + _logger = logger; _fileChangedService = fileChangedService; _sharpIdeSolutionModificationService = sharpIdeSolutionModificationService; GlobalEvents.Instance.FileSystemWatcherInternal.FileChanged.Subscribe(OnFileChanged); @@ -72,14 +75,13 @@ public class IdeFileExternalChangeHandler var sharpIdeFolder = SolutionModel.AllFolders.SingleOrDefault(f => f.Path == folderPath); if (sharpIdeFolder is not null) { - //Console.WriteLine($"Error - Folder {folderPath} already exists"); return; } var containingFolderPath = Path.GetDirectoryName(folderPath)!; var containingFolderOrProject = (IFolderOrProject?)SolutionModel.AllFolders.SingleOrDefault(f => f.ChildNodeBasePath == containingFolderPath) ?? SolutionModel.AllProjects.SingleOrDefault(s => s.ChildNodeBasePath == containingFolderPath); if (containingFolderOrProject is null) { - Console.WriteLine($"Error - Containing Folder or Project of {folderPath} does not exist"); + _logger.LogError("Containing Folder or Project of folder '{FolderPath}' does not exist", folderPath); return; } var folderName = Path.GetFileName(folderPath); @@ -101,7 +103,7 @@ public class IdeFileExternalChangeHandler var containingFolderOrProject = (IFolderOrProject?)SolutionModel.AllFolders.SingleOrDefault(f => f.ChildNodeBasePath == createdFileDirectory) ?? SolutionModel.AllProjects.SingleOrDefault(s => s.ChildNodeBasePath == createdFileDirectory); if (containingFolderOrProject is null) { - Console.WriteLine($"Error - Containing Folder or Project of {filePath} does not exist"); + _logger.LogError("Containing Folder or Project of file '{FilePath}' does not exist", filePath); return; } @@ -122,11 +124,11 @@ public class IdeFileExternalChangeHandler var now = DateTimeOffset.Now; if (now - sharpIdeFile.LastIdeWriteTime.Value < TimeSpan.FromMilliseconds(300)) { - Console.WriteLine($"IdeFileExternalChangeHandler: Ignored - {filePath}"); + _logger.LogTrace("File change ignored - recently modified by the IDE: '{FilePath}'", filePath); return; } } - Console.WriteLine($"IdeFileExternalChangeHandler: Changed - {filePath}"); + _logger.LogInformation("IdeFileExternalChangeHandler: Changed - '{FilePath}'", filePath); var file = SolutionModel.AllFiles.SingleOrDefault(f => f.Path == filePath); if (file is not null) {