Table of Contents

Interface IDslCompilerContext

Namespace: Casewhere.Runtime.DSL.CompilerContext
Assembly: Casewhere.Runtime.dll

This interface will provide a list of function that helps user create the data to data object for each levels in the system.

public interface IDslCompilerContext

Extension Methods

ObjectExtension.ConvertToBsonValue(object), EnumExtensions.DeepClone<IDslCompilerContext>(IDslCompilerContext)

Properties

Activity

The Activity in Context.

DslActivity Activity { get; }

Property Value

DslActivity

Case

The Case in Context.

DslCase Case { get; }

Property Value

DslCase

FormData

The Form ActualData in context.

dynamic FormData { get; }

Property Value

dynamic

Input

Workflow input object. If there is multiple objects, it references the first one.

dynamic Input { get; }

Property Value

dynamic

Inputs

Workflow input objects.

IList<dynamic> Inputs { get; }

Property Value

IList<dynamic>

Output

Using this property to get/set Output value object for the workflow in the current context.

object Output { get; set; }

Property Value

object

Parameters

The parameters are parsed from the query string of the web trigger request Assume that a dynamic web trigger has the friendly uri: employee/info
Then a request for that trigger is: employee/info?isActive=true&from=2020-07-27

var dataApi = ctx.Use<IDataApi>();
var @from = ctx.Parameters.Get<DateTime>("from");
var isActive = ctx.Parameters["isActive"];
var filter = FilterBuilder.Create().Eq("Active", isActive)
.Gt("CreatedAt", @from)
.Build();
var result = dataApi.Search(DataObjectApiQuery
.For("Employee")
.FilterBy(filter));
var employee  = result.Data.FirstOrDefault();
ctx.Output = employee;

DynamicDataObject Parameters { get; }

Property Value

DynamicDataObject

RouteParameters

The route parameters are parsed from the url of the web trigger request Assume that a dynamic web trigger has the friendly uri: employee/info/{code}
Then a request for that trigger is: employee/info/DEV-123

var dataApi = ctx.Use<IDataApi>();
var employeeCode = ctx.RouteParameters.Get<string>("code");
var filter = FilterBuilder.Create().Eq("Active", true)
.Eq("Code", employeeCode)
.Build();
var result = dataApi.Search(DataObjectApiQuery
.For("Employee")
.Paging(0, 1)
.FilterBy(filter));
var employee  = result.Data.FirstOrDefault();
ctx.Output = employee;

DynamicDataObject RouteParameters { get; }

Property Value

DynamicDataObject

User

The User in context.

DslUser User { get; }

Property Value

DslUser

WorkerSite

The WorkerSite in Context

DslWorkerSite WorkerSite { get; }

Property Value

DslWorkerSite

Workflow

The Workflow in Context.

DslWorkflow Workflow { get; }

Property Value

DslWorkflow

WorkflowContext

The context object.

DslWorkflowContext WorkflowContext { get; }

Property Value

DslWorkflowContext

Methods

AddDataObject(string, object)

[Obsolete]
string AddDataObject(string dataClass, object data)

Parameters

dataClass string

data object

Returns

string

AttachToDataSource(string, params string[])

Links a ActualData Object that is created in Scripted Activity to a Workflow ActualData Source so it can be used in Form Activity.

void AttachToDataSource(string dataSourceName, params string[] dataObjectIds)

Parameters

dataSourceName string

ActualData Source name.

dataObjectIds string[]

ActualData Object ids.

Examples

var dataApi = ctx.Use<IDataApi>();
var employeeId = dataApi.Add("Employee", candidateObj);
ctx.AttachToDataSource("employeeToEdit", employeeId);

Remarks

The ActualData Source's context must be set to "Manual".

BadData(string)

Throw an exception when the data is in invalid state

void BadData(string message)

Parameters

message string

The error message

CommitChanges()

Saves all changes made in this context to the underlying database.

void CommitChanges()

Remarks

Normally, Casewhere will only write to database when the workflow finishes. Calling CommitChanges will force Casewhere to write to database immediately. This is useful when you want to query the data that was created in previous activities. However, using this method inapproriately may impact the workflow's performance e.g. avoid calling this method in a loop.

DeleteDataObject(object)

[Obsolete]
void DeleteDataObject(object dataObjectId)

