Skip to content

Commit

Permalink
#24: Removed dependency on Synergy.Contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinCelej committed Jul 13, 2023
1 parent 4be66da commit c095e2a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Text;
using Synergy.Architecture.Diagrams.Sequence;
using Synergy.Contracts;

namespace Synergy.Architecture.Diagrams.Documentation;

Expand Down Expand Up @@ -44,15 +43,15 @@ public TechnicalBlueprint Register(Type @interface, Type implementation)
return this;
}

public TechnicalBlueprint Add(params SequenceDiagram[] diagram)
public TechnicalBlueprint Add(params SequenceDiagram[] diagrams)
{
this.diagrams.AddRange(diagram.OrFail(nameof(diagram)));
this.diagrams.AddRange(diagrams ?? throw new ArgumentNullException(nameof(diagrams)));
return this;
}

public TechnicalBlueprint Add(IEnumerable<SequenceDiagram> diagram)
public TechnicalBlueprint Add(IEnumerable<SequenceDiagram> diagrams)
{
this.diagrams.AddRange(diagram.OrFail(nameof(diagram)));
this.diagrams.AddRange(diagrams ?? throw new ArgumentNullException(nameof(diagrams)));
return this;
}

Expand All @@ -79,7 +78,8 @@ public string Render()

public override string ToString()
=> this.Render();


// TODO: Marcin Celej [from: Marcin Celej on: 12-06-2023]: Hide this class as it should be internal component store
public class DiagramComponents
{
private readonly List<Component> _components = new();
Expand All @@ -93,7 +93,7 @@ private record Component(Type Interface, Type Implementation);

public Type Resolve(Type origin)
{
Fail.IfArgumentNull(origin, nameof(origin));
origin = origin ?? throw new ArgumentNullException(nameof(origin));
var resolved = this._components.FirstOrDefault(c => c.Interface == origin);

return resolved?.Implementation ?? origin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Synergy.Architecture.Annotations.Diagrams.Sequence;
using Synergy.Architecture.Diagrams.Api;
using Synergy.Architecture.Diagrams.Documentation;
using Synergy.Contracts;
using Synergy.Reflection;

namespace Synergy.Architecture.Diagrams.Sequence;
Expand Down Expand Up @@ -39,7 +38,7 @@ public SequenceDiagram Calling<T>(string methodName, params Type[] arguments)

public SequenceDiagram Calling<T>(Expression<Action<T>> call)
{
var calling = (call.Body as MethodCallExpression).FailIfNull(Violation.Of("This is not a method call"));
var calling = (call.Body as MethodCallExpression) ?? throw new Exception("This is not a method call");
return this.Calling(calling.Method);
}

Expand All @@ -53,13 +52,13 @@ public SequenceDiagram Calling(Type type, string methodName, params Type[] argum
else
method = type.GetMethod(methodName, flags);

method.FailIfNull(Violation.Of("No method {0}.{1}()", type.Name, methodName));
method = method ?? throw new Exception($"No method {type.Name}.{methodName}()");

return this.Calling(method!);
}

public SequenceDiagram Calling(MethodInfo method)
=> this with { Method = method.OrFail(nameof(method)) };
=> this with { Method = method ?? throw new ArgumentNullException(nameof(method)) };

public SequenceDiagram Footer(string footer)
=> this with { FooterText = footer };
Expand All @@ -74,7 +73,7 @@ public string Render()
{
var diagrams = new StringBuilder();
var method = Method;
var type = Components.Resolve(method.DeclaringType.OrFail(nameof(method.DeclaringType)));
var type = Components.Resolve(method.DeclaringType ?? throw new ArgumentNullException(nameof(method.DeclaringType)));
var finish = FinishOn.ToList();
var arguments = String.Join(", ",
method.GetParameters()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Synergy.Architecture.Diagrams.Api;
using Synergy.Architecture.Diagrams.Documentation;
using Synergy.Architecture.Diagrams.Extensions;
using Synergy.Contracts;
using Synergy.Reflection;

namespace Synergy.Architecture.Diagrams.Sequence;
Expand Down Expand Up @@ -209,7 +208,7 @@ private void InsertCall(SequenceDiagramCallAttribute nextStep, StringBuilder dia
return;
}

var method = methodInfo.OrFail($"{currentTypeName}.{nextStep.Method}")!;
var method = methodInfo ?? throw new Exception($"There is no {currentTypeName}.{nextStep.Method}()");
var arguments = SequenceDiagramUrl.GetArguments(method.GetParameters());
diagram.AppendLine($"{sourceTypeName}->{currentTypeName}: {nextStep.Method}({arguments})");

Expand Down Expand Up @@ -245,7 +244,7 @@ private void InsertSelfCall(SequenceDiagramSelfCallAttribute nextStep, StringBui
return;
}

var method = methodInfo.OrFail($"{currentTypeName}.{nextStep.Method}")!;
var method = methodInfo ?? throw new Exception($"There is no {currentTypeName}.{nextStep.Method}()");
var arguments = SequenceDiagramUrl.GetArguments(method.GetParameters());
diagram.AppendLine($"{sourceTypeName}->{currentTypeName}: {nextStep.Method}({arguments})");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
<AssemblyVersion>$(Version)</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE;INTERNALS</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE;INTERNALS</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Contracts\Synergy.Contracts\Synergy.Contracts.csproj" />
<ProjectReference Include="..\Synergy.Architecture.Annotations\Synergy.Architecture.Annotations.csproj" />
</ItemGroup>

Expand Down

0 comments on commit c095e2a

Please sign in to comment.