Skip to content

Commit

Permalink
1) Fixing
Browse files Browse the repository at this point in the history
  * Changing class scope visibility to sealed
  * Optimising embedded C4 resource

2) New Features
  * Adding SHOW_LEGEND() control
  * Adding LAYOUT_AS_SKETCH() control
  * Adding FLOW_VISUALIZATION: TOP_DOWN or LEFT_RIGHT

3) API changes
  * Removing obsolete SoftwareSystemType class and their dependencies
  • Loading branch information
yanjustino committed May 7, 2021
1 parent 30f3e1c commit 2c6a9b2
Show file tree
Hide file tree
Showing 22 changed files with 526 additions and 451 deletions.
3 changes: 3 additions & 0 deletions src/C4Sharp.Sample/Diagrams/ComponentDiagramBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using C4Sharp.Models;
using C4Sharp.Models.Diagrams;
using C4Sharp.Models.Diagrams.Core;
using C4Sharp.Sample.Structures;

Expand All @@ -15,6 +16,8 @@ public static ComponentDiagram Build()
return new()
{
Title = "Internet Banking System API Application",
FlowVisualization = DiagramLayout.LeftRight,
LayoutAsSketch = true,
Structures = new Structure[]
{
Spa,
Expand Down
1 change: 1 addition & 0 deletions src/C4Sharp.Sample/Diagrams/ContainerDiagramBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static ContainerDiagram Build()
{
return new()
{
ShowLegend = true,
Title = "Container diagram for Internet Banking System",
Structures = new Structure[]
{
Expand Down
11 changes: 4 additions & 7 deletions src/C4Sharp/C4Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RepositoryUrl>https://github.com/8T4/c4sharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>c4, diagrams</PackageTags>
<PackageVersion>1.1.5</PackageVersion>
<PackageVersion>2.0.0</PackageVersion>
<PackageIconUrl>https://github.com/8T4/c4sharp/blob/main/LICENSE</PackageIconUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -31,12 +31,9 @@

<!-- Embedded Resource For C4 Plunt UML and Plantuml -->
<ItemGroup>
<EmbeddedResource Include="bin\C4.puml" />
<EmbeddedResource Include="bin\C4_Component.puml" />
<EmbeddedResource Include="bin\C4_Container.puml" />
<EmbeddedResource Include="bin\C4_Context.puml" />
<EmbeddedResource Include="bin\C4_Deployment.puml" />
<EmbeddedResource Include="bin\C4_Dynamic.puml" />
<None Remove="bin\*.puml" />

<EmbeddedResource Include="bin\*.puml" />
<EmbeddedResource Include="bin\plantuml.jar" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/C4Sharp/Models/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace C4Sharp.Models
/// space. In the C4 model, components are not separately deployable units.
/// <see href="https://c4model.com/"/>
/// </summary>
public class Component : Structure
public sealed class Component : Structure
{
public string Technology { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Models/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace C4Sharp.Models
///
/// <see href="https://c4model.com/#ContainerDiagram"/>
/// </summary>
public class Container : Structure
public sealed class Container : Structure
{
private readonly Dictionary<int, Container> _instances =
new Dictionary<int, Container>();
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Models/ContainerBoundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace C4Sharp.Models
/// <summary>
/// Container Boundary
/// </summary>
public class ContainerBoundary: Structure
public sealed class ContainerBoundary: Structure
{
public IEnumerable<Component> Components { get; set; }
public IEnumerable<Relationship> Relationships { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Models/DeploymentNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace C4Sharp.Models
/// server, Microsoft IIS), etc. Deployment nodes can be nested.
/// <see href="https://c4model.com/#DeploymentDiagram"/>
/// </summary>
public class DeploymentNode : Structure
public sealed class DeploymentNode : Structure
{
public IEnumerable<DeploymentNode> Nodes { get; set; }
public Dictionary<string, string> Properties { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions src/C4Sharp/Models/Diagrams/Diagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public abstract class Diagram
{
internal string Name { get; }
public bool LayoutWithLegend { get; set; }
public bool ShowLegend { get; set; }
public bool LayoutAsSketch { get; set; }
public string Title { get; set; }
public DiagramLayout FlowVisualization { get; set; }
public Structure[] Structures { get; set; }
public Relationship[] Relationships { get; set; }

Expand All @@ -22,6 +25,9 @@ public abstract class Diagram
protected Diagram(string name)
{
LayoutWithLegend = true;
LayoutAsSketch = false;
ShowLegend = false;
FlowVisualization = DiagramLayout.TopDown;
Name = name;
}

Expand Down
8 changes: 8 additions & 0 deletions src/C4Sharp/Models/Diagrams/DiagramLayout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace C4Sharp.Models.Diagrams
{
public enum DiagramLayout
{
TopDown,
LeftRight
}
}
2 changes: 1 addition & 1 deletion src/C4Sharp/Models/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace C4Sharp.Models
/// A person represents one of the human users of your software system (e.g. actors, roles, personas, etc)
/// <see href="https://c4model.com/"/>
/// </summary>
public class Person : Structure
public sealed class Person : Structure
{
/// <summary>
/// Constructor
Expand Down
21 changes: 19 additions & 2 deletions src/C4Sharp/Models/Plantuml/PlantumlDiagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ public static string ToPumlString(this Diagram diagram)
stream.AppendLine($"@startuml {diagram.Slug()}");
stream.AppendLine($"!include {path}");
stream.AppendLine();
stream.AppendLine($"{(diagram.LayoutWithLegend ? "LAYOUT_WITH_LEGEND()" : "")}");

if (diagram.LayoutWithLegend && !diagram.ShowLegend)
{
stream.AppendLine("LAYOUT_WITH_LEGEND()");
}

if (diagram.LayoutAsSketch)
{
stream.AppendLine("LAYOUT_AS_SKETCH()");
}

stream.AppendLine($"{(diagram.FlowVisualization == DiagramLayout.TopDown ? "LAYOUT_TOP_DOWN()" : "LAYOUT_LEFT_RIGHT()")}");
stream.AppendLine();

foreach (var structure in diagram.Structures)
Expand All @@ -38,7 +49,13 @@ public static string ToPumlString(this Diagram diagram)
stream.AppendLine(relationship.ToPumlString());
}

stream.AppendLine($"@enduml");
if (diagram.ShowLegend)
{
stream.AppendLine();
stream.AppendLine("SHOW_LEGEND()");
}

stream.AppendLine("@enduml");
return stream.ToString();
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/C4Sharp/Models/Plantuml/PlantumlException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ public class PlantumlException: Exception
{
public PlantumlException(string message):base(message)
{

}

public PlantumlException(string message, Exception innerException):base(message, innerException)
{

}
}
}
3 changes: 1 addition & 2 deletions src/C4Sharp/Models/Plantuml/PlantumlStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ private static string ToPumlString(this Person person)

private static string ToPumlString(this SoftwareSystem system)
{
var isExternal = system.SoftwareSystemType == SoftwareSystemType.External ||
system.Boundary == Boundary.External;
var isExternal = system.Boundary == Boundary.External;

return isExternal
? $"System_Ext({system.Alias}, \"{system.Label}\", \"{system.Description}\")"
Expand Down
31 changes: 6 additions & 25 deletions src/C4Sharp/Models/SoftwareSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,29 @@ namespace C4Sharp.Models
/// a single software development team.
/// <see href="https://c4model.com/"/>
/// </summary>
public class SoftwareSystem : Structure
public sealed class SoftwareSystem : Structure
{
[Obsolete("Uses Boundary enumeration instead")]
public SoftwareSystemType SoftwareSystemType { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
public SoftwareSystem(string alias, string label)
: base(alias, label)
public SoftwareSystem(string alias, string label)
: base(alias, label, string.Empty, Boundary.Internal)
{
SoftwareSystemType = SoftwareSystemType.Internal;
}

}

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
public SoftwareSystem(string alias, string label, string description)
: base(alias, label, description)
: base(alias, label, description, Boundary.Internal)
{
SoftwareSystemType = SoftwareSystemType.Internal;
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="softwareSystemType"></param>
[Obsolete("Uses Boundary enumeration instead")]
public SoftwareSystem(string alias, string label, string description, SoftwareSystemType softwareSystemType)
: base(alias, label, description)
{
SoftwareSystemType = softwareSystemType;
}

/// <summary>
/// Constructor
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Models/SoftwareSystemBoundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace C4Sharp.Models
/// <summary>
/// Software System Boundary
/// </summary>
public class SoftwareSystemBoundary: Structure
public sealed class SoftwareSystemBoundary: Structure
{
public IEnumerable<Container> Containers { get; set; }

Expand Down
14 changes: 0 additions & 14 deletions src/C4Sharp/Models/SoftwareSystemType.cs

This file was deleted.

Loading

0 comments on commit 2c6a9b2

Please sign in to comment.