Skip to content

Commit

Permalink
In this version:
Browse files Browse the repository at this point in the history
- Fixing NameSpaces (Please update your project to use the correct namespaces)
- Update plantuml.jar
- Update C4-plantuml files in Resource
- Add new SequenceDiagram (See the sample)
- Update ElementStyle.cs to accept UpdateElementStyle(...,?borderStyle, ?borderThickness)
- Removing support to .NET 5.0
  • Loading branch information
yanjustino committed Mar 1, 2024
1 parent 7229d5a commit d904df1
Show file tree
Hide file tree
Showing 38 changed files with 1,193 additions and 436 deletions.
2 changes: 1 addition & 1 deletion samples/Basic/C4Sharp.Sample/C4Sharp.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>true</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Basic/C4Sharp.Sample/Diagrams/ComponentDiagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ComponentDiagram: DiagramBuildRunner

protected override DiagramType DiagramType => DiagramType.Component;
protected override DiagramLayout FlowVisualization => DiagramLayout.LeftRight;
protected override bool LayoutAsSketch => true;
protected override bool LayoutAsSketch => false;

protected override IEnumerable<Structure> Structures => new Structure[]
{
Expand Down
8 changes: 4 additions & 4 deletions samples/Basic/C4Sharp.Sample/Diagrams/ContainerDiagram.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using C4Sharp.Diagrams;
using C4Sharp.Diagrams.Interfaces;
using C4Sharp.Diagrams.Plantuml.Constants;
using C4Sharp.Diagrams.Plantuml.Style;
using C4Sharp.Elements;
using C4Sharp.Elements.Boundaries;
using C4Sharp.Elements.Plantuml;
using C4Sharp.Elements.Plantuml.Constants;
using C4Sharp.Elements.Relationships;
using C4Sharp.Sample.Structures;

Expand All @@ -26,7 +26,7 @@ public class ContainerDiagram: DiagramBuildRunner
Spa,
MobileApp,
SqlDatabase,
RabbitMQ,
RabbitMq,
BackendApi
)
};
Expand All @@ -41,7 +41,7 @@ public class ContainerDiagram: DiagramBuildRunner
Spa > BackendApi | ("Uses", "async, JSON/HTTPS"),
MobileApp > BackendApi | ("Uses", "async, JSON/HTTPS"),
SqlDatabase < BackendApi | ("Uses", "async, JSON/HTTPS") | Position.Neighbor,
RabbitMQ < BackendApi | ("Uses", "async, JSON"),
RabbitMq < BackendApi | ("Uses", "async, JSON"),

People.Customer < Systems.MailSystem | "Sends e-mails to",
Systems.MailSystem < BackendApi | ("Sends e-mails using", "sync, SMTP"),
Expand Down
4 changes: 2 additions & 2 deletions samples/Basic/C4Sharp.Sample/Diagrams/ContextDiagram.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using C4Sharp.Diagrams;
using C4Sharp.Diagrams.Interfaces;
using C4Sharp.Diagrams.Plantuml.Constants;
using C4Sharp.Diagrams.Plantuml.Style;
using C4Sharp.Elements;
using C4Sharp.Elements.Plantuml;
using C4Sharp.Elements.Plantuml.Constants;
using C4Sharp.Elements.Relationships;
using C4Sharp.Sample.Structures;

Expand Down
4 changes: 2 additions & 2 deletions samples/Basic/C4Sharp.Sample/Diagrams/EnterpriseDiagram.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using C4Sharp.Diagrams;
using C4Sharp.Diagrams.Interfaces;
using C4Sharp.Diagrams.Plantuml.Constants;
using C4Sharp.Diagrams.Plantuml.Style;
using C4Sharp.Elements;
using C4Sharp.Elements.Boundaries;
using C4Sharp.Elements.Plantuml;
using C4Sharp.Elements.Plantuml.Constants;
using C4Sharp.Elements.Relationships;
using C4Sharp.Sample.Structures;

