Table of Contents

Class ActivityContext

Namespace
Acuit.Pinpoint.Workflows
Assembly
Acuit.Pinpoint.Workflows.dll

The context available to an activity during its execution.

public sealed class ActivityContext : IDisposable
Inheritance
ActivityContext
Implements
Inherited Members
Extension Methods

Remarks

Instances of activities only contain definitions; they do not themselves track runtime state. All runtime state is only available via this context.

Each executing activity instance gets its own context instance, so an instance of this context represents a single executing activity instance. Its lifetime coincides with the execution of the activity instance.

Context is inherited from the parent activity as appropriate.

Each activity context keeps track of the following:

  • A data context: There is one WorkflowDataContext instance shared by all activities executing in a workflow. Members: DataContext
  • Parameters: Input parameters available to the executing activity, as a named dictionary of objects. Each activity inherits all parameters from its parent, plus any parameters defined by the activity. Any parameter defined by this activity with the same name as an inherited parameter will hide access to the parameter in the parent activity's context. Before the activity is executed, each input parameter defined by the activity will be initialized via the parameter value provider (see below); the activity execution will fail if the parameter is not provided and has no default value. Members: Parameters
  • Variables: Variables available to the executing activity, as a named dictionary of objects. Each activity inherits all variables from its parent, plus any variables defined by the activity. Any variable defined by this activity with the same name as an inherited variable will exist as a new variable, hiding access to the variable in the parent activity's context. Members: Variables
  • Local state: Local, private data associated with the executing activity, as a named dictionary of objects. This data is not inherited by child activities. State data items can be created as needed while the activity executes. Members: GetStateValue<TValue>(string), SetStateValue<TValue>(string, TValue)
  • A service provider: Each activity has its own service provider, which can be inherited from its parent or can be unique to the executing activity, possibly augmenting the services provided by the parent. Members: ServiceProvider
  • A parameter value provider: Each activity has its own parameter value provider, which can be inherited from its parent or can be unique to the executing activity, possibly augmenting the parameter value provider provided by the parent. This is how an activity can make a data value available to a child activity. Members: ParameterValueProvider
  • An event bus: There is one event bus shared by all activities executing in a workflow. Members: RegisterEvent<TEvent>(WorkflowEventHandler<TEvent>), UnregisterEvent<TEvent>(WorkflowEventHandler<TEvent>), RaiseEvent<TEvent>(TEvent)

Properties

DataContext

Gets the data context used to exchange data with the world outside of the workflow (e.g., WPF) while a workflow is executing.

public WorkflowDataContext DataContext { get; }

Property Value

WorkflowDataContext

ParameterValueProvider

Gets the parameter value provider.

public IParameterValueProvider ParameterValueProvider { get; }

Property Value

IParameterValueProvider

Parameters

Gets the parameters.

public IParametersStorage Parameters { get; }

Property Value

IParametersStorage

ServiceProvider

Gets the service provider.

public IServiceProvider ServiceProvider { get; }

Property Value

IServiceProvider

Variables

Gets the variables.

public VariablesStorage Variables { get; }

Property Value

VariablesStorage

Methods

Dispose()

Closes and releases all resources used by the ActivityContext.

public void Dispose()

ExecuteChildActivityAsync(IActivity, IParameterValueProvider, IServiceProvider, CancellationToken)

Executes a child activity.

public Task ExecuteChildActivityAsync(IActivity activity, IParameterValueProvider parameterValueProvider, IServiceProvider serviceProvider, CancellationToken cancellationToken)

Parameters

activity IActivity

The activity to execute.

parameterValueProvider IParameterValueProvider

The parameter value provider for the child activity to use.

serviceProvider IServiceProvider

The service provider for the child activity to use.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A task that represents the asynchronous operation.

Exceptions

ArgumentNullException

activity is null.

ArgumentNullException

parameterValueProvider is null.

ArgumentNullException

serviceProvider is null.

Exception

An error occurred while executing the activity.

ExecuteChildActivityAsync(IActivity, IParameterValueProvider, CancellationToken)

Executes a child activity.

public Task ExecuteChildActivityAsync(IActivity activity, IParameterValueProvider parameterValueProvider, CancellationToken cancellationToken)

Parameters

activity IActivity

The activity to execute.

parameterValueProvider IParameterValueProvider

The parameter value provider for the child activity to use.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A task that represents the asynchronous operation.

Remarks

The service provider for this activity context will be used for the child activity.

Exceptions

ArgumentNullException

activity is null.

ArgumentNullException

parameterValueProvider is null.

Exception

An error occurred while executing the activity.

ExecuteChildActivityAsync(IActivity, IServiceProvider, CancellationToken)

Executes a child activity.

public Task ExecuteChildActivityAsync(IActivity activity, IServiceProvider serviceProvider, CancellationToken cancellationToken)

Parameters

activity IActivity

The activity to execute.

serviceProvider IServiceProvider

The service provider for the child activity to use.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A task that represents the asynchronous operation.

Remarks

The parameter value provider for this activity context will be used for the child activity.

Exceptions

ArgumentNullException

activity is null.

ArgumentNullException

serviceProvider is null.

Exception

An error occurred while executing the activity.

ExecuteChildActivityAsync(IActivity, CancellationToken)

Executes a child activity.

public Task ExecuteChildActivityAsync(IActivity activity, CancellationToken cancellationToken)

Parameters

activity IActivity

The activity to execute.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A task that represents the asynchronous operation.

Remarks

The parameter value provider and service provider for this activity context will be used for the child activity.

