Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="DendroDocs.Shared" Version="0.3.2" />
<PackageVersion Include="DendroDocs.Shared" Version="0.4.2" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Nuke.Common" Version="9.0.4" />
<PackageVersion Include="Nuke.Components" Version="9.0.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="PlantUml.Builder" Version="0.1.63" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
hashAlgorithm="SHA256" allowUntrustedRoot="false" />
<certificate fingerprint="1F4B311D9ACC115C8DC8018B5A49E00FCE6DA8E2855F9F014CA6F34570BC482D"
hashAlgorithm="SHA256" allowUntrustedRoot="false" />
<owners>DendroDocs;microsoft;nuget;simoncropp;nukebuild;SharpDevelop;rsuter;serilog;jetbrains;mrunleaded;dotnetframework;danielpalme;aaubry;gittools;GitHub</owners>
<owners>DendroDocs;eNeRGy164;microsoft;nuget;simoncropp;nukebuild;SharpDevelop;rsuter;serilog;jetbrains;mrunleaded;dotnetframework;danielpalme;aaubry;gittools;GitHub</owners>
</repository>

<author name="microsoft">
Expand Down
1 change: 1 addition & 0 deletions src/DendroDocs.Client/DendroDocs.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<ItemGroup>
<PackageReference Include="DendroDocs.Shared" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="PlantUml.Builder" />
</ItemGroup>

<ItemGroup>
Expand Down
50 changes: 50 additions & 0 deletions src/DendroDocs.Client/Uml/Extensions/IHaveModifiersExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using DendroDocs.Extensions;
using PlantUml.Builder;

namespace DendroDocs.Uml.Extensions;

/// <summary>
/// Provides extension methods for objects implementing the <see cref="IHaveModifiers"/> interface, enabling conversion
/// of visibility modifiers to their PlantUML equivalents.
/// </summary>
/// <remarks>This class contains methods that simplify the process of mapping visibility modifiers from objects
/// implementing <see cref="IHaveModifiers"/> to corresponding UML visibility representations, such as public,
/// protected, private, and internal.</remarks>
public static class IHaveModifiersExtensions
{
/// <summary>
/// Converts the visibility modifiers of the specified object to a PlantUML visibility modifier.
/// </summary>
/// <param name="modifiers">An object implementing <see cref="IHaveModifiers"/> that provides access to visibility modifiers.</param>
/// <returns>A <see cref="VisibilityModifier"/> value representing the UML visibility equivalent of the object's modifiers.
/// Returns <see cref="VisibilityModifier.Public"/> for public visibility, <see
/// cref="VisibilityModifier.PackagePrivate"/> for internal visibility, <see cref="VisibilityModifier.Protected"/>
/// for protected visibility, <see cref="VisibilityModifier.Private"/> for private visibility, or <see
/// cref="VisibilityModifier.None"/> if no visibility modifier is applicable.</returns>
public static VisibilityModifier ToPlantUmlVisibility(this IHaveModifiers modifiers)
{
ArgumentNullException.ThrowIfNull(modifiers);

if (modifiers.IsPublic())
{
return VisibilityModifier.Public;
}

if (modifiers.IsInternal())
{
return VisibilityModifier.PackagePrivate;
}

if (modifiers.IsProtected())
{
return VisibilityModifier.Protected;
}

if (modifiers.IsPrivate())
{
return VisibilityModifier.Private;
}

return VisibilityModifier.None;
}
}
30 changes: 30 additions & 0 deletions src/DendroDocs.Client/Uml/Fragments/Alt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Diagnostics;

namespace DendroDocs.Uml.Fragments;

/// <summary>
/// Represents a group with 1 or more sections, like <c>alt</c>, <c>par</c>, <c>loop</c>, etc..
/// </summary>
[DebuggerDisplay("Alt")]
public class Alt : InteractionFragment
{
private readonly List<AltSection> sections = [];

/// <summary>
/// Gets all sections.
/// </summary>
public IReadOnlyList<AltSection> Sections => this.sections;

/// <summary>
/// Add a sections to this alt.
/// </summary>
/// <param name="section">The section to add.</param>
public void AddSection(AltSection section)
{
ArgumentNullException.ThrowIfNull(section);

section.Parent = this;

this.sections.Add(section);
}
}
20 changes: 20 additions & 0 deletions src/DendroDocs.Client/Uml/Fragments/AltSection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Diagnostics;

namespace DendroDocs.Uml.Fragments;

/// <summary>
/// Represents a section in a larger group.
/// </summary>
[DebuggerDisplay("AltSection {GroupType} {Label}")]
public class AltSection : InteractionFragment
{
/// <summary>
/// The type of group, like <c>alt</c>, <c>else</c>, etc..
/// </summary>
public string? GroupType { get; set; }

/// <summary>
/// The label of this section.
/// </summary>
public string? Label { get; set; }
}
35 changes: 35 additions & 0 deletions src/DendroDocs.Client/Uml/Fragments/Arrow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Diagnostics;

namespace DendroDocs.Uml.Fragments;

