Basic Plugin
This Plugin implements the most common functions for handling processes, parameters, etc.
The BasicPlugin main actions, conditions, rules and API.
Installation and settings
Add the following namespaces to the section of the using statements:
using OptimaJet.Workflow.Plugins;
Create a plugin object and specify the necessary settings:
var basicPlugin = new BasicPlugin();
// Here are your settings
// basicPlugin.Setting_Mailserver = "smtp.yourserver.com";
// basicPlugin.Setting_MailserverPort = 25;
// basicPlugin.Setting_MailserverFrom = "from@yourserver.com";
// basicPlugin.Setting_MailserverLogin = "login@yourserver.com";
// basicPlugin.Setting_MailserverPassword = "password";
// basicPlugin.Setting_MailserverSsl = true;
// basicPlugin.Setting_MailserverSsl = true;
// basicPlugin.RequestHeaders.add("MyHeader", "headerValue");
// basicPlugin.UsersInRoleAsync += MyUsersInRoleAsync;
// basicPlugin.CheckPredefinedActorAsync += CheckMyPredefinedActorAsync;
// basicPlugin.GetPredefinedIdentitiesAsync += GetMyPredefinedIdentitiesAsync;
// basicPlugin.ApproversInStageAsync += MyApproversInStageAsync;
// basicPlugin.UpdateDocumentStateAsync += UpdateMyDocumentStateAsync;
// Disable compilation of expressions in parameters
// basicPlugin.Setting_DontCompileExpressions = true
Connect the plugin to WorkflowRuntime:
var runtime = new WorkflowRuntime();
...
runtime.WithPlugin(basicPlugin);
Read about Settings.
Cases
SendEmail
To send an email, use action: SendEmail.
You should specify the server and the port associated with your email address account in the parameters or settings.
For example, the following options are available:
- Gmail: Server: smtp.gmail.com; Port: 587
- iCloud: Server: smtp.mail.me.com; Port: 587
- Yahoo: Server: smtp.mail.yahoo.com; Port: 465
HTTPRequest
To send an HTTP request, use action: HTTPRequest.
PredefinedActors
Actors are created on the server with the WithActor/WithActors methods. Those actors have rule = Predefined.
By way of the CheckAsync method, the delegate CheckPredefinedActorAsync are used.
By way of the GetIdentitiesAsync method, the delegate GetPredefinedIdentitiesAsync are used.
To get a list of the predefined actors, the appropriate flag should be enabled in the actors panel in the designer.
CheckPredefinedActorAsync
A delegate, your function should return: true
- if the user meets the specified rule; false
- if
the user doesn't meet the specified rule.
Handler syntax:
async Task<bool> CheckMyPredefinedActorAsync(ProcessInstance processInstance,
WorkflowRuntime runtime, string parameter,
string identityId)
{
// Example: check if the user with the specified Id is a manager
if (parameter == "Manager")
{
return identityId == myManagerId;
}
return false;
}
GetPredefinedIdentitiesAsync
A delegate, your function should return all of the users with the specified rule. Using this function, your can implement the rules both for the security system and for the given document. For example: document author, document manager, controller.
Handler syntax:
async Task<IEnumerable<string>> GetMyPredefinedIdentitiesAsync(ProcessInstance processInstance,
WorkflowRuntime runtime,
string parameter)
{
// Example: return id for all of the users who are managers
if (parameter == "Manager")
{
return new List<string>() {myManagerId1, myManagerId2};
}
return new List<string>();
}
WithActor
basicPlugin.WithActor("Manager");
WithActors
basicPlugin.WithActors(new List<string>() {"Manager", "Director"});
Update document state
To update the document state, use the delegate UpdateDocumentStateAsync in the settings.
UpdateDocumentStateAsync
The delegate that fires the ProcessStatusChanged event in WorkflowRuntime.
Handler syntax:
public static async Task UpdateMyDocumentStateAsync(ProcessInstance processInstance,
string stateName,
string localizedStateName)
{
// here you can update your document state
myDoc.State = stateName;
}
Parallel approval without branches
Implements a parallel approval when a document state can be approved by several users from the list, and all the users from this list must approve a document in this state.
1, 4: Fill approvers
Activity with action from the list:
The lists are filled with users or roles, whose approval is necessary at the current stage.
2, 5: Approve
Transitions with Command trigger.
You can limit the list of users, able to run the command, using the Restrictions.
Adding restrictions with the parameters Actor: Approver; Type: Allow
Read about manage roles
3, 6: Is approved
Transitions with condition from the list:
- IsApproveComplete - it is the preferable choice, OR
- IsApprovedByUsers OR
- IsApprovedByRoles
The transition is performed after the specified users or roles have completed the approval.
7: Approval finished
Activity to be executed after the approval.