Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA Enterprise SCADA Execution Pipeline API Reference

Write a New Step within the Krunch Pipeline Data Stream

Write a New Step within the Krunch Pipeline Data Stream

This scenario guides you through the steps required to add a new step code into the Krunch Pipeline Data Stream.

To identify the code associated with each step, see the code comments in the Example code section.

To add a new step into the Krunch Pipeline Data Stream.

In this example, the step code is written to a file called MyNewStep.cs.

  1. In the created project used to create the step code, open or create the class file.
  2. Ensure that the following libraries (at a minimum) are referenced at the top of the file:
    using System;
    using OASySDNA.RealTime.ExecutionPipelines.KrunchCommon.Context;
    using OASySDNA.RealTime.ExecutionPipelines.KrunchDataStream.Steps.Common;
  1. Ensure that the namespace is appropriate for a KrunchDataStream step and the appropriate RealTime database (RTDB) table.

    For example:

  1. namespace OASySDNA.RealTime.ExecutionPipelines.KrunchDataStream.Steps.Analog
  2. Name the class to the name of your step, inheriting from IStep.
  3. Set the Name member of the IStepInterface to the name of your step.
  4. Set the ExecutionRequired member of the IStep Interface.
  5. Create the step method with IStepContext and ICachedSettings as parameters, and returning an IStepContext.
  6. Initialize return parameters and local stepContext variables that access the krunch context parameters.
  7. Create the code within the step as desired.
  8. Catch exceptions and gracefully perform error handling.
  9. Provide a StepResult to the context with the resultState of success/failure and the resultException (if it exists).
  10. Return the updated step context.

Example code

// In the created project used to create the step code, open, or create the class file.
// Ensure that the following libraries (at a minimum) are referenced at the top of the file.
using System;
using OASySDNA.RealTime.ExecutionPipelines.KrunchCommon.Context;
using OASySDNA.RealTime.ExecutionPipelines.KrunchDataStream.Steps.Common;
// Ensure that the namespace is for a KrunchDataStream step, and the appropriate RealTime table.
namespace OASySDNA.RealTime.ExecutionPipelines.KrunchDataStream.Steps.Analog
{
    // Name the class to the name of your step, inheriting from IStep.
    public sealed class MyNewStep : IStep
    {
        // Set the Name member of the IStepInterface to the name of your step.
        public String Name { get; } = "MyNewStep";
        // Set the ExecutionRequired member of the IStep Interface.
        public Boolean ExecutionRequired { get; } = false;
        // Create the step method, with IStepContext and ICachedSettings
        // as parameters, and returning an IStepContext.
        /// <param name="stepContext">Context for krunching that contains information passed between steps.</param>
        /// <param name="cachedSettings">Cached configurations from RealTime JSON files.</param>
        /// <returns>The stepContext that has been updated by the step.</returns>
        public IStepContext Execute(IStepContext stepContext, ICachedSettings cachedSettings)
        {
            // Initialize return parameters and local stepContext variables that access the krunch context parameters.
            Exception resultException = null;
            var resultState = true;
            var context = stepContext as KrunchContext;
            var commonParameters = context.CommonParameters as CommonKrunchDataStreamParameters;
            var additionalParameters = context.AdditionalParameters;
            var setRecord = context.CommonParameters.SetRecord;
            try
            {
                 // Create the code within the step as desired.
                 DoStepCode();
            }
            catch (Exception exp)
            {
                // Catch exceptions and gracefully perform error handling.
                // Set the resultState to false and save a copy of the exception.
                resultException = exp;
                resultState = false;
            }
            // Provide a StepResult to the context with the resultState of success/failure and the resultException (if it exists).
            context.StepResults.Add(new StepResult(Name, resultState, resultException));
            // Return the updated step context that contains success/failure of our step.
            return context;
        }
    }
}
TitleResults for “How to create a CRG?”Also Available in