Table of Contents

Class FlowModule

Namespace
Crosser.EdgeNode.Flows
Assembly
Crosser.EdgeNode.Flows.dll

Base class for all modules, but you will probably use FlowModule<TSettings> for your implementation

public abstract class FlowModule : IFlowModule, IDisposable
Inheritance
FlowModule
Implements
Derived
FlowModule<TSettings>
Inherited Members

Constructors

FlowModule(FlowModuleType)

Constructor for FlowModule

protected FlowModule(FlowModuleType moduleType)

Parameters

moduleType FlowModuleType

Fields

InteractivityJsonOptions

public static readonly JsonSerializerOptions InteractivityJsonOptions

Field Value

JsonSerializerOptions

Properties

AssemblyVersion

public string AssemblyVersion { get; set; }

Property Value

string

Categories

Sets the tags to be able to group modules together representing similar functionality

[JsonIgnore]
public List<string> Categories { get; set; }

Property Value

List<string>

Debug

If true the module will log messages in/out from the module.

public bool Debug { get; set; }

Property Value

bool

Description

[JsonIgnore]
public string Description { get; }

Property Value

string

Disabled

If true the module will ignore messages coming in

public bool Disabled { get; set; }

Property Value

bool

FlowContext

Reference to the flow specific context that the module belongs to

[JsonIgnore]
public RepositoryInstance<string, dynamic> FlowContext { get; }

Property Value

RepositoryInstance<string, dynamic>

FlowId

Id of the flow that the module belongs to

public Guid FlowId { get; set; }

Property Value

Guid

FlowName

public string FlowName { get; }

Property Value

string

FlowStatistics

[Obsolete("This property will be removed in the next major version")]
[JsonIgnore]
public FlowStatistics FlowStatistics { get; set; }

Property Value

FlowStatistics

HaltOnError

If true the module and flow will be stopped when OnError is called

public bool HaltOnError { get; set; }

Property Value

bool

HasInput

If true you can pass data to this module

public bool HasInput { get; set; }

Property Value

bool

HasInteractiveSupport

public virtual bool HasInteractiveSupport { get; }

Property Value

bool

HasOutput

if Outputs Count is > 0 this will be true

public bool HasOutput { get; }

Property Value

bool

Id

Unique Id for the module instance

public Guid Id { get; set; }

Property Value

Guid

Index

[JsonIgnore]
public int Index { get; set; }

Property Value

int

InteractiveMethods

Get all currently available interactive methods from the module. Can be overridden in derived classes i.e. lets derived class have another way of storing methods.

public virtual IEnumerable<KeyValuePair<(string Uri, string Method), Func<JsonElement, ILog?, Task<(object?, FlowError?)>>>> InteractiveMethods { get; }

Property Value

IEnumerable<KeyValuePair<(string Uri, string Method), Func<JsonElement, ILog, Task<(object, FlowError)>>>>

InteractivityTopics

Get all registered methods from the module

public IEnumerable<(string Uri, string Method)> InteractivityTopics { get; }

Property Value

IEnumerable<(string Uri, string Method)>

Logger

public ILog? Logger { get; }

Property Value

ILog

MaxNrOfOutputs

The maximum number of outputs for the module, defaults to 1 so set this in your custom module if needed

[Obsolete("This property will be removed in the next major version")]
public int MaxNrOfOutputs { get; set; }

Property Value

int

ModuleProtocol

If the module uses a specific protocol for communication is should be registered here to make routers able to locate the module

[Obsolete("Modules that communicate via a specific protocol will solve the communication on their own")]
[JsonIgnore]
public FlowModuleProtocol ModuleProtocol { get; set; }

Property Value

FlowModuleProtocol

ModuleStatistics

[Obsolete("This property will be removed in the next major version")]
[JsonIgnore]
public FlowModuleStatistics ModuleStatistics { get; set; }

Property Value

FlowModuleStatistics

ModuleType

The module type implemented. See FlowModuleType

[JsonIgnore]
public FlowModuleType ModuleType { get; set; }

Property Value

FlowModuleType

ModuleVersion

public string ModuleVersion { get; set; }

Property Value

string

Name

Name of the module at runtime (set by users using the module in the flow)

public string Name { get; set; }

Property Value

string

NoError

protected static Task<IError?> NoError { get; }

Property Value

Task<IError>

NrOfOutputs

The available number of outputs from the module

public int NrOfOutputs { get; }

Property Value

int

Remarks

Each output can have several modules connected to it

OnDebug

