Skip to content

Commit

Permalink
feat: added logging (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
SlavaVedernikov authored Aug 14, 2024
2 parents 646d847 + 1f34ea5 commit e547d6d
Show file tree
Hide file tree
Showing 35 changed files with 572 additions and 204 deletions.
16 changes: 11 additions & 5 deletions C4InterFlow.Automation/Readers/JObjectStructuresResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Collections.Concurrent;
using System.Reflection;
using System.Security.Cryptography;
using C4InterFlow.Commons;
using Serilog;

namespace C4InterFlow.Automation.Readers
{
Expand Down Expand Up @@ -193,7 +195,7 @@ public IEnumerable<string> ResolveStructures(IEnumerable<string> structures)
{
if (item.Contains(".*"))
{
Console.WriteLine($"Resolving wildcard Structures for '{item}'.");
Log.Information("Resolving wildcard Structure for {Structure}", item);
}

result.AddRange(RootJObject.SelectTokens(item).Select(x => x.Path));
Expand Down Expand Up @@ -280,9 +282,9 @@ public void CompletePartialUseFlowExpressions()
}
}

public void Validate(out IEnumerable<string> errors)
public void Validate(out IEnumerable<LogMessage> errors)
{
var errorsInternal = new List<string>();
var errorsInternal = new List<LogMessage>();

var interfaces = RootJObject.SelectTokens("..Interfaces.*");

Expand All @@ -297,7 +299,9 @@ public void Validate(out IEnumerable<string> errors)

if (usesInterface == null)
{
errorsInternal.Add($"Cannot resolve Interface '{usesInterfaceAlias}' referenced in Use Flow(s) of '{@interface.Path}' Interface.");
var error = new LogMessage(
"Cannot resolve Interface {InterfaceAlias} referenced in Use Flow(s) of {Interface} Interface.", usesInterfaceAlias, @interface.Path);
errorsInternal.Add(error);
}
}
}
Expand All @@ -317,7 +321,9 @@ public void Validate(out IEnumerable<string> errors)

if (usesInterface == null)
{
errorsInternal.Add($"Cannot resolve Interface '{usesInterfaceAlias}' referenced in Use Flow(s) of '{activity.Path} - {activity["Label"]}' Activity.");
var error = new LogMessage(
"Cannot resolve Interface {InterfaceAlias} referenced in Use Flow(s) of {Activity} Activity.", usesInterfaceAlias, $"{activity.Path} - {activity["Label"]}");
errorsInternal.Add(error);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions C4InterFlow.Automation/Readers/JsonAaCReaderStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Serilog;

namespace C4InterFlow.Automation.Readers
{
Expand Down Expand Up @@ -32,12 +33,12 @@ private bool ValidateFiles(string[] paths)
}
catch (JsonReaderException ex)
{
Console.WriteLine($"File '{jsonFile}' has error at line {ex.LineNumber}, column {ex.LinePosition}: {ex.Message}");
Log.Error(ex, "File {File} has error at line {LineNumber}, column {LinePosition}: {Error}", jsonFile, ex.LineNumber, ex.LinePosition, ex.Message);
result = false;
}
catch (Exception ex)
{
Console.WriteLine($"File '{jsonFile}' has error: {ex.Message}");
Log.Error(ex, "File {File} has error: {Error}", jsonFile, ex.Message);
result = false;
}
}
Expand Down
11 changes: 7 additions & 4 deletions C4InterFlow.Automation/Readers/NetStructuresResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Runtime.Loader;
using System.Text;
using System.Threading.Tasks;
using C4InterFlow.Commons;
using Serilog;
using static C4InterFlow.Automation.Writers.CsvToAnyAaCWriter;

namespace C4InterFlow.Automation.Readers
Expand Down Expand Up @@ -110,7 +112,8 @@ public IEnumerable<string> ResolveStructures(IEnumerable<string> aliases)
}
else
{
Console.WriteLine($"Resolving wildcard Structures for '{item}'.");
Log.Information("Resolving wildcard Structures for {Path}", item);

var types = new List<string>();
var supersededTypes = new List<string>();
foreach (var segmentItem in segments)
Expand Down Expand Up @@ -258,7 +261,7 @@ private IEnumerable<Assembly> LoadArchitectureAssemblies()
}
catch(Exception ex)
{
Console.WriteLine($"Failed to load an assembly from path '{path}': {ex.Message}");
Log.Error(ex, "Failed to load an assembly from path {AssemblyPath}: {Error}", path, ex.Message);
}
}
return result;
Expand Down Expand Up @@ -314,10 +317,10 @@ public IEnumerable<T> GetNestedInstances<T>(string? alias) where T : Structure
return result;
}

public void Validate(out IEnumerable<string> errors)
public void Validate(out IEnumerable<LogMessage> errors)
{
//TODO: Implement Use Flow Expressions validation
errors = new List<string>();
errors = new List<LogMessage>();
}
}
}
5 changes: 3 additions & 2 deletions C4InterFlow.Automation/Readers/YamlAaCReaderStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization;
using System.Text;
using Serilog;
using YamlDotNet.RepresentationModel;
using YamlDotNet.Core;