Exceptions

ArgumentNullException

activity is null.

Exception

An error occurred while executing the activity.

ExecuteChildActivityAsync<TResult>(Activity<TResult>, IParameterValueProvider, IServiceProvider, CancellationToken)

Executes a child activity.

public Task<TResult> ExecuteChildActivityAsync<TResult>(Activity<TResult> activity, IParameterValueProvider parameterValueProvider, IServiceProvider serviceProvider, CancellationToken cancellationToken)

Parameters

activity Activity<TResult>

The activity to execute.

parameterValueProvider IParameterValueProvider

The parameter value provider for the child activity to use.

serviceProvider IServiceProvider

The service provider for the child activity to use.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TResult>

A task that represents the asynchronous operation.

Type Parameters

TResult

Exceptions

ArgumentNullException

activity is null.

ArgumentNullException

parameterValueProvider is null.

ArgumentNullException

serviceProvider is null.

Exception

An error occurred while executing the activity.

ExecuteChildActivityAsync<TResult>(Activity<TResult>, IParameterValueProvider, CancellationToken)

Executes a child activity.

public Task<TResult> ExecuteChildActivityAsync<TResult>(Activity<TResult> activity, IParameterValueProvider parameterValueProvider, CancellationToken cancellationToken)

Parameters

activity Activity<TResult>

The activity to execute.

parameterValueProvider IParameterValueProvider

The parameter value provider for the child activity to use.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TResult>

A task that represents the asynchronous operation.

Type Parameters

TResult

Remarks

The service provider for this activity context will be used for the child activity.

Exceptions

ArgumentNullException

activity is null.

ArgumentNullException

parameterValueProvider is null.

Exception

An error occurred while executing the activity.

ExecuteChildActivityAsync<TResult>(Activity<TResult>, IServiceProvider, CancellationToken)

Executes a child activity.

public Task<TResult> ExecuteChildActivityAsync<TResult>(Activity<TResult> activity, IServiceProvider serviceProvider, CancellationToken cancellationToken)

Parameters

activity Activity<TResult>

The activity to execute.

serviceProvider IServiceProvider

The service provider for the child activity to use.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TResult>

A task that represents the asynchronous operation.

Type Parameters

TResult

Remarks

The parameter value provider for this activity context will be used for the child activity.

Exceptions

ArgumentNullException

activity is null.

ArgumentNullException

serviceProvider is null.

Exception

An error occurred while executing the activity.

ExecuteChildActivityAsync<TResult>(Activity<TResult>, CancellationToken)

Executes a child activity.

public Task<TResult> ExecuteChildActivityAsync<TResult>(Activity<TResult> activity, CancellationToken cancellationToken)

Parameters

activity Activity<TResult>

The activity to execute.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TResult>

A task that represents the asynchronous operation.

Type Parameters

TResult

Remarks

The parameter value provider and service provider for this activity context will be used for the child activity.

Exceptions

ArgumentNullException

activity is null.

Exception

An error occurred while executing the activity.

GetStateValue<TValue>(string)

Gets an existing data value from the local state collection.

public TValue GetStateValue<TValue>(string key)

Parameters

key string

The data key.

Returns

TValue

The data value.

Type Parameters

TValue

The data value type.

Exceptions

ArgumentNullException

key is null.

KeyNotFoundException

key does not exist in the collection.

InvalidCastException

The data value in the collection is not of type TValue.

RaiseEvent<TEvent>(TEvent)

Raises an event on the workflow event bus.

public void RaiseEvent<TEvent>(TEvent e)

Parameters

e TEvent

The event.

Type Parameters

TEvent

The event type.

Remarks

All registered event handlers for event type TEvent will be called synchronously, in the order in which they were registered. This will return once all of the event handlers have executed.

There is one workflow event bus shared by the entire workflow.

RegisterEvent<TEvent>(WorkflowEventHandler<TEvent>)

Registers an event handler on the workflow event bus.

public void RegisterEvent<TEvent>(WorkflowEventHandler<TEvent> eventHandler)

Parameters

eventHandler WorkflowEventHandler<TEvent>

The event handler.

Type Parameters

TEvent

The event type.

Remarks

Whenever any activity raises an event of type TEvent (via RaiseEvent<TEvent>(TEvent)), eventHandler will be called. All registered event handlers are called in the order in which they are registered. Calling this multiple times for the same event type and event handler will cause the event handler to be called multiple times.

There is one workflow event bus shared by the entire workflow.

Exceptions

ArgumentNullException

eventHandler is null.

SetStateValue<TValue>(string, TValue)

Sets a data value in the local state collection.

public void SetStateValue<TValue>(string key, TValue value)

Parameters

key string

The data key.

value TValue

The data value.

Type Parameters

TValue

The data value type.

Remarks

If the specified key does not exist, a new data value with the specified key will be added; otherwise, the existing data value will be replaced.

UnregisterEvent<TEvent>(WorkflowEventHandler<TEvent>)

Unregisters an event handler on the workflow event bus that has been previously registered via RegisterEvent<TEvent>(WorkflowEventHandler<TEvent>).

public void UnregisterEvent<TEvent>(WorkflowEventHandler<TEvent> eventHandler)

Parameters

eventHandler WorkflowEventHandler<TEvent>

The event handler.

Type Parameters

TEvent

The event type.

Remarks

If the eventHandler event handler is not currently registered for the TEvent event type, then this will do nothing and will not throw an exception.

Exceptions

ArgumentNullException

eventHandler is null.