Check message sequence
This is an example of outputting the flow from a specific message.
public void GetSendMessages(ICommandContext c, ICommandParams p)
{
ISequenceDiagram sequenceDiagram = c.App.Workspace.CurrentEditor as ISequenceDiagram;
if (sequenceDiagram == null) return;
//Get the starting message
var message = sequenceDiagram.GetSelectedShapes().FirstOrDefault() as IMessageShape;
//End processing if the starting message is a reply message
if (message.GetMessageKind() == "reply") return;
//Output message information
OutputMessageInfo(message, c);
}
//Output message information starting from the target message
private void OutputMessageInfo(IMessageShape message, ICommandContext c)
{
OutputLog(message, c);
var receivePort = message.ReceivePort;
//If the message receiver is an execution specification, follow the next message.
if (receivePort is IExecutionSpecificationShape executionSpecification)
{
foreach (IMessageShape sendMessage in executionSpecification.SendMessages)
{
if (sendMessage.GetMessageKind() == "reply") continue;
OutputMessageInfo(sendMessage, c);
}
}
}
//Output message information
private void OutputLog(IMessageShape message, ICommandContext c)
{
//Output message information (including sender and receiver)
c.App.Output.WriteLine("sample", $"{message.GetSendPortText()} -> {message.GetReceivePortText()} : {message.Text}");
}
public static class IMessageShapeExtension
{
//Get the message type
public static string GetMessageKind(this IMessageShape self)
{
return ((IMessage) self.Model).Kind;
}
//Get the text of the sender port
public static string GetSendPortText(this IMessageShape self)
{
return GetMessagePortText(self.SendPort);
}
//Get the text of the receiver port
public static string GetReceivePortText(this IMessageShape self)
{
return GetMessagePortText(self.ReceivePort);
}
//Get the text of the message end
private static string GetMessagePortText(IMessagePortShape messagePort)
{
//Get the text to output depending on the type of message end
switch (messagePort)
{
case IFrameShape frame:
return frame.Text;
case IExecutionSpecificationShape executionSpecification:
return executionSpecification.Lifeline.Text;
case IMessageEndShape messageEnd:
return "Message end";
}
return string.Empty;
}
}