Skip to content

Commit

Permalink
Merge pull request #2 from jtreher/add-custom-tag-support
Browse files Browse the repository at this point in the history
Adds support for custom tags
  • Loading branch information
jtreher authored Oct 28, 2021
2 parents ee12d5e + d1be5a0 commit e7dd90b
Show file tree
Hide file tree
Showing 17 changed files with 360 additions and 120 deletions.
51 changes: 33 additions & 18 deletions src/C4Sharp.Sample.Orders/PackageByLayerDiagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class PackageByLayerDiagram
ShowLegend = false,
Structures = new Structure[]
{
WebLayer,
ServiceLayer,
WebLayer(),
ServiceLayer(),
DataLayer,
},
Relationships = new[]
Expand All @@ -25,26 +25,41 @@ public class PackageByLayerDiagram
}
};

private static ContainerBoundary WebLayer => new("WebLayer", "web")
private static ContainerBoundary WebLayer()
{
Components = new[]
var ordersController = OrdersController;
ordersController.AddTag(Tag.Deprecated);

return new("WebLayer", "web")
{
OrdersController
Components = new[]
{
ordersController
},
};
};
}

private static ContainerBoundary ServiceLayer => new("ServiceLayer", "service")
private static ContainerBoundary ServiceLayer()
{
Components = new[]
{
IOrdersService,
OrdersService
},
Relationships = new []
var iOrdersService = IOrdersService;
iOrdersService.AddTag(Tag.Planned);

var ordersService = OrdersService;
ordersService.AddTag(Tag.InProgress);

return new("ServiceLayer", "service")
{
(IOrdersService < OrdersService)["implements"],
}
};
Components = new[]
{
iOrdersService,
ordersService
},
Relationships = new[]
{
(IOrdersService < OrdersService)["implements"],
}
};
}

private static ContainerBoundary DataLayer => new("DataLayer", "data")
{
Expand All @@ -53,10 +68,10 @@ public class PackageByLayerDiagram
IOrdersRepository,
OrdersRepository
},
Relationships = new []
Relationships = new[]
{
(IOrdersRepository < OrdersRepository)["implements"],
}
}
};
}
}
16 changes: 8 additions & 8 deletions src/C4Sharp.Sample.Orders/Structures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ public static class Structures
description: "Orders controller",
technology: "Asp.net REST API"
);

public static Component IOrdersService => new(
alias: nameof(IOrdersService),
label: nameof(IOrdersService),
description: "Orders service interface",
technology: "C# Interface"
);
);

public static Component OrdersService => new(
alias: nameof(OrdersService),
label: nameof(OrdersService),
description: "Orders service concret",
technology: "C# class"
);
);

public static Component IOrdersRepository => new(
alias: nameof(IOrdersRepository),
label: nameof(IOrdersRepository),
description: "Orders repository interface",
technology: "C# interface"
);
);

public static Component OrdersRepository => new(
alias: nameof(OrdersRepository),
label: nameof(OrdersRepository),
description: "Orders repository",
technology: "C# class / Dapper Framework"
);
);
}
}
10 changes: 5 additions & 5 deletions src/C4Sharp.Sample/Diagrams/ComponentDiagramBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

