← Gallery

Sequence

Client and server exchange

Explore the example, download the output or use the C# source in your own project.

Preview
Client and server exchangeProduct-neutral diagram semantics
Client and server exchange
Client and server exchangeProduct-neutral diagram semantics
Client and server exchange
600 × 375 pixels

Create this example

Create a console project, add the ChartForgeX package, and replace Program.cs with this source. Run it to write SVG, PNG and HTML with the default system fonts.

For the same typography as the gallery, download the gallery-font recipe and copy the gallery’s fonts directory beside your program.

#region Setup
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using ChartForgeX;
using ChartForgeX.Core;
using ChartForgeX.Primitives;
using ChartForgeX.Rendering;
using ChartForgeX.Themes;
using ChartForgeX.Topology;
using ChartForgeX.Typography;
using ChartForgeX.VisualArtifacts;
using ChartForgeX.VisualBlocks;

var mode = ThemeMode.Light;
var theme = VisualTheme.Graphite();
var model = SimpleSequenceRecipe.Create("feasibility", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(600, 375)), theme, mode,
    new VisualFrame("Client and server exchange", "Product-neutral diagram semantics", showLegend: false, showSurface: false));
var prepared = model.Prepare(context);
File.WriteAllText("visual.svg", prepared.ToSvg());
File.WriteAllBytes("visual.png", prepared.ToPng());
File.WriteAllText("visual.html", prepared.ToArtifact("example", VisualArtifactKind.Sequence).ToHtmlPage());
#endregion

/// <summary>Creates a two-participant exchange with a multiline request and dashed return.</summary>
public static class SimpleSequenceRecipe {
    /// <summary>Creates the simple client and server sequence model.</summary>
    /// <param name="variant">Use wide or feasibility for the simple sequence.</param>
    /// <param name="mode">The rendering mode; diagram colors are resolved when the model is prepared.</param>
    public static SequenceArtifact Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "feasibility"))
            throw new ArgumentOutOfRangeException(nameof(variant), variant, "Use wide or feasibility.");

        return SequenceArtifact.Create("session").Width(600).Height(375)
            .AddParticipant("client", "Client")
            .AddParticipant("server", "Server")
            .AddMessage("client", "server", "Request\npayload")
            .AddMessage("server", "client", "Response", SequenceArtifactMessageLineStyle.Dashed, SequenceArtifactMessageKind.Return);
    }
}
#region Setup
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using ChartForgeX;
using ChartForgeX.Core;
using ChartForgeX.Primitives;
using ChartForgeX.Rendering;
using ChartForgeX.Themes;
using ChartForgeX.Topology;
using ChartForgeX.Typography;
using ChartForgeX.VisualArtifacts;
using ChartForgeX.VisualBlocks;

var mode = ThemeMode.Dark;
var theme = VisualTheme.Graphite();
var model = SimpleSequenceRecipe.Create("feasibility", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(600, 375)), theme, mode,
    new VisualFrame("Client and server exchange", "Product-neutral diagram semantics", showLegend: false, showSurface: false));
var prepared = model.Prepare(context);
File.WriteAllText("visual.svg", prepared.ToSvg());
File.WriteAllBytes("visual.png", prepared.ToPng());
File.WriteAllText("visual.html", prepared.ToArtifact("example", VisualArtifactKind.Sequence).ToHtmlPage());
#endregion

/// <summary>Creates a two-participant exchange with a multiline request and dashed return.</summary>
public static class SimpleSequenceRecipe {
    /// <summary>Creates the simple client and server sequence model.</summary>
    /// <param name="variant">Use wide or feasibility for the simple sequence.</param>
    /// <param name="mode">The rendering mode; diagram colors are resolved when the model is prepared.</param>
    public static SequenceArtifact Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "feasibility"))
            throw new ArgumentOutOfRangeException(nameof(variant), variant, "Use wide or feasibility.");

        return SequenceArtifact.Create("session").Width(600).Height(375)
            .AddParticipant("client", "Client")
            .AddParticipant("server", "Server")
            .AddMessage("client", "server", "Request\npayload")
            .AddMessage("server", "client", "Response", SequenceArtifactMessageLineStyle.Dashed, SequenceArtifactMessageKind.Return);
    }
}