[JsonIgnore]
public EventHandler<ModuleDebugMessage>? OnDebug { get; set; }

Property Value

EventHandler<ModuleDebugMessage>

OnError

[Obsolete("Use SetStatus instead")]
[JsonIgnore]
public EventHandler<FlowModuleException>? OnError { get; set; }

Property Value

EventHandler<FlowModuleException>

OnFlowDataReceived

[JsonIgnore]
[Obsolete("This will be removed in the next major version")]
public EventHandler<FlowStatisticsData>? OnFlowDataReceived { get; set; }

Property Value

EventHandler<FlowStatisticsData>

OnFlowDataSent

[JsonIgnore]
[Obsolete("This will be removed in the next major version")]
public EventHandler<FlowStatisticsData>? OnFlowDataSent { get; set; }

Property Value

EventHandler<FlowStatisticsData>

OnMessageDeadLetter

[JsonIgnore]
public EventHandler<MessageEvent>? OnMessageDeadLetter { get; set; }

Property Value

EventHandler<MessageEvent>

OnMessageDropped

[JsonIgnore]
public EventHandler<MessageEvent>? OnMessageDropped { get; set; }

Property Value

EventHandler<MessageEvent>

OnModuleDataReceived

[JsonIgnore]
[Obsolete("This will be removed in the next major version")]
public EventHandler<FlowModuleStatisticsData>? OnModuleDataReceived { get; set; }

Property Value

EventHandler<FlowModuleStatisticsData>

OnModuleDataSent

[JsonIgnore]
[Obsolete("This will be removed in the next major version")]
public EventHandler<FlowModuleStatisticsData>? OnModuleDataSent { get; set; }

Property Value

EventHandler<FlowModuleStatisticsData>

OnStatusChanged

[JsonIgnore]
public EventHandler<ModuleStatusEvent>? OnStatusChanged { get; set; }

Property Value

EventHandler<ModuleStatusEvent>

OnWarning

[Obsolete("Use SetStatus instead")]
[JsonIgnore]
public EventHandler<FlowModuleException>? OnWarning { get; set; }

Property Value

EventHandler<FlowModuleException>

Outputs

The actual outputs from the module

public List<RepositoryInstance<Guid, IFlowModule?>> Outputs { get; set; }

Property Value

List<RepositoryInstance<Guid, IFlowModule>>

ReceivesInputFromMultipleModules

public bool ReceivesInputFromMultipleModules { get; set; }

Property Value

bool

RemoteSessionEnabled

[JsonIgnore]
public bool RemoteSessionEnabled { get; set; }

Property Value

bool

Resources

public IList<ResourceBase> Resources { get; set; }

Property Value

IList<ResourceBase>

Settings

public FlowModuleSettings Settings { get; protected set; }

Property Value

FlowModuleSettings

SettingsUri

public string SettingsUri { get; }

Property Value

string

Status

[JsonIgnore]
public Status Status { get; }

Property Value

Status

Topic

To get the topic for routing modules. This setting should be refactored with the ModuleType later on.

[Obsolete("Modules that communicate via a specific protocol will solve the communication on their own")]
[JsonIgnore]
public string? Topic { get; set; }

Property Value

string

Type

[JsonIgnore]
public string Type { get; }

Property Value

string

Uri

public string Uri { get; }

Property Value

string

UserFriendlyName

Name to present to users

public abstract string UserFriendlyName { get; }

Property Value

string

Methods

AddMethod<TParameters, TResult>(string, Func<TParameters, Task<(TResult, FlowError?)>>)

protected void AddMethod<TParameters, TResult>(string name, Func<TParameters, Task<(TResult, FlowError?)>> method)

Parameters

name string
method Func<TParameters, Task<(TResult, FlowError)>>

Type Parameters

TParameters
TResult

AddMethod<TParameters, TResult>(string, string, Func<TParameters, Task<(TResult, FlowError?)>>)

protected void AddMethod<TParameters, TResult>(string uri, string name, Func<TParameters, Task<(TResult, FlowError?)>> method)

Parameters

uri string
name string
method Func<TParameters, Task<(TResult, FlowError)>>

Type Parameters

TParameters
TResult

AddModuleMethod<TParameters, TResult>(string, Func<TParameters, Task<(TResult, FlowError?)>>)

protected void AddModuleMethod<TParameters, TResult>(string name, Func<TParameters, Task<(TResult, FlowError?)>> method)

Parameters

name string
method Func<TParameters, Task<(TResult, FlowError)>>

Type Parameters

TParameters
TResult

