From 9141eddbd7bbb1c3127e531aa2ad672e296a8822 Mon Sep 17 00:00:00 2001 From: Robert Bunning Date: Mon, 27 Jun 2022 11:36:04 -0400 Subject: [PATCH] Added component types Components can now be marked as databases and queries, like containers --- src/C4Sharp/Models/Component.cs | 14 ++++++++++++++ src/C4Sharp/Models/ComponentType.cs | 18 ++++++++++++++++++ .../Plantuml/Extensions/PlantumlStructure.cs | 8 +++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/C4Sharp/Models/ComponentType.cs diff --git a/src/C4Sharp/Models/Component.cs b/src/C4Sharp/Models/Component.cs index 68ae652..c93072b 100644 --- a/src/C4Sharp/Models/Component.cs +++ b/src/C4Sharp/Models/Component.cs @@ -16,23 +16,37 @@ public record Component : Structure { public string? Technology { get; init; } + public ComponentType ComponentType { get; init; } + public Component(string alias, string label): base(alias, label) { + ComponentType = ComponentType.None; } public Component(StructureIdentity alias, string label): base(alias, label) { + ComponentType = ComponentType.None; } public Component(string alias, string label, string technology): this(alias, label) { Technology = technology; + } + + public Component(string alias, string label, ComponentType componentType, string technology): this(alias, label, technology) + { + ComponentType = componentType; } public Component(string alias, string label, string technology, string description): this(alias, label) { Technology = technology; Description = description; + } + + public Component(string alias, string label, ComponentType componentType, string technology, string description): this(alias, label, technology, description) + { + ComponentType = componentType; } } diff --git a/src/C4Sharp/Models/ComponentType.cs b/src/C4Sharp/Models/ComponentType.cs new file mode 100644 index 0000000..f2555e2 --- /dev/null +++ b/src/C4Sharp/Models/ComponentType.cs @@ -0,0 +1,18 @@ +using System.ComponentModel; + +namespace C4Sharp.Models; + +/// +/// Component types +/// +public enum ComponentType +{ + [Description("Database")] + Database, + + [Description("Queue")] + Queue, + + [Description("")] + None +} \ No newline at end of file diff --git a/src/C4Sharp/Models/Plantuml/Extensions/PlantumlStructure.cs b/src/C4Sharp/Models/Plantuml/Extensions/PlantumlStructure.cs index 2b1210a..de67cc7 100644 --- a/src/C4Sharp/Models/Plantuml/Extensions/PlantumlStructure.cs +++ b/src/C4Sharp/Models/Plantuml/Extensions/PlantumlStructure.cs @@ -83,7 +83,13 @@ private static string ToPumlString(this EnterpriseBoundary boundary) private static string ToPumlString(this Component component) { - var procedureName = $"Component{GetExternalSuffix(component)}"; + var externalSuffix = GetExternalSuffix(component); + var procedureName = component.ComponentType switch + { + ComponentType.Database => $"ComponentDb{externalSuffix}", + ComponentType.Queue => $"ComponentQueue{externalSuffix}", + _ => $"Component{externalSuffix}" + }; return $"{procedureName}({component.Alias}, \"{component.Label}\", \"{component.Technology}\", \"{component.Description}\""