Parameters

dataObjectId object

DeleteDataObject(string, object)

[Obsolete]
void DeleteDataObject(string dataClassName, object dataObjectId)

Parameters

dataClassName string

dataObjectId object

Emit(string, object)

Emit data with event name

void Emit(string eventName, object data)

Parameters

eventName string

Emit a custom event with the given even name and its data

data object

The event data

Error(string, bool, Exception)

Throw an exception with custom error message.

void Error(string message, bool showErrorMessage = false, Exception ex = null)

Parameters

message string

The error message

showErrorMessage bool

Determines whether Casewhere should show the custom error message or not.

ex Exception

The exception

FindDataObject(string, DataObjectExpression)

[Obsolete]
IList<dynamic> FindDataObject(string dataClassName, DataObjectExpression filterExpressionTemp)

Parameters

dataClassName string

filterExpressionTemp DataObjectExpression

Returns

IList<dynamic>

FindDataObject(string, DataObjectExpression, int, int)

[Obsolete]
DynamicQueryResult FindDataObject(string dataClassName, DataObjectExpression doExpression, int skip = 0, int take = 0)

Parameters

dataClassName string

doExpression DataObjectExpression

skip int

take int

Returns

DynamicQueryResult

ForceEmit(string, object)

Force emit data with event name

void ForceEmit(string eventName, object data)

Parameters

eventName string

Emit a custom event with the given even name and its data

data object

The event data

Get<T>(string)

Get value by name.

T Get<T>(string key)

Parameters

key string

The key.

Returns

T

The variable value.

Type Parameters

T

The variable type.

Examples

// Assuming a workflow has 2 activities like below:
// Activity 1:
ctx.Set("Confirmed", true);
ctx.Set("ConfirmedOption", 5);
// Activity 2:
if (ctx.Get<bool>("Confirmed"))
    DoSomething(ctx.Get<int>("ConfirmedOption"));

Get(string)

Get value object by name.

DynamicDataObject Get(string key)

Parameters

key string

The key.

Returns

DynamicDataObject

The stored object.

GetDataObject(string, string)

[Obsolete]
dynamic GetDataObject(string dataClass, string level = "workflow")

Parameters

dataClass string

level string

Returns

dynamic

GetDataObjectById(string)

[Obsolete]
dynamic GetDataObjectById(string dataObjectId)

Parameters

dataObjectId string

Returns

dynamic

GetDataObjects(string, string)

[Obsolete]
IList<dynamic> GetDataObjects(string dataClassName, string level = "workflow")

Parameters

dataClassName string

level string

Returns

IList<dynamic>

GetTemp<T>(string)

Get value by name in a context workflow. Throw an exception when key is not existed yet.

T GetTemp<T>(string key)

Parameters

key string

The key.

Returns

T

The variable value.

Type Parameters

T

The variable type.

Examples

// Assuming a workflow has 2 activities like below:
// Activity 1:
ctx.SetTemp("Confirmed", true);
ctx.SetTemp("ConfirmedOption", 5);
// Activity 2:
if (ctx.GetTemp<bool>("Confirmed"))
    DoSomething(ctx.GetTemp<int>("ConfirmedOption"));

Has(string)

Determines if a variable exists in the workflow.

bool Has(string key)

Parameters

key string

The key.

Returns

bool

True if the variable exists; otherwise, False.

HasTempKey(string)

Determines if a temporary key exists in the current workflow context.

bool HasTempKey(string key)

Parameters

key string

The key.

Returns

bool

True if the temporary key exists; otherwise, False.

HasValue(string)

Determines if a variable exists in the workflow and it has value e.g. not empty string, not empty array, etc.

bool HasValue(string key)

Parameters

key string

The key.

Returns

bool

True if the variable exists and has value; otherwise, False.

LoadDataObject(string, DataLoadingScope)

[Obsolete]
dynamic LoadDataObject(string dataClassName, DataLoadingScope scope = DataLoadingScope.Workflow)

Parameters

dataClassName string

scope DataLoadingScope

Returns

dynamic

LoadDataObject(string, object)

[Obsolete]
dynamic LoadDataObject(string dataClassName, object localDataObjectId)

Parameters

dataClassName string

localDataObjectId object

Returns

dynamic

LoadDataObjectById(object)

