PDIM Library

by onezero
2 years ago
1002 Views

Table of Contents


Voodoo Code Step: Main Class

The below design enables the user to write and use their own codes in scenario flow. Below is the default code version of the code step produced in C# selection. The target code needs to be written in the ExecuteComputation method. In scenario flow, when coming to this step, this main method is called. After this method completed, the scenario goes on to other steps. To integrate your code into the scenario, you can use one of the Voodoo Built-In Library namely Voodoo Plan Data Instance Manager (PDIM).

namespace VoodooImplementation
{
    using System;
    using System.Windows.Forms;
    using VooDooCommonData.CommonInterface;
    using VooDooCommonData.InstanceData;

    public class ComputationEvaluator : System.MarshalByRefObject, IPlugInComputation
    {
        private bool result_;
        private VooDooCommonData.InstanceData.PlanDataInstanceManager planDataInstanceManager_;

        public ComputationEvaluator()
        {
        }

        public bool result
        {
            get
            {
                return result_;
            }
        }

        public virtual VooDooCommonData.InstanceData.PlanDataInstanceManager planDataInstanceManager
        {
            get
            {
                return planDataInstanceManager_;
            }
            set
            {
                planDataInstanceManager_ = value;
            }
        }

        public virtual void ExecuteComputation()
        {
            //First Initialized Method: Your Code Here
        }
    }
}

PlanDataInstanceManager Class

Constructors

Property Description
PlanDataInstanceManager() Create a new instance of an object.

Note: Object for this class is automatically created by Voodoo as shown above in default class schema. So, there is no need to manually create that.

Methods

Property Description
void SetDataRowIndex (long dataDefinitionId, long dataRowIndex) Move the pointer to the target index in DataSource.

dataDefinitionId: DataSource Id
dataRowIndex: Index to be set

Example: You create DataSource that’s Id is 3. And, you want to set the pointer of DataSource into the first row. So, you need to call the below code.

planDataInstanceManager_.SetDataRowIndex(3, 0);
long GetDataRowIndex(long dataDefinitionId) Return the active row’s index in DataSource.

dataDefinitionId: DataSource Id

Example: You create a DataSource that’s Id is 3. And, you want to get the pointer location of DataSource. So, you need to call the below code.

long curRowIndex = planDataInstanceManager_.GetDataRowIndex(3);
void IncrementDataRowIndex(long dataDefinitionId) Increment the index of active row in DataSource.

dataDefinitionId: DataSource Id

Example: You have a data source that’s Id is 3 and in there are 10 records. Active row is 0 at initialization of DataSource during scenario process execution. And, you want to increment the pointer of DataSource up to next row. So, you need to call the below code.

planDataInstanceManager_.IncrementDataRowIndex(3);
bool CheckIfDataRowIndexLessThanDataRowCount(long dataDefinitionId) Return true if active row is smaller than data table row count else return false. Especially, use to get to know when loop through whether last row is passing on the DataTable.

dataDefinitionId: DataSource Id

Example: You have a data source that’s Id is 3 and in there are some records. And, you want to know the last pointer of DataSource and whether there is a new row. So, you need to call the below code.

if (planDataInstanceManager_.CheckIfDataRowIndexLessThanDataRowCount(3))
{
    result_ = true;
}
else
{
    result_ = false;
}
object GetDataTableValueFromCurrentDataRowIndex(long dataDefinitionId, string columnName) Return the column value that is given as parameter on active row in DataTable as object type.

dataDefinitionId: DataSource Id

Example: You have a DataSource that’s Id is 3 and in there are 5 records. And, you need to get the value of active row at “Ad” column in this DataSource. So, you need to call the below code.

string ad = planDataInstanceManager_.GetDataTableValueFromCurrentDataRowIndex(3, “Ad”).ToString();
void SetDataTableValueFromCurrentDataRowIndex(long dataDefinitionId, string columnName, object value) Set the value given to the column value given as a parameter in the active row in the data table.

dataDefinitionId: DataSource Id

Example: You have a DataSource that’s Id is 3 and in there are 5 records. And, you need to set the value as “Ahmet” to active row of “Ad” column in this DataSource. So, you need to call the below code.

Note: Variable type of column and set value type must be same.

planDataInstanceManager_.SetDataTableValueFrom(3, "Ad", "Ahmet");
object GetVariableValue(long dataDefinitionId) Return the value given to the column value given as a parameter in the active row in the data table.

dataDefinitionId: DataSource Id

Example: You have a DataSource that’s Id is 3 and in there are 5 records. And, you need to get the value from active row of first column. So, you need to call the below code.

string deger = planDataInstanceManager_. GetDataTableValueFrom(3).ToString();
void SetVariableValue(long dataDefinitionId, object value) Set the value given to the value of the first column in the active row in the DataSource.

dataDefinitionId: DataSource Id
Value: Set value

Example: You have a DataSource that’s Id is 3 and in there are 5 records. And, you need to set the value as “Suna” to active row of first column in this DataSource. So, you need to call the below code.

Note: Variable type of column and set value type must be same.

planDataInstanceManager_.SetDataTableValueFrom(3, "Suna");
Type GetDataTypeOfColumn(long dataDefinitionId, string columnName) Return the value of requested column type in the DataSource.

dataDefinitionId: DataSource Id
columnName: Column name requested data type

Example: You have a DataSource that’s Id is 3. And, you need to get “Ad” column type whether is string. So, you need to call the below code.

if (columnType == System.Type.GetType("System.String"))
{
    // ..
}
int SetDataTableValueFromCurrentDataRowIndexWithTypeConversion(long dataDefinitionId, string columnName, string stringValue) Set the value given to the column value given as a parameter in the active row in the DataSource. Since the given value is a string, it assigns the value of the string to the column data type, if necessary, by looking at the type of the column.