Expand Down Expand Up @@ -52,12 +53,12 @@ private bool ValidateFiles(string[] paths)
}
catch (YamlException ex)
{
Console.WriteLine($"File '{yamlFile}' has error at line {ex.Start.Line}, column {ex.Start.Column}: {ex.Message}");
Log.Error(ex, "File {YamlFile} has error at line {LineNumber}, column {ColumnNumber}: {Error}",yamlFile, ex.Start.Line, ex.Start.Column, ex.Message );
result = false;
}
catch (Exception ex)
{
Console.WriteLine($"File '{yamlFile}' has error: {ex.Message}");
Log.Error("File {YamlFile} has error: {Error}", yamlFile, ex.Message);
result = false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion C4InterFlow.Automation/Writers/CSharpToAnyAaCWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.MSBuild;
using C4InterFlow.Structures;
using Serilog;

namespace C4InterFlow.Automation.Writers
{
Expand All @@ -27,7 +28,7 @@ private static void RegisterInstanceVisualStudioInstance()

public CSharpToAnyAaCWriter(string softwareSystemSourcePath, string architectureRootNamespace)
{
Console.WriteLine($"Loading Software System source from '{softwareSystemSourcePath}'...");
Log.Information("Loading Software System source from {Path}", softwareSystemSourcePath);
RegisterInstanceVisualStudioInstance();
var softwareSystemWorkspace = MSBuildWorkspace.Create(new Dictionary<string, string>()
{
Expand Down
18 changes: 10 additions & 8 deletions C4InterFlow.Automation/Writers/CSharpToCSharpAaCWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using C4InterFlow.Structures;
using System.Text;
using System.Text.RegularExpressions;
using Serilog;

namespace C4InterFlow.Automation.Writers
{
Expand Down Expand Up @@ -33,7 +34,7 @@ public override CSharpToCSharpAaCWriter AddSoftwareSystem(string name, string? b

if (project == null)
{
Console.WriteLine($"Project '{ArchitectureNamespace}' was not found in '{ArchitectureWorkspace.CurrentSolution.FilePath}' Solution.");
Log.Warning("Project {Name} was not found in {Solution} solution", ArchitectureNamespace, ArchitectureWorkspace.CurrentSolution.FilePath);
return this;
}

Expand All @@ -47,7 +48,7 @@ public override CSharpToCSharpAaCWriter AddSoftwareSystem(string name, string? b

if (project.Documents.Any(x => x.FilePath == filePath))
{
Console.WriteLine($"Document '{filePath}' already exists in '{project.Name}' Project.");
Log.Warning("Document {Name} already exists in {Project} project", filePath, project.Name);
return this;
}

Expand Down Expand Up @@ -76,7 +77,7 @@ public override CSharpToCSharpAaCWriter AddContainer(string softwareSystemName,

if (project == null)
{
Console.WriteLine($"Project '{ArchitectureNamespace}' was not found in '{ArchitectureWorkspace.CurrentSolution.FilePath}' Solution.");
Log.Warning("Project {Name} was not found in {Solution} solution", ArchitectureNamespace, ArchitectureWorkspace.CurrentSolution.FilePath);
return this;
}

Expand All @@ -90,7 +91,7 @@ public override CSharpToCSharpAaCWriter AddContainer(string softwareSystemName,

if (project.Documents.Any(x => x.FilePath == filePath))
{
Console.WriteLine($"Document '{filePath}' already exists in '{project.Name}' Project.");
Log.Warning("Document {Name} already exists in {Project} project", filePath, project.Name);
return this;
}

Expand Down Expand Up @@ -121,7 +122,8 @@ public override CSharpToCSharpAaCWriter AddComponent(string softwareSystemName,

if (project == null)
{
Console.WriteLine($"Project '{ArchitectureNamespace}' was not found in '{ArchitectureWorkspace.CurrentSolution.FilePath}' Solution.");

Log.Warning("Project {Name} was not found in {Solution} solution", ArchitectureNamespace, ArchitectureWorkspace.CurrentSolution.FilePath);
return this;
}

Expand All @@ -135,7 +137,7 @@ public override CSharpToCSharpAaCWriter AddComponent(string softwareSystemName,

if (project.Documents.Any(x => x.FilePath == filePath))
{
Console.WriteLine($"Document '{filePath}' already exists in '{project.Name}' Project.");
Log.Warning("Document {Name} already exists in {Project} project", filePath, project.Name);
return this;
}

Expand Down Expand Up @@ -176,7 +178,7 @@ public override CSharpToCSharpAaCWriter AddComponentInterface(

if (architectureProject == null)
{
Console.WriteLine($"Project '{ArchitectureNamespace}' was not found in '{ArchitectureWorkspace.CurrentSolution.FilePath}' Solution.");
Log.Warning("Project {Name} was not found in {Solution} solution", ArchitectureNamespace, ArchitectureWorkspace.CurrentSolution.FilePath);
return this;
}

Expand All @@ -190,7 +192,7 @@ public override CSharpToCSharpAaCWriter AddComponentInterface(

if (architectureProject.Documents.Any(x => x.FilePath == filePath))
{
Console.WriteLine($"Document '{filePath}' already exists in '{architectureProject.Name}' Project.");
Log.Warning("Document {Name} already exists in {Project} project", filePath, architectureProject.Name);
return this;
}

Expand Down
Loading

0 comments on commit e547d6d

Please sign in to comment.