/// <summary>
/// Represents an arrow between 2 participants.
/// </summary>
[DebuggerDisplay("{Source} -> {Target} : {Name}")]
public class Arrow : InteractionFragment
{
/// <summary>
/// The left participant of the arrow.
/// </summary>
public string? Source { get; set; }

/// <summary>
/// The right participant of the arrow.
/// </summary>
public string? Target { get; set; }

/// <summary>
/// The optional color of the arrow.
/// </summary>
public string? Color { get; set; }

/// <summary>
/// Whether the arrow is dashed.
/// </summary>
public bool Dashed { get; set; }

/// <summary>
/// The message with the arrow.
/// </summary>
public string? Name { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
namespace DendroDocs.Uml.Fragments.Extensions;

/// <summary>
/// Provides extension methods for querying and navigating through collections of <see cref="InteractionFragment"/>
/// objects.
/// </summary>
/// <remarks>This static class includes methods for retrieving descendants, ancestors, and sibling fragments
/// within a hierarchy of <see cref="InteractionFragment"/> objects. These methods are designed to facilitate traversal
/// and filtering of interaction fragments in a structured manner.</remarks>
public static class InteractionFragmentExtensions
{
/// <summary>
/// Query all descendants from this level down.
/// </summary>
/// <typeparam name="TFragment">The type of fragment to filter on.</typeparam>
/// <returns>Returns a readonly list of child fragments.</returns>
public static IReadOnlyList<TFragment> Descendants<TFragment>(this IEnumerable<InteractionFragment> nodes)
where TFragment : InteractionFragment
{
ArgumentNullException.ThrowIfNull(nodes);

var result = new List<TFragment>();

foreach (var node in nodes)
{
switch (node)
{
case TFragment t:
result.Add(t);
break;

case Alt a:
result.AddRange(a.Sections.SelectMany(s => s.Fragments).Descendants<TFragment>());
break;

default:
break;
}
}

return result;
}

/// <summary>
/// Query all parent fragments from this fragment up.
/// </summary>
/// <returns>Returns a list of parent fragments.</returns>
public static IReadOnlyList<InteractionFragment> Ancestors(this InteractionFragment fragment)
{
ArgumentNullException.ThrowIfNull(fragment);

var result = new List<InteractionFragment>();

var parent = fragment.Parent;
while (parent is not null)
{
result.Add(parent);

parent = parent.Parent;
}

return result;
}

/// <summary>
/// Query all sibling before the current fragment.
/// </summary>
/// <returns>Returns a readonly list of siblings comming before this fragment.</returns>
public static IReadOnlyList<InteractionFragment> StatementsBeforeSelf(this InteractionFragment fragment)
{
ArgumentNullException.ThrowIfNull(fragment);

if (fragment.Parent != null)
{
return [.. fragment.Parent.Fragments.TakeWhile(s => s != fragment)];
}

return [];
}
}
46 changes: 46 additions & 0 deletions src/DendroDocs.Client/Uml/Fragments/InteractionFragment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace DendroDocs.Uml.Fragments;

/// <summary>
/// Represents interaction fragments in a sequence diagram.
/// </summary>
public abstract class InteractionFragment
{
private readonly List<InteractionFragment> interactionFragments = [];

/// <summary>
/// The parent of this fragment.
/// </summary>
public InteractionFragment? Parent { get; set; }

/// <summary>
/// The children of this fragment.
/// </summary>
public virtual IReadOnlyList<InteractionFragment> Fragments => this.interactionFragments;

/// <summary>
/// Add a fragment to this level.
/// </summary>
/// <param name="fragment">The fragment to add.</param>
public void AddFragment(InteractionFragment fragment)
{
ArgumentNullException.ThrowIfNull(fragment);

fragment.Parent = this;

this.interactionFragments.Add(fragment);
}

/// <summary>
/// Add a list of fragments to this level.
/// </summary>
/// <param name="fragments">The fragments to add.</param>
public void AddFragments(IEnumerable<InteractionFragment> fragments)
{
ArgumentNullException.ThrowIfNull(fragments);

foreach (var fragment in fragments)
{
this.AddFragment(fragment);
}
}
}
8 changes: 8 additions & 0 deletions src/DendroDocs.Client/Uml/Fragments/Interactions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace DendroDocs.Uml.Fragments;

/// <summary>
/// Represents a list of fragments on the same level.
/// </summary>
public class Interactions : InteractionFragment
{
}
12 changes: 9 additions & 3 deletions src/DendroDocs.Client/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"net8.0": {
"DendroDocs.Shared": {
"type": "Direct",
"requested": "[0.3.2, )",
"resolved": "0.3.2",
"contentHash": "8k305PV9XQwZle+1EXH1ckGc/QJRYq/6eQOz2W6EFM0arobYLbcub1aCKiW6nZ7LGXdwEsB/WOEJjZ+sd6j+9w==",
"requested": "[0.4.2, )",
"resolved": "0.4.2",
"contentHash": "YfYo/kboAwdy8Qo0Iu1FF7+pZ+Fd8BHIyM8XbHTczjYjcmVsSJl2VS1oCJTj5eymMHqWMX2eTzQWRMByxnVVaA==",
"dependencies": {
"Newtonsoft.Json": "13.0.3"
}
Expand All @@ -21,6 +21,12 @@
"Microsoft.SourceLink.Common": "8.0.0"
}
},
"PlantUml.Builder": {
"type": "Direct",
"requested": "[0.1.63, )",
"resolved": "0.1.63",
"contentHash": "oidQGXTbe3E9SQ3UWLtUglJNgGEg2hWyCc4vDU1xYtESG9hZoO93tRu2QIhH/KCGSBh50hMuOMRXBUHoIyiJbQ=="
},
"Microsoft.Build.Tasks.Git": {
"type": "Transitive",
"resolved": "8.0.0",
Expand Down
Loading
Loading