Flow Network Application Programming Interface (API)
- Last UpdatedApr 24, 2025
- 5 minute read
The Flow Network Application Programming Interface (API) allows you to load a single Flow Network or a set of interconnected Flow Networks (also known as Mega Flow Networks) into an object model.
Flow Network Model
The Flow Network model contains all the topological and device information contained in the RealTime database (RTDB) for a single Flow Network.
The Flow Network model is used by both the ILoadService and the IFlowNetworkPlugin.
Mega Flow Network Model
The Mega Flow Network model contains all the topological and device information contained in the RTDB for all Flow Network models that are interconnected to the requesting model.
The Mega Flow Network model is used by both the IFlowNetworkInterconnectionService and the IMegaFlowNetworkPlugin.
Flow Network Load Service
The Flow Network Load Service allows for an external application to load a single Flow Network model from the RTDB. The external application can then traverse through the Flow Network model to query for relevant topographical and device information.
Parameters
|
Name |
Type |
Optional |
Output |
Description |
|
ptnum |
Int32 |
False |
False |
The slot number of the FNet record. |
|
uniqueIdentifierRepository |
IUniqueIdentifierRepository |
True |
False |
The repository used to generate unique IDs for elements in the model. |
Return Value
|
Type |
Description |
|---|---|
|
IFlowNetworkModel |
An object containing a single Flow Network model. |
Example
The following example shows you how to load a Flow Network based on an FNet record slot.
using OASySDNA.LMS.FlowNetwork;
using OASySDNA.LMS.FlowNetwork.RecordServices.Load;
using System;
namespace FlowNetworkQueryExample
{
/// <summary>
/// <see cref="LoadFlowNetworkExample"/> demonstrates how to load a single Flow Network based on a FNet record slot.
///
/// <see cref="LoadService.Load(int)"/> will load a single model. Topography and station traversal can proceed anywhere
/// within said model. Interconnect devices may exist within the model, but traversal will not proceed past them into other models.
/// </summary>
internal sealed class LoadFlowNetworkExample
{
internal static void Run()
{
Console.WriteLine("Enter a fnet slot number to load an individual Flow Network: ");
var requestedSlot = Convert.ToInt32(Console.ReadLine());
var loadService = new LoadService();
IFlowNetworkModel singlePipeline = loadService.Load(requestedSlot);
Console.WriteLine($"Flow Network loaded with key {requestedSlot}. Its name is {singlePipeline.ModelName} and has {singlePipeline.Stations.Count} stations");
}
}
}
Mega Flow Network Load Service
The Mega Flow Network Load Service allows for an external application to load a set of interconnected Flow Network models from the RTDB. The external application can then traverse through all the Flow Network models to query for relevant topographical and device information.
Parameters
|
Name |
Type |
Optional |
Output |
Description |
|
requestingFlowNetworkRecordSlot |
Int32 |
False |
False |
The slot number of any FNet record that is part of the Mega Flow Network. |
Return Value
|
Type |
Description |
|---|---|
|
IEnumerable<IFlowNetworkEditModel> |
An object containing all the Flow Networks in the Mega Flow Network. |
Example
The following example shows you how to load a Mega Flow Network based on an FNet record slot. It will load the Flow Network as well as any Flow Networks interconnected to it.
using OASySDNA.LMS.FlowNetwork;
using OASySDNA.LMS.FlowNetwork.Interconnect;
using System;
namespace FlowNetworkQueryExample
{
/// <summary>
/// <see cref="LoadMegaNetworkExample"/> demonstrates how to load a Mega Flow Network based on a FNet record slot.
///
/// <see cref="FlowNetworkInterconnectionService.LoadMegaNetwork(int)"/> will load a Flow Network, and any Flow Networks
/// connected to it through interconnections. This allows for topography and station traversals to proceed across interconnections.
///
/// Any FNet slot provided in the same constellation of interconnected Flow Networks will result in the same object being loaded.
/// </summary>
internal sealed class LoadMegaNetworkExample
{
internal static void Run()
{
Console.WriteLine("Enter a fnet slot number to load a Mega Flow Network: ");
var requestedSlot = Convert.ToInt32(Console.ReadLine());
var interconnectionService = new FlowNetworkInterconnectionService();
IMegaFlowNetwork megaNetwork = interconnectionService.LoadMegaNetwork(requestedSlot);
Console.WriteLine($"Mega Flow Network loaded with key {megaNetwork.Key}. Contained models:");
foreach (var model in megaNetwork.Models)
{
Console.WriteLine($"({model.MainlineComponents.FlowNetworkSlot}) - {model.ModelName}");
}
}
}
}
Mega Flow Network Plugin API
The plugin API allows for an application to process a Flow Network upon a device update or an integrity update.
Note: Implementing the IMegaFlowNetworkPlugin interface is recommended to process single Flow Networks as well as interconnected Flow Networks in order to achieve full network context. IFlowNetworkPlugin is limited to a single Flow Network model. It is still available for backwards compatibility.
Parameters for the Handle Method
|
Name |
Type |
Optional |
Output |
Description |
|
megaFlowNetwork |
IMegaFlowNetwork |
False |
False |
The updated Mega Flow Network. |
|
triggeringDevice |
String |
True |
False |
Indicates which device triggered the re-evaluation. |
Parameters for the HandleIntegrityUpdate Method
|
Name |
Type |
Optional |
Output |
Description |
|
megaFlowNetwork |
IMegaFlowNetwork |
False |
False |
The updated Mega Flow Network. |
Example
The following example shows you how to implement the IMegaFlowNetworkPlugin, which will be invoked whenever a device in any of the models within the Mega Flow Network changes state.
using OASySDNA.Common.Logging;
using OASySDNA.LMS.FlowNetwork;
namespace OASySDNA.LMS.SDKTests.RealTime.FlowNetworkPluginExample
{
/// <summary>
/// An example of how to create a plugin that returns the entire Mega Flow Network whenever a device in any of the models
/// in said Mega Flow Network changes state.
///
/// The <see cref="Handle(IMegaFlowNetwork, string)"/> or <see cref="HandleIntegrityUpdate(IMegaFlowNetwork)"/> methods will
/// be invoked only on the Hot RealTime server that owns the Mega Flow Network. Standby and non-owning systems will not
/// receive a callback until they assert or take ownership.
///
/// The referenced Json file FlowNetworkPluginSettings.json must be included in the RealTime config/Settings folder prior
/// to starting the RealTime service. Since both plugins in this example exist in the same assembly, only one reference is
/// required.
///
/// Plugins can also be created using <see cref="IFlowNetworkPlugin"/>. Both will be invoked whenever a device changes state.
/// </summary>
public sealed class MegaFlowNetworkPluginExample : IMegaFlowNetworkPlugin
{
private IDNALog Log { get; } = DNALogAdapter.Instance;
public void Handle(IMegaFlowNetwork megaFlowNetwork, string triggeringDevice)
{
Log.Always($"{nameof(MegaFlowNetworkPluginExample)}
Handle method invoked for mega network {megaFlowNetwork.Key} due to
a change in state of device {triggeringDevice}.");
LogInformation(megaFlowNetwork);
}
public void HandleIntegrityUpdate(IMegaFlowNetwork megaFlowNetwork)
{
Log.Always($"{nameof(MegaFlowNetworkPluginExample)}
HandleIntegrityUpdate method invoked for mega network
{megaFlowNetwork.Key} due to an integrity update.");
LogInformation(megaFlowNetwork);
}
private void LogInformation(IMegaFlowNetwork megaFlowNetwork)
{
Log.Always($"Models in mega network:");
foreach (var model in megaFlowNetwork.Models)
{
Log.Always(model.ModelName);
}
}
}
}
Flow Network Plugin Setting Configuration Example
The Flow Network Application Programming Interface (API) loads plugins using the standard OASyS extension architecture.
To load your custom plugin assemblies, create a JSON file in the %DNADataRoot%\RealTime\config\settings directory with the following format:
{
"LMS": {
"Extensions": {
"FlowNetwork": {
"FlowNetworkPluginExample.dll": true
}
}
}
}
How to Access the Software Development Kit (SDK)
Additional examples can be found in the Flow Network Software Development Kit (SDK).
Example code is included within the developer environment that is created when you run the Initialize-DevEnvironment.ps1 script within C:\Program Files\AVEVA\DNA\Tools\scripts.
For example: \Initialize-DevEnvironment.ps1 -Path C:\dev -Name RealTime
Additional SDK example code can then be found here: C:\dev\RealTime\source\FlowNetwork.