-
Notifications
You must be signed in to change notification settings - Fork 0
Running the Transpiler
With the code in place to consume and deserialize the SysML model, the next step is to execute the transpilation process. This involves utilizing the TranspilerDispatcher
, which orchestrates deserializing the SysML model and invoking the transpilation through your ITranspilerSink
implementations.
Before we begin the transpilation, it's necessary to configure options for the XmiDeserializer
. This component can be initialized in two primary ways:
The FromFileOptions
is used when you have a local file containing the SysML model. This option allows you to specify the filepath for the XmiDeserializer
to construct the XmlDocument
.
Alternatively, the FromGitHubOptions
lets you specify a GitHub Release Tag to directly download the Model.xml
from GitHub. Setting GitHubRelease
to latest
will dynamically select the most recent release tagged as Latest.
TranspilerDispatcher
is the key to the transpilation process, managing the deserialization of the SysML model and triggering the ITranspilerSink.Transpile
method.
Below is an example that includes the use of "Consoul" for enhanced logging and user experience:
// Uses Microsoft.Extensions.Logging for the LoggerFactory and ILogger
// Retaining the use of the Consoul library for enhanced console output
var logger = LoggerFactory.Create(builder => builder.AddConsoulLogger()).CreateLogger<TranspilerDispatcher>();
var options = new FromGitHubOptions() { GitHubRelease = "latest" };
using (var cancellationSource = new CancellationTokenSource())
using (var dispatcher = new TranspilerDispatcher(options, logger))
{
dispatcher.AddSink(new Transpiler()); // Add your ITranspilerSink implementation here
var task = Task.Run(() => dispatcher.TranspileAsync(cancellationSource.Token)).ContinueWith((t) => cancellationSource.Cancel());
// Leveraging Consoul to enhance console output. The ContinueWith above ensures that the Consoul.Wait indication is dismissed once the task completes.
Consoul.Wait(cancellationToken: cancellationSource.Token);
if (task.IsCompletedSuccessfully) {
Consoul.Write("Success!", ConsoleColor.Green);
} else {
Consoul.Write("Aborted!", ConsoleColor.Red);
}
}
This code snippet demonstrates how to use the TranspilerDispatcher
alongside the "Consoul" library to visually enhance the console output during the transpilation process. By integrating "Consoul", developers can provide a more engaging and informative console experience, especially useful for long-running operations or to highlight the success or failure of the transpilation process.
Using the TranspilerDispatcher
is recommended for its convenience in sourcing the XmiDeserializer
and its capability to manage multiple sinks from the same source model. This approach simplifies the overall process, allowing you to focus on the custom logic within your ITranspilerSink
implementations.
By following the outlined steps and incorporating the "Consoul" library for improved console interactions, you'll be well-equipped to execute the transpilation process, transforming SysML models into the formats needed for your projects.