namespace C4Sharp.Sample.Diagrams
{
using static Systems;
using static Components;
using static Containers;
using static Systems;
using static Components;
using static Containers;

public static class ComponentDiagramBuilder
{
public static ComponentDiagram Build()
Expand Down Expand Up @@ -38,7 +38,7 @@ public static ComponentDiagram Build()

private static ContainerBoundary Boundary()
{
return new ("c1", "API Application")
return new("c1", "API Application")
{
Components = new[]
{
Expand Down
6 changes: 4 additions & 2 deletions src/C4Sharp/C4Sharp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>9.0</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>C4Sharp - simple .NET superset of C4-PlantUML</Title>
<Authors>yanjustino, leisiamedeiros</Authors>
Expand All @@ -10,7 +11,7 @@
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/8T4/c4sharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>c4, diagrams</PackageTags>
<Package>c4, diagrams</Package>
<PackageVersion>2.2.1</PackageVersion>
<PackageIconUrl>https://github.com/8T4/c4sharp/blob/main/LICENSE</PackageIconUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand All @@ -20,6 +21,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 12 additions & 4 deletions src/C4Sharp/Models/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public sealed class Component : Structure
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="technology"></param>
public Component(string alias, string label, string description, string technology)
/// <param name="tags">Optional</param>
public Component(string alias, string label, string description, string technology, params Tag[] tags)
: base(alias, label, description, Boundary.Internal)
{
Technology = technology;
AddTag(tags);
}

/// <summary>
Expand All @@ -37,10 +39,12 @@ public Component(string alias, string label, string description, string technolo
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="link"></param>
public Component(string alias, string label, string description, string technology, string link)
/// <param name="tags">Optional</param>
public Component(string alias, string label, string description, string technology, string link, params Tag[] tags)
: base(alias, label, description, link)
{
Technology = technology;
AddTag(tags);
}

/// <summary>
Expand All @@ -51,10 +55,12 @@ public Component(string alias, string label, string description, string technolo
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="boundary"></param>
public Component(string alias, string label, string description, string technology, Boundary boundary)
/// <param name="tags">Optional</param>
public Component(string alias, string label, string description, string technology, Boundary boundary, params Tag[] tags)
: base(alias, label, description, boundary)
{
Technology = technology;
AddTag(tags);
}

/// <summary>
Expand All @@ -66,10 +72,12 @@ public Component(string alias, string label, string description, string technolo
/// <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)
/// <param name="tags">Optional</param>
public Component(string alias, string label, string description, string technology, string link, Boundary boundary, params Tag[] tags)
: base(alias, label, description, link, boundary)
{
Technology = technology;
AddTag(tags);
}
}
}
48 changes: 33 additions & 15 deletions src/C4Sharp/Models/Container.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using C4Sharp.Extensions;
using C4Sharp.Extensions;
using C4Sharp.Models.Relationships;
using System.Collections.Generic;

namespace C4Sharp.Models
{
Expand All @@ -17,25 +17,27 @@ namespace C4Sharp.Models
/// </summary>
public sealed class Container : Structure
{
private readonly Dictionary<int, Container> _instances =
private readonly Dictionary<int, Container> _instances =
new Dictionary<int, Container>();

public string Technology { get; }
public ContainerType ContainerType { get; }
public Container this[int index] => this.NewInstance(index);

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="type"></param>
/// <param name="description"></param>
/// <param name="technology"></param>
public Container(string alias, ContainerType type, string description, string technology)
/// <param name="tags">Optional</param>
public Container(string alias, ContainerType type, string description, string technology, params Tag[] tags)
: base(alias, type.GetDescription(), description, Boundary.Internal)
{
Technology = technology;
ContainerType = type;
AddTag(tags);
}

/// <summary>
Expand All @@ -46,11 +48,13 @@ public Container(string alias, ContainerType type, string description, string te
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="link"></param>
public Container(string alias, ContainerType type, string description, string technology, string link)
/// <param name="tags">Optional</param>
public Container(string alias, ContainerType type, string description, string technology, string link, params Tag[] tags)
: base(alias, type.GetDescription(), description, link)
{
Technology = technology;
ContainerType = type;
AddTag(tags);
}

/// <summary>
Expand All @@ -61,11 +65,13 @@ public Container(string alias, ContainerType type, string description, string te
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="boundary"></param>
public Container(string alias, ContainerType type, string description, string technology, Boundary boundary)
/// <param name="tags">Optional</param>
public Container(string alias, ContainerType type, string description, string technology, Boundary boundary, params Tag[] tags)
: base(alias, type.GetDescription(), description, boundary)
{
Technology = technology;
ContainerType = type;
AddTag(tags);
}

/// <summary>
Expand All @@ -77,25 +83,29 @@ public Container(string alias, ContainerType type, string description, string te
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="boundary"></param>
public Container(string alias, ContainerType type, string label, string description, string technology, Boundary boundary)
/// <param name="tags">Optional</param>
public Container(string alias, ContainerType type, string label, string description, string technology, Boundary boundary, params Tag[] tags)
: base(alias, label, description, boundary)
{
Technology = technology;
ContainerType = type;
}

AddTag(tags);
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="alias">Should be unique</param>
/// <param name="label"></param>
/// <param name="description"></param>
/// <param name="technology"></param>
public Container(string alias, string label, string description, string technology)
/// <param name="tags">Optional</param>
public Container(string alias, string label, string description, string technology, params Tag[] tags)
: base(alias, label, description, Boundary.Internal)
{
Technology = technology;
ContainerType = ContainerType.None;
AddTag(tags);
}

/// <summary>
Expand All @@ -106,11 +116,13 @@ public Container(string alias, string label, string description, string technolo
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="link"></param>
public Container(string alias, string label, string description, string technology, string link)
/// <param name="tags">Optional</param>
public Container(string alias, string label, string description, string technology, string link, params Tag[] tags)
: base(alias, label, description, link)
{
Technology = technology;
ContainerType = ContainerType.None;
AddTag(tags);
}

/// <summary>
Expand All @@ -121,11 +133,13 @@ public Container(string alias, string label, string description, string technolo
/// <param name="description"></param>
/// <param name="technology"></param>
/// <param name="boundary"></param>
public Container(string alias, string label, string description, string technology, Boundary boundary)
/// <param name="tags">Optional</param>
public Container(string alias, string label, string description, string technology, Boundary boundary, params Tag[] tags)
: base(alias, label, description, boundary)
{
Technology = technology;
ContainerType = ContainerType.None;
AddTag(tags);
}

/// <summary>
Expand All @@ -137,11 +151,13 @@ public Container(string alias, string label, string description, string technolo
/// <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)
/// <param name="tags">Optional</param>
public Container(string alias, string label, string description, string technology, string link, Boundary boundary, params Tag[] tags)
: base(alias, label, description, link, boundary)
{
Technology = technology;
ContainerType = ContainerType.None;
AddTag(tags);
}

/// <summary>
Expand All @@ -154,11 +170,13 @@ public Container(string alias, string label, string description, string technolo
/// <param name="technology"></param>
/// <param name="link"></param>
/// <param name="boundary"></param>
public Container(string alias, ContainerType type, string label, string description, string technology, string link, Boundary boundary)
/// <param name="tags">Optional</param>
public Container(string alias, ContainerType type, string label, string description, string technology, string link, Boundary boundary, params Tag[] tags)
: base(alias, label, description, link, boundary)
{
Technology = technology;
ContainerType = type;
AddTag(tags);
}

/// <summary>
Expand Down
Loading

0 comments on commit e7dd90b

Please sign in to comment.