Class BlockGraphBuilder
Builds a directed graph of interconnected blocks from a set of JSON-based model definitions. Each model is instantiated via an IBlockFactory and wired together according to the declared input references.
Inherited Members
Namespace: MOSAIC.Components.Factory
Assembly: MOSAIC.dll
Syntax
public static class BlockGraphBuilder
Methods
Build(IReadOnlyDictionary<string, JsonModel>, IBlockFactory)
Builds and wires a block graph from the provided model definitions.
Declaration
public static BlockGraphBuilder.BuiltGraph Build(IReadOnlyDictionary<string, JsonModel> models, IBlockFactory factory)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyDictionary<string, JsonModel> | models | A read-only dictionary of node keys to their corresponding JsonModel definitions. |
| IBlockFactory | factory | The IBlockFactory responsible for creating block instances from model definitions. |
Returns
| Type | Description |
|---|---|
| BlockGraphBuilder.BuiltGraph | A BlockGraphBuilder.BuiltGraph with every block that could be built and connected, and the list of what could not. |
Remarks
The build process consists of two phases:
-
Instantiation – Each JsonModel is passed to the
factoryto create a concrete block instance. If the instance derives from BaseBlock, its input configuration is stored for later JSON export. - Wiring – For every model that declares Inputs, the referenced publisher nodes are connected to the current subscriber node via the IPublisher/ISubscriber contract.
A block that fails to build, or an input that cannot be connected, is recorded in Failures and skipped rather than thrown, allowing valid blocks and wires to load. The failed block's name remains in downstream input lists so saving the graph preserves the unresolved reference.
Connect(object, object)
Connects a publisher block to a subscriber block by registering the subscriber with the publisher's notification list.
Declaration
private static void Connect(object publisher, object subscriber)
Parameters
| Type | Name | Description |
|---|---|---|
| object | publisher | The source object that must implement IPublisher. |
| object | subscriber | The target object that must implement ISubscriber. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when |