Skip to content

Commit

Permalink
Merge pull request #14 from BenRStutzman/feature/add-links-to-structures
Browse files Browse the repository at this point in the history
Enable adding links to structures
  • Loading branch information
yanjustino authored May 25, 2021
2 parents 5d25145 + 66d1b9f commit f44c971
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 32 deletions.
33 changes: 31 additions & 2 deletions src/C4Sharp/Models/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@ public Component(string alias, string label, string description, string technolo
{
Technology = technology;
}


/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Unique identification</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="link"></param>
public Component(string alias, string label, string description, string technology, string link)
: base(alias, label, description, link)
{
Technology = technology;
}

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -41,6 +55,21 @@ public Component(string alias, string label, string description, string technolo
: base(alias, label, description, boundary)
{
Technology = technology;
}
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Unique identification</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="link"></param>
/// <param name="boundary"></param>
public Component(string alias, string label, string description, string technology, string link, Boundary boundary)
: base(alias, label, description, link, boundary)
{
Technology = technology;
}
}
}
53 changes: 49 additions & 4 deletions src/C4Sharp/Models/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ public Container(string alias, ContainerType type, string description, string te
{
Technology = technology;
ContainerType = type;
}

}

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="type"></param>
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="link"></param>
public Container(string alias, ContainerType type, string description, string technology, string link)
: base(alias, type.GetDescription(), description, link)
{
Technology = technology;
ContainerType = type;
}

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -53,7 +68,6 @@ public Container(string alias, ContainerType type, string description, string te
ContainerType = type;
}


/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -83,7 +97,22 @@ public Container(string alias, string label, string description, string technolo
Technology = technology;
ContainerType = ContainerType.None;
}


/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="link"></param>
public Container(string alias, string label, string description, string technology, string link)
: base(alias, label, description, link)
{
Technology = technology;
ContainerType = ContainerType.None;
}

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -99,6 +128,22 @@ public Container(string alias, string label, string description, string technolo
ContainerType = ContainerType.None;
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="link"></param>
/// <param name="boundary"></param>
public Container(string alias, string label, string description, string technology, string link, Boundary boundary)
: base(alias, label, description, link, boundary)
{
Technology = technology;
ContainerType = ContainerType.None;
}

/// <summary>
/// Create a new instance of current container
/// </summary>
Expand Down
29 changes: 27 additions & 2 deletions src/C4Sharp/Models/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ public Person(string alias, string label, string description)
: base(alias, label, description)
{
}


/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="link"></param>
public Person(string alias, string label, string description, string link)
: base(alias, label, description, link)
{
}

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -29,6 +41,19 @@ public Person(string alias, string label, string description)
public Person(string alias, string label, string description, Boundary boundary)
: base(alias, label, description, boundary)
{
}
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="link"></param>
/// <param name="boundary"></param>
public Person(string alias, string label, string description, string link, Boundary boundary)
: base(alias, label, description, link, boundary)
{
}
}
}
36 changes: 17 additions & 19 deletions src/C4Sharp/Models/Plantuml/PlantumlStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ public static string ToPumlString(this Structure structure)

private static string ToPumlString(this Person person)
{
return person.Boundary == Boundary.External
? $"Person_Ext({person.Alias}, \"{person.Label}\", \"{person.Description}\" )"
: $"Person({person.Alias}, \"{person.Label}\", \"{person.Description}\" )";
var procedureName = $"Person{GetExternalSuffix(person)}";

return $"{procedureName}({person.Alias}, \"{person.Label}\", \"{person.Description}\", $link=\"{person.Link}\")";
}

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

return isExternal
? $"System_Ext({system.Alias}, \"{system.Label}\", \"{system.Description}\")"
: $"System({system.Alias}, \"{system.Label}\", \"{system.Description}\")";
var procedureName = $"System{GetExternalSuffix(system)}";

