Class DslCompilerContext
Namespace: Casewhere.Runtime.DSL.CompilerContext
Assembly: Casewhere.Runtime.dll
public class DslCompilerContext : IDslCompilerContext, IDisposable
Inheritance
Implements
IDslCompilerContext, IDisposable
Inherited Members
object.ToString(), object.Equals(object), object.Equals(object, object), object.ReferenceEquals(object, object), object.GetHashCode(), object.GetType(), object.MemberwiseClone()
Extension Methods
ObjectExtension.ConvertToBsonValue(object), EnumExtensions.DeepClone<DslCompilerContext>(DslCompilerContext)
Constructors
DslCompilerContext(WorkflowContext, ICwRuntimePrincipal, IDataObjectApiService, IDataObjectLoader, IManagedApiFactory, IWorkflowVariablesService, ITempDataService, IWorkflowParametersService)
public DslCompilerContext(WorkflowContext context, ICwRuntimePrincipal cwPrincipal, IDataObjectApiService dataObjectApiService, IDataObjectLoader contextDataObjectService, IManagedApiFactory managedApiFactory, IWorkflowVariablesService workflowVariablesService, ITempDataService tempDataService, IWorkflowParametersService workflowParametersService)
Parameters
context
WorkflowContext
cwPrincipal
ICwRuntimePrincipal
dataObjectApiService
IDataObjectApiService
contextDataObjectService
IDataObjectLoader
managedApiFactory
IManagedApiFactory
workflowVariablesService
IWorkflowVariablesService
tempDataService
ITempDataService
workflowParametersService
IWorkflowParametersService
Properties
Activity
The Activity in Context.
public DslActivity Activity { get; }
Property Value
Case
The Case in Context.
public DslCase Case { get; }
Property Value
FormData
The Form ActualData in context.
public dynamic FormData { get; }
Property Value
dynamic
Input
Workflow input object. If there is multiple objects, it references the first one.
public dynamic Input { get; }
Property Value
dynamic
Inputs
Workflow input objects.
public 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.
public object Output { get; set; }
Property Value
Parameters
The parameters are parsed from the query string of the web trigger request
Then a request for that trigger is: employee/info?isActive=true&from=2020-07-27var 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;
public DynamicDataObject Parameters { get; }
Property Value
DynamicDataObject
RouteParameters
The route parameters are parsed from the url of the web trigger request
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;
public DynamicDataObject RouteParameters { get; }
Property Value
DynamicDataObject
User
The User in context.
public DslUser User { get; }
Property Value
WorkerSite
The WorkerSite in Context
public DslWorkerSite WorkerSite { get; }
Property Value
Workflow
The Workflow in Context.
public DslWorkflow Workflow { get; }
Property Value
WorkflowContext
The context object.
public DslWorkflowContext WorkflowContext { get; }
Property Value
Methods
AddDataObject(string, object)
[Obsolete]
public string AddDataObject(string dataClass, object data)
Parameters
dataClass
string
data
object
Returns
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.
public 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
public void BadData(string message)
Parameters
message
string
The error message
CommitChanges()
Saves all changes made in this context to the underlying database.
public 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]
public void DeleteDataObject(object dataObjectId)
Parameters
dataObjectId
object
DeleteDataObject(string, object)
[Obsolete]
public void DeleteDataObject(string dataClassName, object dataObjectId)
Parameters
dataClassName
string
dataObjectId
object
Dispose()
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
Emit(string, object)
Emit data with event name
public 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.
public 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
~DslCompilerContext()
protected ~DslCompilerContext()
FindDataObject(string, DataObjectExpression)
[Obsolete]
public IList<dynamic> FindDataObject(string dataClassName, DataObjectExpression doExpression)
Parameters
dataClassName
string
doExpression
DataObjectExpression
Returns
IList<dynamic>
FindDataObject(string, DataObjectExpression, int, int)
[Obsolete]
public DynamicQueryResult FindDataObject(string dataClassName, DataObjectExpression doExpression, int skip = 0, int take = 0)
Parameters
dataClassName
string
doExpression
DataObjectExpression
skip
int
take
int
Returns
ForceEmit(string, object)
Force emit data with event name
public 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.
public 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.
public DynamicDataObject Get(string key)
Parameters
key
string
The key.
Returns
DynamicDataObject
The stored object.
GetDataObject(string, string)
[Obsolete]
public dynamic GetDataObject(string dataClassName, string scope = "workflow")
Parameters
dataClassName
string
scope
string
Returns
dynamic
GetDataObjectById(string)
[Obsolete]
public dynamic GetDataObjectById(string dataObjectId)
Parameters
dataObjectId
string
Returns
dynamic
GetDataObjects(string, string)
[Obsolete]
public IList<dynamic> GetDataObjects(string dataClassName, string scope = "workflow")
Parameters
dataClassName
string
scope
string
Returns
IList<dynamic>
GetTemp<T>(string)
Get value by name in a context workflow. Throw an exception when key is not existed yet.
public 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.
public bool Has(string key)
Parameters
key
string
The key.
Returns
True if the variable exists; otherwise, False.
HasTempKey(string)
Determines if a temporary key exists in the current workflow context.
public bool HasTempKey(string key)
Parameters
key
string
The key.
Returns
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.
public bool HasValue(string key)
Parameters
key
string
The key.
Returns
True if the variable exists and has value; otherwise, False.
LoadDataObject(string, object)
public dynamic LoadDataObject(string dataClassName, object localDataObjectId)
Parameters
dataClassName
string
localDataObjectId
object
Returns
dynamic
LoadDataObject(string, DataLoadingScope)
public dynamic LoadDataObject(string dataClassName, DataLoadingScope scope = DataLoadingScope.Workflow)
Parameters
dataClassName
string
scope
DataLoadingScope
Returns
dynamic
LoadDataObjectById(object)
public dynamic LoadDataObjectById(object dataObjectId)
Parameters
dataObjectId
object
Returns
dynamic
LoadDataObjects(string, DataLoadingScope)
public 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.
public void NotFound(string message)
Parameters
message
string
The error message
Ref(string, string)
Set value for a context reference.
public 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.
public dynamic Ref(string key)
Parameters
key
string
The reference key.
Returns
dynamic
The data object. Null if nothing is found.
SearchDataObjects(string, DataObjectExpression)
[Obsolete]
public IList<dynamic> SearchDataObjects(string dataClassName, DataObjectExpression doExpression)
Parameters
dataClassName
string
doExpression
DataObjectExpression
Returns
IList<dynamic>
SearchDataObjects(string, DataObjectExpression, int, int)
[Obsolete]
public DynamicQueryResult SearchDataObjects(string dataClassName, DataObjectExpression doExpression, int skip = 0, int take = 0)
Parameters
dataClassName
string
doExpression
DataObjectExpression
skip
int
take
int
Returns
Set(string, object)
Set value for a context variable.
public 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.
public 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.
public 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
public void Unauthorized(string message)
Parameters
message
string
The error message
UpdateDataObject(object, object)
[Obsolete]
public void UpdateDataObject(object dataObjectId, object data)
Parameters
dataObjectId
object
data
object
UpdateDataObject(string, object, object)
[Obsolete]
public void UpdateDataObject(string dataClassName, object localDataObjectId, object data)
Parameters
dataClassName
string
localDataObjectId
object
data
object
Use<TApi>()
Factory method to create API objects.
public 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]
public TIOApi UseIOApi<TIOApi>() where TIOApi : IIOApi
Returns
TIOApi
Type Parameters
TIOApi