Expand Down
34 changes: 34 additions & 0 deletions samples/Basic/C4Sharp.Sample/Diagrams/SequenceDiagram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using C4Sharp.Diagrams;
using C4Sharp.Elements;
using C4Sharp.Elements.Boundaries;
using C4Sharp.Elements.Relationships;

namespace C4Sharp.Sample.Diagrams;

public class SequenceDiagram: DiagramBuildRunner
{
protected override string Title => "Sequence diagram for Internet Banking System";
protected override DiagramType DiagramType => DiagramType.Sequence;

protected override IEnumerable<Structure> Structures => new Structure[]
{
new Container("cA", "Single-Page Application", ContainerType.None, "JavaScript and Angular", "Provides all of the Internet banking functionality to customers via their web browser."),

new SequenceContainerBoundary("b", "Api Application")
{
Components = new Component[]
{
new ("cB", "Sign In Controller", ComponentType.None, "Spring MVC Rest Controller", "Allows users to sign in to the Internet Banking System."),
new ("cC", "Security Component", ComponentType.None, "Spring Bean", "Provides functionality Related to signing in, changing passwords, etc.")
}
},
new Container("cD", "Database", ContainerType.Database ,"Relational Database Schema", "Stores user registration information, hashed authentication credentials, access logs, etc.")
};

protected override IEnumerable<Relationship> Relationships => new[]
{
It("cA") > It("cB") | ("Submits credentials to", "JSON/HTTPS"),
It("cB") > It("cC") | "Calls isAuthenticated() on",
It("cC") > It("cD") | ("select * from users where username = ?o", "JDBCS")
};
}
7 changes: 4 additions & 3 deletions samples/Basic/C4Sharp.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using C4Sharp.Elements.Plantuml.IO;
using C4Sharp.Diagrams.Plantuml;
using C4Sharp.Sample.Diagrams;

namespace C4Sharp.Sample;
Expand All @@ -14,14 +14,15 @@ private static void Main()
new ComponentDiagram().Build(),
new DeploymentDiagram().Build(),
new EnterpriseDiagram().Build(),
new SequenceDiagram().Build()
};

var context = new PlantumlContext();

context
.UseDiagramImageBuilder()
.UseDiagramSvgImageBuilder()
.UseDiagramMermaidBuilder()
//.UseDiagramSvgImageBuilder()
//.UseDiagramMermaidBuilder()
//.UseStandardLibraryBaseUrl() //load the resources from github C4plantuml repository
.Export(diagrams);
}
Expand Down
4 changes: 2 additions & 2 deletions samples/Basic/C4Sharp.Sample/Structures/Containers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static class Containers
Technology: "SQL Database"
);

public static Queue _rabbitMQ;
private static Queue? _rabbitMq = null;