AddSettingMethod<TParameters, TResult>(string, Func<TParameters, Task<(TResult, FlowError?)>>)

protected void AddSettingMethod<TParameters, TResult>(string name, Func<TParameters, Task<(TResult, FlowError?)>> method)

Parameters

name string
method Func<TParameters, Task<(TResult, FlowError)>>

Type Parameters

TParameters
TResult

AllowMessageToEnterModule(IFlowMessage)

protected abstract bool AllowMessageToEnterModule(IFlowMessage message)

Parameters

message IFlowMessage

Returns

bool

BypassMessageNotMatchingRules()

protected abstract bool BypassMessageNotMatchingRules()

Returns

bool

CanStart()

[Obsolete("This method will be removed in the next major version")]
public virtual IError? CanStart()

Returns

IError

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public virtual void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

FlowDefinitionId()

public Guid FlowDefinitionId()

Returns

Guid

GetCredential(Guid)

This will return the Credential loaded into the Settings.Credential dictionary. If you need to download the resource use the IFlowCredentialsManagerService

[Obsolete("Use GetCredentialAsync instead")]
public IResult<Credential> GetCredential(Guid credentialId)

Parameters

credentialId Guid

Returns

IResult<Credential>

GetCredentialAsync(Guid)

If the credential is not found locally it will be downloaded. This call need all required services to be registered in the ServiceCollection. This is done by the runtime, but if you are using the method in a unit test you need to handle these requirements.

public Task<IResult<Credential>> GetCredentialAsync(Guid credentialId)

Parameters

credentialId Guid

Returns

Task<IResult<Credential>>

GetCredentialContentAs<T>(Guid)

This will return the Credential loaded into the Settings.Credential dictionary. If you need to download the resource use the IFlowCredentialsManagerService

[Obsolete("Use GetCredentialContentAsync instead")]
public IResult<T> GetCredentialContentAs<T>(Guid credentialId) where T : class, new()

Parameters

credentialId Guid

Returns

IResult<T>

Type Parameters

T

Exceptions

NullReferenceException

GetCredentialContentAsync<T>(Guid)

If the credential is not found locally it will be downloaded. This call need all required services to be registered in the ServiceCollection. This is done by the runtime, but if you are using the method in a unit test you need to handle these requirements.

public Task<IResult<T>> GetCredentialContentAsync<T>(Guid credentialId) where T : class, new()

Parameters

credentialId Guid

Returns

Task<IResult<T>>

Type Parameters

T

Exceptions

NullReferenceException

GetResource(Guid)

This will return the ResourceItem loaded into the Settings.Resources dictionary. If you need to download the resource use the IFlowResourceManagerService

[Obsolete("Use GetResourceAsync instead")]
public IResult<ResourceItem> GetResource(Guid resourceId)

Parameters

resourceId Guid

Returns

IResult<ResourceItem>

GetResourceAsync(Guid)

If the resource is not found locally it will be downloaded. This call need all required services to be registered in the ServiceCollection. This is done by the runtime, but if you are using the method in a unit test you need to handle these requirements.

public Task<IResult<ResourceItem>> GetResourceAsync(Guid resourceId)

Parameters

resourceId Guid

Returns

Task<IResult<ResourceItem>>

GetResourceContentAs<T>(Guid)

This will return the ResourceItem loaded into the Settings.Resources dictionary. If you need to download the resource use the IFlowResourceManagerService

[Obsolete("Use GetResourceContentAsync instead")]
public IResult<T> GetResourceContentAs<T>(Guid resourceId) where T : class, new()

Parameters

resourceId Guid

Returns

IResult<T>

Type Parameters

T

Exceptions

NullReferenceException

GetResourceContentAsync<T>(Guid)

If the resource is not found locally it will be downloaded. This call need all required services to be registered in the ServiceCollection. This is done by the runtime, but if you are using the method in a unit test you need to handle these requirements.

public Task<IResult<T>> GetResourceContentAsync<T>(Guid resourceId) where T : class, new()

Parameters

resourceId Guid

Returns

Task<IResult<T>>

Type Parameters

T

Exceptions

NullReferenceException

Initialize()

This method will be called when the flow is about to be started, but before the call to Start()

public virtual Task<IError?> Initialize()

Returns

Task<IError>

An awaitable Task

InitializeInteractivity()

Override this method and register your module interactivity methods

public virtual void InitializeInteractivity()

InteractiveSessionRequest(string, string, JsonElement)

public Task<(object? result, FlowError? error)> InteractiveSessionRequest(string uri, string method, JsonElement parameters)

Parameters