dataDefinitionId: DataSource Id
columnName: Column name requested data type
Value: Set value

Example: You have a DataSource that’s Id is 3 and in there are 5 records. And, you need to call the value to set “123” value to active column of “Adet” column in the DataSource. So, you need to call the below code. During the set time, function set the “123” string value as number in case the column type is number.

Note: System.String, System.Int32, System.Int64, System.Decimal types are supported.

planDataInstanceManager_.SetDataTableValueFromCurrentDataRowIndexWithTypeConversion(3, “Adet”, “123”);
System.Data.DataRow GetNewRow(long dataDefinitionId) Create a new row to add in the DataSource.

dataDefinitionId: DataSource Id
dataRow: Adding row

Example: You have a DataSource that’s Id is 3. And, you need to add a new row to the end of the DataSource with 3 columns. So, you need to call the below code.

Note: This function does not increment the pointer by 1.

DataRow dr = planDataInstanceManager_.GetNewRow(3);
dr[0] = 0;
dr[1] = "";
dr[2] = "";
planDataInstanceManager_.AddRowToDataTable(3, dr);
void DeleteRowFromDataTable(long dataDefinitionId, int rowIndexToDelete) Delete a row from DataSoruce.

dataDefinitionId: DataSource Id
Value: Set value

Example: You have a DataSource that’s Id is 3. And, you need to delete a row from the DataSource. So, you need to call the below code.

planDataInstanceManager_.DeleteRowFromDataTable(3, 0);
void GetParameter(String dataFromDataSource, StringByRef data) Assigns a variable in the data source to a variable in the code step.

dataFromDataSource: Data in Data Source
data: Data Wanted to Add in Code Step

Example: We need to assign the variable named “ParaBirimi” existing in the data source to the variable “currency_”. So, you need to call the below code.

planDataInstanceManager_.GetParameter("ParaBirimi", ref currency_);
void AddRowToDataTable(int ID, DataRow dataRow) This function adds the data line that we defined in the code to the data source whose ID we have given.

ID: Data Source ID
dataRow: Datasource row defined in code step

Example: We need to add the data source row named row to the data source with ID 3. So, you need to call the below code.

planDataInstanceManager_.AddRowToDataTable(int 3, DataRow satir);
String GetParameters() Returns the list of parameters defined to the scenario.

Example: We want to get all the parameters defined in the scenario. So, you need to call the below code.

planDataInstanceManager_.GetParameters();
bool GetRuntimeVar(string name, out object value) Returns runtime variable.

name: Name of Parameter.
value: Return value.

Example: We want to get the value of the runtime variable named Data. So, you need to call the below code.

planDataInstanceManager_.GetRuntimeVar("Data", int);
bool GetRuntimeVarWithStepId(string name, out object value, long stepId) Returns runtime variable which have step id

name: Name of Parameter.
value: Return value.
stepId: The id of the step in which the variable was created.

Example: We want to get the value of the runtime variable named Data defined in Step 3. So, you need to call the below code.

planDataInstanceManager_.GetRuntimeVarWithStepId("Data", int, 3);
void SetRuntimeVar(string name, object value) If it does not exist, it creates the step-based runtime variable used in the scenario and assigns its value. If the variable was created before, it just updates its value.

Note: Runtime variables are scenario based and are reset when the scenario is started.

name: Name of Parameter
value: Return value.

Example: We want to assign the value “a” to the runtime variable named “p1”. So, you need to call the below code.

planDataInstanceManager.SetRunTimeVar("p1", "a");
void SetRuntimeVarWithStepId(string name, object value, long stepId) If it does not exist, it creates the step-based runtime variable used in the scenario and assigns its value. If the variable was created before, it just updates its value.

Note: Runtime variables are scenario based and are reset when the scenario is started.

name: Name of Parameter

value: Return value.
stepId: The id of the step in which the variable was created.

Example: We want to assign the value “a” to the runtime variable named “p1” defined in Step 3. So, you need to call the below code.

planDataInstanceManager.SetRuntimeVarWithStepId("p1", "a", 3);
void RemoveRuntimeVar(System.String name) Deletes the runtime parameter used in the scenario.

name: Name of Parameter.

Example: We want to delete the runtime variable named “p1”. So, you need to call the below code.

planDataInstanceManager.RemoveRuntimeVar("p1");
void RemoveRuntimeVarWithStepId(System.String name ,Int64 stepId) Deletes the runtime variable used in the scenario.

name: Name of Parameter
stepId: The id of the step in which the variable was created.

Example: We want to delete the runtime variable defined in step 3 named “p1”. So, you need to call the below code.

planDataInstanceManager.RemoveRuntimeVarWithStepId("p1", 3);
void GotoStep(long stepId) It directs the stream to a specific step. The step must be in the same flow.

stepId : The id value of the step to which the flow is to be directed.

Example: We want to go to the step with the Id value of 115 in the stream. So, you need to call the below code.

planDataInstanceManager.planDataInstanceManager_.GotoStep(115);
bool CheckIfExist(Int64 Id) It checks whether the data source whose id is given exists.

Example: We want to check if the data source with id 3 exists. So, you need to call the below code.

planDataInstanceManager_.CheckIfExist(3);
void Log(VooDooCommonData.InstanceData.EnLogType LogType, System.String LogMessage) Writes the desired log message to the result section of the logs of the relevant step in UC and to the additional information area in the studio.

Example: We want to send a “Veri bağlantısı yapıldı” message to the logs. So, you need to call the below code.

Note: There are two types of log messages. These are;
Type.Info: Info Message.
Type.Error: Error Message.

planDataInstanceManager_.Log(VooDooCommonData.InstanceData.EnLogType.Info, "Veri bağlantısı yapıldı");