return $"{procedureName}({system.Alias}, \"{system.Label}\", \"{system.Description}\", $link=\"{system.Link}\")";
}

private static string ToPumlString(this SoftwareSystemBoundary boundary)
Expand All @@ -61,25 +59,23 @@ private static string ToPumlString(this SoftwareSystemBoundary boundary)

private static string ToPumlString(this Component component)
{
return component.Boundary == Boundary.External
? $"Component_Ext({component.Alias}, \"{component.Label}\", \"{component.Technology}\", \"{component.Description}\" )"
: $"Component({component.Alias}, \"{component.Label}\", \"{component.Technology}\", \"{component.Description}\" )";
var procedureName = $"Component{GetExternalSuffix(component)}";

return $"{procedureName}({component.Alias}, \"{component.Label}\", \"{component.Technology}\", \"{component.Description}\", $link=\"{component.Link}\")";
}

private static string ToPumlString(this Container container)
{
var external = container.Boundary == Boundary.External
? "_Ext"
: string.Empty;
var externalSuffix = GetExternalSuffix(container);

var value = container.ContainerType switch
var procedureName = container.ContainerType switch
{
ContainerType.Database => $"ContainerDb{external}",
ContainerType.Queue => $"ContainerQueue{external}",
_ => $"Container{external}"
ContainerType.Database => $"ContainerDb{externalSuffix}",
ContainerType.Queue => $"ContainerQueue{externalSuffix}",
_ => $"Container{externalSuffix}"
};

return $"{value}({container.Alias}, \"{container.Label}\", \"{container.Technology}\", \"{container.Description}\" )";
return $"{procedureName}({container.Alias}, \"{container.Label}\", \"{container.Technology}\", \"{container.Description}\", $link=\"{container.Link}\")";
}

private static string ToPumlString(this ContainerBoundary boundary)
Expand Down Expand Up @@ -144,5 +140,7 @@ private static string ToPumlString(this DeploymentNode deployment, int concat =

return stream.ToString();
}

private static string GetExternalSuffix(Structure structure) => structure.Boundary == Boundary.External ? "_Ext" : string.Empty;
}
}
35 changes: 30 additions & 5 deletions src/C4Sharp/Models/SoftwareSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,46 @@ public SoftwareSystem(string alias, string label)
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
public SoftwareSystem(string alias, string label, string description)
public SoftwareSystem(string alias, string label, string description)
: base(alias, label, description, Boundary.Internal)
{
}

}

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

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

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="link"></param>
/// <param name="boundary"></param>
public SoftwareSystem(string alias, string label, string description, string link, Boundary boundary)
: base(alias, label, description, link, boundary)
{
}
}
}
22 changes: 22 additions & 0 deletions src/C4Sharp/Models/Structure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class Structure
public string Label { get; }
public string Description { get; }
public string[] Tags { get; private set; }
public string Link { get; }
public Boundary Boundary { get; }

/// <summary>
Expand All @@ -34,6 +35,16 @@ protected Structure(string alias, string label) =>
protected Structure(string alias, string label, string description) =>
(Alias, Label, Description, Boundary) = (alias, label, description, Boundary.Internal);

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="link"></param>
protected Structure(string alias, string label, string description, string link) =>
(Alias, Label, Description, Link, Boundary) = (alias, label, description, link, Boundary.Internal);

/// <summary>
/// Constructor
/// </summary>
Expand All @@ -44,6 +55,17 @@ protected Structure(string alias, string label, string description) =>
protected Structure(string alias, string label, string description, Boundary boundary) =>
(Alias, Label, Description, Boundary) = (alias, label, description, boundary);

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="link"></param>
/// <param name="boundary"></param>
protected Structure(string alias, string label, string description, string link, Boundary boundary) =>
(Alias, Label, Description, Link, Boundary) = (alias, label, description, link, boundary);

/// <summary>
/// Add Tags
/// </summary>
Expand Down

0 comments on commit f44c971

Please sign in to comment.