uri string
method string
parameters JsonElement

Returns

Task<(object result, FlowError error)>

InteractiveSessionUri(string)

Obsolete method to get the interactive session URI. This method is deprecated and should be replaced with Uri and interpolated string. Uri

[Obsolete("Use Uri and interpolated string instead")]
public string InteractiveSessionUri(string uri)

Parameters

uri string

Returns

string

Interactivity()

public virtual ModuleInteractivity Interactivity()

Returns

ModuleInteractivity

LoadSettings(string)

public abstract void LoadSettings(string settingsAsJson)

Parameters

settingsAsJson string

MessageReceived(IFlowMessage)

Implement this method in your custom modules to implement logic for the FlowMessage passing through the module. If you want to pass data to the next IFlowModule you should call Next(params IFlowMessage[]) in this method

protected abstract Task MessageReceived(IFlowMessage message)

Parameters

message IFlowMessage

The FlowMessage passed into the module

Returns

Task

An awaitable Task

Next(params IFlowMessage[])

When you want to pass the message(s) to the next module(s) in the. This should be called from the MessageReceived(IFlowMessage) method.

protected Task Next(params IFlowMessage[] messages)

Parameters

messages IFlowMessage[]

The parameter is 0 to n FlowMessage"

Returns

Task

An awaitable Task

Receive(IFlowMessage)

Passing data to this will flag the module to process the message. In most cases this will be done by the flow-engine or the flow but in special cases you can call this manually to trigger the processing of a message

public Task Receive(IFlowMessage message)

Parameters

message IFlowMessage

The FlowMessage passed into the module

Returns

Task

An awaitable Task

ReceiveFrom(IFlowModule, int)

Will register the module passed in as a receiver from this module. The module will will be registered at output index 0 by default

public IFlowModule ReceiveFrom(IFlowModule module, int ix = 0)

Parameters

module IFlowModule

The module to receive data

ix int

The output-index to register the module on

Returns

IFlowModule

SendTo(IFlowModule, int)

Will pass messages this module to the module passed in

public IFlowModule SendTo(IFlowModule module, int ix = 0)

Parameters

module IFlowModule

The module that will receive the data

ix int

The output index to add the module to

Returns

IFlowModule

The module that will receive the data (the module passed in)

SetNrOfOutputs(int)

protected void SetNrOfOutputs(int value)

Parameters

value int

SetStatus(Status)

Set the Status of the module. If the current status is different the OnStatusChanged event will be triggered.

public void SetStatus(Status status)

Parameters

status Status

The new Status

SetStatus(Status, string)

Set the Status of the module. If the current status is different the OnStatusChanged event will be triggered.

public void SetStatus(Status status, string message = "")

Parameters

status Status

The new Status

message string

The message to attach to the ModuleStatusEvent

SetStatus(Status, string, bool)

public void SetStatus(Status status, string message = "", bool force = false)

Parameters

status Status
message string
force bool

SetStatus(Status, string, bool, Exception?)

Set the Status of the module. If the current status is different the OnStatusChanged event will be triggered.

public void SetStatus(Status status, string message = "", bool force = false, Exception? exception = null)

Parameters

status Status

The new Status

message string

The message to attach to the ModuleStatusEvent

force bool

Pass true to force the OnStatusChanged event to be triggered regardless of current status

exception Exception

Start()

This method will be called when the flow is about to be started, but after the call to Initialize()

public virtual Task<IError?> Start()

Returns

Task<IError>

A Crosser.EdgeNode.Common.Abstractions.Utilities.Errors.IError describing the error. If null there was no error.

Stop()

This method will be called when the flow is about to be stopped.

public virtual Task Stop()

Returns

Task

An awaitable Task

UpdateFlowReceivedStatistics(long)

[Obsolete("This method will be removed in the next major version")]
protected void UpdateFlowReceivedStatistics(long size = 0)

Parameters

size long

UpdateFlowSentStatistics(long)

[Obsolete("This method will be removed in the next major version")]
protected void UpdateFlowSentStatistics(long size = 0)

Parameters

size long

UpdateModuleReceivedStatistics(long)

[Obsolete("This method will be removed in the next major version")]
protected void UpdateModuleReceivedStatistics(long size = 0)

Parameters

size long

UpdateModuleSentStatistics(long)

[Obsolete("This method will be removed in the next major version")]
protected void UpdateModuleSentStatistics(long size = 0)

Parameters

size long

ValidateSettings(SettingsValidator)

public virtual void ValidateSettings(SettingsValidator validator)

Parameters

validator SettingsValidator