public static Queue RabbitMQ => _rabbitMQ ?? new Queue(
public static Queue RabbitMq => _rabbitMq ?? new Queue(
Alias: "Queue",
Label: "RabbitMQ",
Description: "Stores user registration information, hashed auth credentials, access logs, etc.",
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp.Tools/C4Sharp.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>c4scli</AssemblyName>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>C4SCLI - Tool for C4Sharp</Title>
<Authors>yanjustino, albertomonteiro</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp.Tools/Commands/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Reflection;
using C4Sharp.Diagrams;
using C4Sharp.Diagrams.Interfaces;
using C4Sharp.Elements.Plantuml.IO;
using C4Sharp.Diagrams.Plantuml;
using C4Sharp.Tools.Commands.Arguments;
using C4Sharp.Tools.Commands.Options;

Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/C4Sharp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>C4Sharp - simple .NET superset of C4-PlantUML</Title>
<Authors>yanjustino, leisiamedeiros</Authors>
Expand Down
6 changes: 4 additions & 2 deletions src/C4Sharp/Commons/FileSystem/C4FileException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace C4Sharp.FileSystem;
namespace C4Sharp.Commons.FileSystem;

/// <summary>
/// C4File Exception
Expand All @@ -27,6 +26,8 @@ public C4FileException(string message, Exception innerException) : base(message,
{
}


#if NET6
/// <summary>
/// Constructor
/// </summary>
Expand All @@ -35,4 +36,5 @@ public C4FileException(string message, Exception innerException) : base(message,
public C4FileException([NotNull] SerializationInfo info, StreamingContext context) : base(info, context)
{
}
#endif
}
2 changes: 1 addition & 1 deletion src/C4Sharp/Commons/FileSystem/C4SharpDirectory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace C4Sharp.FileSystem;
namespace C4Sharp.Commons.FileSystem;

/// <summary>
/// Manipulate the C4 folder and their resourcers
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Commons/ResourceFile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using C4Sharp.Elements.Plantuml.IO;
using C4Sharp.Diagrams.Plantuml;

namespace C4Sharp.Commons;

Expand Down
1 change: 1 addition & 0 deletions src/C4Sharp/Diagrams/DiagramConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public static class DiagramConstants
public const string Container = "C4_Container";
public const string Context = "C4_Context";
public const string Deployment = "C4_Deployment";
public const string Sequence = "C4_Sequence";
}
1 change: 1 addition & 0 deletions src/C4Sharp/Diagrams/DiagramType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public record DiagramType(string Value, string Name)
public static DiagramType Container => new (DiagramConstants.Container, nameof(DiagramConstants.Container));
public static DiagramType Context => new (DiagramConstants.Context, nameof(DiagramConstants.Context));
public static DiagramType Deployment => new (DiagramConstants.Deployment, nameof(DiagramConstants.Deployment));
public static DiagramType Sequence => new (DiagramConstants.Sequence, nameof(DiagramConstants.Sequence));
}
20 changes: 20 additions & 0 deletions src/C4Sharp/Diagrams/Plantuml/Constants/BorderStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace C4Sharp.Diagrams.Plantuml.Constants;

public class BorderStyle
{
/// <summary>
/// This call returns the name of the dashed line and can be used as ?lineStyle argument.
/// </summary>
public static BorderStyle SolidLine => new() { Value = "SolidLine()" };
/// <summary>
/// This call returns the name of the dotted line and can be used as ?lineStyle argument.
/// </summary>
public static BorderStyle DashedLine => new() { Value = "DashedLine()" };
/// <summary>
/// This call returns the name of the bold line and can be used as ?lineStyle argument.
/// </summary>
public static BorderStyle DottedLine => new() { Value = "DottedLine()" };
public static BorderStyle BoldLine => new() { Value = "BoldLine()" };

public string Value { get; private init; } = string.Empty;
}
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/Plantuml/Constants/ElementName.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace C4Sharp.Elements.Plantuml.Constants;
namespace C4Sharp.Diagrams.Plantuml.Constants;

public record ElementName
{
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/Plantuml/Constants/LineStyle.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace C4Sharp.Elements.Plantuml.Constants;
namespace C4Sharp.Diagrams.Plantuml.Constants;

public record LineStyle
{
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/Plantuml/Constants/Shape.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace C4Sharp.Elements.Plantuml.Constants;
namespace C4Sharp.Diagrams.Plantuml.Constants;

public record Shape
{
Expand Down
10 changes: 4 additions & 6 deletions src/C4Sharp/Diagrams/Plantuml/PlantumlContext.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System.Diagnostics;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using C4Sharp.Diagrams;
using C4Sharp.Diagrams.Plantuml;
using C4Sharp.FileSystem;
using C4Sharp.Commons.FileSystem;

namespace C4Sharp.Elements.Plantuml.IO;
namespace C4Sharp.Diagrams.Plantuml;

public partial class PlantumlContext : IDisposable
{
Expand Down Expand Up @@ -42,9 +39,10 @@ public PlantumlContext()
/// use this method
/// </summary>
/// <returns>PlantumlSession instance</returns>
[Obsolete("Now, we are suporting just embended version")]
public PlantumlContext UseStandardLibraryBaseUrl()
{
StandardLibraryBaseUrl = true;
StandardLibraryBaseUrl = false;
return this;
}

Expand Down
12 changes: 9 additions & 3 deletions src/C4Sharp/Diagrams/Plantuml/PlantumlDiagram.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text;
using C4Sharp.Commons.FileSystem;
using C4Sharp.Elements.Relationships;
using C4Sharp.FileSystem;

namespace C4Sharp.Diagrams.Plantuml;

Expand Down Expand Up @@ -49,7 +49,12 @@ private static StringBuilder BuildHeader(this StringBuilder stream, Diagram diag
}

stream.AppendLine("SHOW_PERSON_PORTRAIT()");
stream.AppendLine($"{(diagram.FlowVisualization == DiagramLayout.TopDown ? "LAYOUT_TOP_DOWN()" : "LAYOUT_LEFT_RIGHT()")}");
if (diagram.Type != DiagramType.Sequence)
{
stream.AppendLine(
$"{(diagram.FlowVisualization == DiagramLayout.TopDown ? "LAYOUT_TOP_DOWN()" : "LAYOUT_LEFT_RIGHT()")}");
}

stream.AppendLine();

if (!string.IsNullOrWhiteSpace(diagram.Title))
Expand Down Expand Up @@ -163,7 +168,8 @@ private static StringBuilder BuildMermaidHeader(this StringBuilder stream, Diagr
DiagramConstants.Context => "C4Context",
DiagramConstants.Container => "C4Container",
DiagramConstants.Component => "C4Component",
DiagramConstants.Deployment => "C4Deployment"
DiagramConstants.Deployment => "C4Deployment",
_ => throw new ArgumentOutOfRangeException()
};

stream.AppendLine(diagramType);
Expand Down
2 changes: 1 addition & 1 deletion src/C4Sharp/Diagrams/Plantuml/PlantumlException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace C4Sharp.Elements.Plantuml.IO;
namespace C4Sharp.Diagrams.Plantuml;

/// <summary>
/// PlantumlException
Expand Down
5 changes: 3 additions & 2 deletions src/C4Sharp/Diagrams/Plantuml/PlantumlResources.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using C4Sharp.Commons;
using C4Sharp.FileSystem;
using C4Sharp.Commons.FileSystem;

namespace C4Sharp.Elements.Plantuml.IO;
namespace C4Sharp.Diagrams.Plantuml;

internal static class PlantumlResources
{
Expand All @@ -19,6 +19,7 @@ public static void LoadResources(string path)
LoadResource(local, "C4_Container.puml");
LoadResource(local, "C4_Context.puml");
LoadResource(local, "C4_Deployment.puml");
LoadResource(local, "C4_Sequence.puml");
}

/// <summary>
Expand Down
17 changes: 17 additions & 0 deletions src/C4Sharp/Diagrams/Plantuml/PlantumlStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static string ToPumlString(this Structure structure)
Container container => container.ToPumlString(),
ContainerBoundary containerBoundary => containerBoundary.ToPumlString(),
EnterpriseBoundary enterpriseBoundary => enterpriseBoundary.ToPumlString(),
SequenceContainerBoundary sequenceContainerBoundary => sequenceContainerBoundary.ToPumlString(),
_ => string.Empty
};

Expand Down Expand Up @@ -136,6 +137,22 @@ private static string ToPumlString(this ContainerBoundary boundary)

return stream.ToString();
}

private static string ToPumlString(this SequenceContainerBoundary boundary)
{
var stream = new StringBuilder();

stream.AppendLine();
stream.AppendLine($"Container_Boundary({boundary.Alias}, \"{boundary.Label}\")");
foreach (var component in boundary.Components)
{
stream.AppendLine($"{TabIndentation.Indent()}{component.ToPumlString()}");
}

stream.AppendLine("Boundary_End()");

return stream.ToString();
}

private static string ToPumlString(this DeploymentNode deployment, int concat = 0)
{
Expand Down
Loading

0 comments on commit d904df1

Please sign in to comment.