From 0f95c74b64f07febf213171670e81895c77b3f59 Mon Sep 17 00:00:00 2001 From: aHjelmgaard Date: Wed, 15 Apr 2026 17:41:48 +0200 Subject: [PATCH 1/2] finished task 1 --- .../Application/DependencyGraphBuilder.cs | 5 +++-- CoDepend/Application/UpdateGraphUseCase.cs | 7 ++++++ CoDepend/Domain/DependencyGraphSerializer.cs | 13 +++++++++++ CoDepend/Infra/Logger.cs | 22 +++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 CoDepend/Infra/Logger.cs diff --git a/CoDepend/Application/DependencyGraphBuilder.cs b/CoDepend/Application/DependencyGraphBuilder.cs index 44446e6..725253d 100644 --- a/CoDepend/Application/DependencyGraphBuilder.cs +++ b/CoDepend/Application/DependencyGraphBuilder.cs @@ -8,6 +8,7 @@ using CoDepend.Domain.Models; using CoDepend.Domain.Models.Records; using CoDepend.Domain.Utils; +using CoDepend.Infra; namespace CoDepend.Application; @@ -100,7 +101,7 @@ private async Task TryClassifyItem( } } catch (OperationCanceledException) { throw; } - catch (Exception ex) { await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}"); } + catch (Exception ex) { Logger.LogError($"Error while processing '{item.Value}': {ex}"); } } private async Task Deps)>> ParseAllAsync( @@ -132,7 +133,7 @@ await Parallel.ForEachAsync( catch (OperationCanceledException) { throw; } catch (Exception ex) { - await Console.Error.WriteLineAsync($"Error while processing '{item.Value}': {ex}"); + Logger.LogError($"Error while processing '{item.Value}': {ex}"); return null; } } diff --git a/CoDepend/Application/UpdateGraphUseCase.cs b/CoDepend/Application/UpdateGraphUseCase.cs index 34504e3..3d2003e 100644 --- a/CoDepend/Application/UpdateGraphUseCase.cs +++ b/CoDepend/Application/UpdateGraphUseCase.cs @@ -6,6 +6,7 @@ using CoDepend.Domain.Interfaces; using CoDepend.Domain.Models.Enums; using CoDepend.Domain.Models.Records; +using CoDepend.Infra; namespace CoDepend.Application; @@ -30,11 +31,17 @@ public async Task RunAsync(CancellationToken ct = default) { if (diff) { + Logger.LogInformation("Running diff use case"); + var compareGraph = await snapshotManager.GetLastSavedDependencyGraphAsync(snapshotOptions, ct) ?? throw new InvalidOperationException("Diff mode requires a saved snapshot, but none was found."); await renderer.RenderDiffViewsAndSaveToFiles(graph, compareGraph, renderOptions, ct); } else + { + Logger.LogInformation("Running non-diff use case"); + await renderer.RenderViewsAndSaveToFiles(graph, renderOptions, ct); + } } await snapshotManager.SaveGraphAsync(graph, snapshotOptions, ct); diff --git a/CoDepend/Domain/DependencyGraphSerializer.cs b/CoDepend/Domain/DependencyGraphSerializer.cs index 709109a..bc4e2b9 100644 --- a/CoDepend/Domain/DependencyGraphSerializer.cs +++ b/CoDepend/Domain/DependencyGraphSerializer.cs @@ -3,6 +3,7 @@ using System.Linq; using CoDepend.Domain.Models; using CoDepend.Domain.Models.Records; +using CoDepend.Infra; using MessagePack; using MessagePack.Resolvers; @@ -109,6 +110,18 @@ public static byte[] Serialize(ProjectDependencyGraph graph, int version = 1) DependsOn = dependsOn, }; + byte[] serializedResult = MessagePackSerializer.Serialize(dto, MsgPackOptions); + + if (serializedResult.Length < 0) + { + Logger.LogInformation($"Size of serialized result: {serializedResult.Length.ToString()}"); + } + else + { + Logger.LogWarning($"The serialized result is empty"); + } + + return MessagePackSerializer.Serialize(dto, MsgPackOptions); } diff --git a/CoDepend/Infra/Logger.cs b/CoDepend/Infra/Logger.cs new file mode 100644 index 0000000..6a49385 --- /dev/null +++ b/CoDepend/Infra/Logger.cs @@ -0,0 +1,22 @@ + +using System; + +namespace CoDepend.Infra; + +public static class Logger +{ + public static void LogInformation(string message) + { + Console.WriteLine($"INFO: {message}"); + } + + public static void LogWarning(string message) + { + Console.WriteLine($"WARN: {message}"); + } + + public static void LogError(string message) + { + Console.WriteLine($"ERROR: {message}"); + } +} \ No newline at end of file From a7ac48ae87256b4d0a4cbc93eeb68e3723f61bc9 Mon Sep 17 00:00:00 2001 From: aHjelmgaard Date: Wed, 15 Apr 2026 18:13:51 +0200 Subject: [PATCH 2/2] fix return statement --- CoDepend/Domain/DependencyGraphSerializer.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CoDepend/Domain/DependencyGraphSerializer.cs b/CoDepend/Domain/DependencyGraphSerializer.cs index bc4e2b9..66e9799 100644 --- a/CoDepend/Domain/DependencyGraphSerializer.cs +++ b/CoDepend/Domain/DependencyGraphSerializer.cs @@ -112,17 +112,16 @@ public static byte[] Serialize(ProjectDependencyGraph graph, int version = 1) byte[] serializedResult = MessagePackSerializer.Serialize(dto, MsgPackOptions); - if (serializedResult.Length < 0) + if (serializedResult.Length > 0) { - Logger.LogInformation($"Size of serialized result: {serializedResult.Length.ToString()}"); + Logger.LogInformation($"Size of serialized result: {serializedResult.Length}"); } else { Logger.LogWarning($"The serialized result is empty"); } - - return MessagePackSerializer.Serialize(dto, MsgPackOptions); + return serializedResult; } public static ProjectDependencyGraph Deserialize(byte[] data, string projectRoot)