[Obsolete]
dynamic LoadDataObjectById(object dataObjectId)

Parameters

dataObjectId object

Returns

dynamic

LoadDataObjects(string, DataLoadingScope)

[Obsolete]
IList<dynamic> LoadDataObjects(string dataClassName, DataLoadingScope scope = DataLoadingScope.Workflow)

Parameters

dataClassName string

scope DataLoadingScope

Returns

IList<dynamic>

NotFound(string)

Throw an exception when the object is not present.

void NotFound(string message)

Parameters

message string

The error message

Ref(string, string)

Set value for a context reference.

void Ref(string key, string id)

Parameters

key string

The reference key.

id string

The data object id i.e. the value returned from Casewhere.Runtime.DSL.Api.IDataApi.Add(string, object, System.Guid?)

Ref(string)

Get the data object is being referenced.

dynamic Ref(string key)

Parameters

key string

The reference key.

Returns

dynamic

The data object. Null if nothing is found.

SearchDataObjects(string, DataObjectExpression)

[Obsolete]
IList<dynamic> SearchDataObjects(string dataClassName, DataObjectExpression doExpression)

Parameters

dataClassName string

doExpression DataObjectExpression

Returns

IList<dynamic>

SearchDataObjects(string, DataObjectExpression, int, int)

[Obsolete]
DynamicQueryResult SearchDataObjects(string dataClassName, DataObjectExpression doExpression, int skip = 0, int take = 0)

Parameters

dataClassName string

doExpression DataObjectExpression

skip int

take int

Returns

DynamicQueryResult

Set(string, object)

Set value for a context variable.

void Set(string key, object value)

Parameters

key string

The key.

value object

The value.

Examples

// Assuming a workflow has 2 activities like below:
// Activity 1:
ctx.Set("Confirmed", true);
ctx.Set("ConfirmedOption", 5);
// Activity 2:
if (ctx.Get<bool>("Confirmed"))
    DoSomething(ctx.Get<int>("ConfirmedOption"));

Remarks

In general, a context variable can accept anything. However, for storing data objects, we recommend using Casewhere.Runtime.DSL.CompilerContext.IDslCompilerContext.Ref(System.String,System.String) for more efficiency and better overall performance.
You can also declare a variable and bind it to a Form Component using data binding:

SetDataSource(string, params string[])

Set a ActualData Object that is created in Scripted Activity to a Workflow ActualData Source so it can be used in Form Activity.

void SetDataSource(string dataSourceName, params string[] dataObjectIds)

Parameters

dataSourceName string

ActualData Source name.

dataObjectIds string[]

ActualData Object ids.

Examples

var dataApi = ctx.Use<IDataApi>();
var employeeId = dataApi.Add("Employee", candidateObj);
ctx.SetDataSource("employeeToEdit", employeeId);

Remarks

The ActualData Source's context must be set to "Manual".

SetTemp(string, object)

Set temporary value in a context workflow. The value only maintaines in memory and will not be persisted to database.

void SetTemp(string key, object value)

Parameters

key string

The key.

value object

The value.

Examples

// Assuming a workflow has 2 activities like below:
// Activity 1:
ctx.SetTemp("Confirmed", true);
ctx.SetTemp("ConfirmedOption", 5);
// Activity 2:
if (ctx.GetTemp<bool>("Confirmed"))
    DoSomething(ctx.GetTemp<int>("ConfirmedOption"));

Unauthorized(string)

Throw an exception when the user lacking permission

void Unauthorized(string message)

Parameters

message string

The error message

UpdateDataObject(string, object, object)

[Obsolete]
void UpdateDataObject(string dataClassName, object dataObjectId, object data)

Parameters

dataClassName string

dataObjectId object

data object

UpdateDataObject(object, object)

[Obsolete]
void UpdateDataObject(object dataObjectId, object data)

Parameters

dataObjectId object

data object

Use<TApi>()

Factory method to create API objects.

TApi Use<TApi>() where TApi : IDslApi

Returns

TApi

The API object.

Type Parameters

TApi

See Casewhere.Runtime.DSL.Api for supported APIs.

UseIOApi<TIOApi>()

[Obsolete]
TIOApi UseIOApi<TIOApi>() where TIOApi : IIOApi

Returns

TIOApi

Type Parameters

TIOApi