- Support for multi-tenant applications. - *TenantId* has been added to processes. When creating a process, one can specify *TenantId* and use its value when working with the process. *TenantId* is stored in the *WorkflowProcessInstance* table in the *TenantId* column. Passing `TenantId` to a process: ```csharp var createInstanceParams = new CreateInstanceParams(schemeCode, processId) { TenantId = "tenantId" }; workflowRuntime.CreateInstance(createInstanceParams); ``` After creating a process with *TenantId* indicated, the access to it inside *Actions*, *Conditions* and *Rules* can be arranged as follows. ```csharp string tenantId = processInstance.TenantId; ``` - For schemes one can specify tags, and then, search for schemes where these tags are indicated. Tags are set in the scheme designer by clicking on the *Process Info* button. Tags are stored in the *WorkflowScheme* table in the *Tags* column. A list of codes for the schemes where the corresponding tags are indicated can be received using the following code: ```csharp List schemeCodes = workflowRuntime.Builder.SearchSchemesByTags(new List {"Tag1", "Tag2"}); ``` The search is performed using an OR expression. - Plugin System and the Basic Plugin. The plugin for WorkflowEngine\.NET is a class that is necessary to implement the `IWorkflowPlugin` interface, and optional to implement the `IWorkflowActionProvider`, `IWorkflowRuleProvider`, `IDesignerParameterFormatProvider`, `IDesignerAutocompleteProvider` interfaces (in any combination). In fact, the plugin is a class that adds functionality to be used when creating process schemes. The plugin connects to WorkflowEngine\.NET when configuring `WorkflowRuntime`. ```csharp WorkflowRuntime workflowRuntime = workflowRuntime.WithPlugin(new BasicPlugin()); ``` Simultaneously, any number of plugins can be connected to WorkflowEngine\.NET. The Basic Plugin `OptimaJet.Workflow.Core.Plugins.BasicPlugin` has been added to the WorkflowEngine\.NET package; it implements the following basic functions: - Actions: - *SendEmail* - sending email. - *CreateProcess* - creating a process from a process. - *HTTPRequest* - sending a request to a third-party web service. - *SetParameter* - setting a process parameter. - Conditions: - *IsProcessFinalized* - checking the finalization of the current process or a process with the Id specified. - *CheckAllSubprocessesCompleted* - checking the finalization (completion) of all the subprocesses. - *CheckParameter* - checking if the parameter is consistent to the given value (so far, only strings are supported). - *IsAprrovedByUsers* - checking if the specified process was processed by all of the listed users. - *IsAprrovedByRoles* - checking if the specified process was processed by all of the listed roles. - *CheckHTTPRequest* - conditional transition based on the result of a request to a third-party web service. - Authorization Rules (Security): - *CheckRole* - checking access to the command for a specific role. **Warning: to perform operations related to the roles checking, `BasicPlugin` must have the delegate handler `basicPlugin.UsersInRoleAsync` installed.** - Now, implicit (that is, not explicitly specified in the scheme) parameters passed when creating a process, executing a command, or setting a new state to a process can be persistent. - When creating a process, use the following code: ```csharp var createInstanceParams = new CreateInstanceParams(schemeCode, processId) .AddPersistentParameter("Parameter1Name", 100) .AddPersistentParameter("ParameterName2", parameterValue); workflowRuntime.CreateInstance(createInstanceParams); ``` - When passing parameters with a command, use the following code: ```csharp WorkflowCommand command = ... command.SetParameter("ParameterName", parameterValue, persist: true); workflowRuntime.ExecuteCommand(command, ... ); ``` - When passing a parameter with a command, use the following code: ```csharp var setStateParams = new SetStateParams(processId,"StateName") .AddPersistentParameter("Parameter1Name", 100) .AddPersistentParameter("ParameterName2", parameterValue); workflowRuntime.SetState(setStateParams); ``` - Support for dynamic parameters has been added. To perform the task, the `DynamicParameter` class, which can be cast into dynamic, has been developed. For example: Creating a parameter: ```csharp var dynamicParameter = new { Name = "Dynamic", ObjectValue = new { Name = "Object", Value = 100 }, ListValue = new List { new {Id = 1, Name = "ObjectInList1"}, new {Id = 2, Name = "ObjectInList2"} } } processInstance.SetParameter("Dynamic", dynamicParameter, ParameterPurpose.Persistence); ``` Getting a parameter: ```csharp var dynamicParameter = processInstance.GetParameter("Dynamic") as dynamic; string name = dynamicParameter.Name; string objectValueName = dynamicParameter.ObjectValue.Name; string firstItemName = (dynamicParameter.ListValue as List).First().Name; ``` - The following aggregating providers are available: `AggregatingActionProvider`, `AggregatingRuleProvider`, `AggregatingDesignerAutocompleteProvider`, `AggregatingDesignerParameterFormatProvider`. An aggregating provider is a provider to which other providers can be added. - `IWorkflowRuleProvider` - supports asynchronous authorization (security) rules. - The scheme code is passed to all methods of all providers. Here are these methods - `IWorkflowActionProvider.GetActions` - `IWorkflowActionProvider.GetConditions` - `IWorkflowActionProvider.IsActionAsync` - `IWorkflowActionProvider.IsConditionAsync` - `IWorkflowRuleProvider.GetRules` - `IWorkflowRuleProvider.IsCheckAsync` - `IWorkflowRuleProvider.IsGetIdentitiesAsync` - `IDesignerParameterFormatProvider.GetFormat` - `IDesignerAutocompleteProvider.GetAutocompleteSuggestions` `string schemeCode` has been added as the last parameter to all these methods. - A unified and correct error output when accessing the Designer API has been added. - Intellisense has been added in the Code Actions (code in schemes) editor. - A new type *TextArea* has been added to the forms where parameter (for Actions, Conditions or rules) values are edited. - In any of the persistence providers, one can optionally turn off the history of transitions and set the history of subprocesses to be written in the history of the main process. For example: ```csharp var provider = new MSSQLProvider(connectionString, writeToHistory:false); var provider = new MSSQLProvider(connectionString, writeSubProcessToRoot:true); ``` ## Update guide to the Workflow Engine 4.1 **The following additional actions must be taken to upgrade to Workflow Engine 4.1:** - Run the following SQL script for all relative databases. - [MSSQL](https://github.com/optimajet/WorkflowEngine.NET/blob/master/Providers/OptimaJet.Workflow.DbPersistence/SQL/update_4_0_to_4_1.sql) - [PostgreSQL](https://github.com/optimajet/WorkflowEngine.NET/blob/master/Providers/OptimaJet.Workflow.PostgreSQL/SQL/update_4_1_to_4_2.sql) - [Oracle](https://github.com/optimajet/WorkflowEngine.NET/blob/master/Providers/OptimaJet.Workflow.Oracle/SQL/update_4_1_to_4_2.sql) - [MySQL](https://github.com/optimajet/WorkflowEngine.NET/tree/master/Providers/OptimaJet.Workflow.MySql/SQL/update_4_0_to_4_1.sql) - Update all files related to the Designer. They are available [here](https://github.com/optimajet/WorkflowEngine.NET/tree/master/Designer). - Update packages or dll to version 4.1. - If the `IWorkflowActionProvider` interface is implemented in your project, the last parameter`string schemeCode` shall be added to the following methods: - `IWorkflowActionProvider.GetActions` - `IWorkflowActionProvider.GetConditions` - `IWorkflowActionProvider.IsActionAsync` - `IWorkflowActionProvider.IsConditionAsync` - If the `IWorkflowRuleProvider` interface is implemented in your project, the following methods shall be added to your provider: ```csharp public Task CheckAsync(ProcessInstance processInstance, WorkflowRuntime runtime, string identityId, string ruleName, string parameter, CancellationToken token) { throw new NotImplementedException(); } public Task> GetIdentitiesAsync(ProcessInstance processInstance, WorkflowRuntime runtime, string ruleName, string parameter, CancellationToken token) { throw new NotImplementedException(); } public bool IsCheckAsync(string ruleName, string schemeCode) { return false; } public bool IsGetIdentitiesAsync(string ruleName, string schemeCode) { return false; } ``` The last parameter `string schemeCode` shall be also added to the following method: - `IWorkflowRuleProvider.GetRules` - If the `IDesignerParameterFormatProvider` interface is implemented in your project, the last parameter `string schemeCode` shall be added to the following method: - `IDesignerParameterFormatProvider.GetFormat` - If the `IDesignerAutocompleteProvider` interface is implemented in your project, the last parameter `string schemeCode` shall be added to the following method: - `IDesignerAutocompleteProvider.GetAutocompleteSuggestions` - **IMPORTANT! Incorrect behavior was fixed when the subprocess was merged in the parent process via the set state of the parent process mechanism. Previously, the parent process parameters were OVERWRITTEN. Now, the parent process parameters won't be changed. Only new parameters from the subprocess will be written to the parent process automatically. The same way the merge via calculating conditions always works. If you consciously exploited this behavior, then the best way to get parameters from the subprocess is to use a property `processInstance.MergedSubprocessParameters` when merge occurs.** - **IMPORTANT! If in your project the Action Provider has changed (after the first initialization) using the method `workflowRuntime.WithActionProvider(...)` replace this code with the following call `workflowRuntime.ClearActionProvider().WithActionProvider(...)`** - **IMPORTANT! If in your project the Rule Provider has changed (after the first initialization) using the method `workflowRuntime.WithRuleProvider(...)` replace this code with the following call `workflowRuntime.ClearRuleProvider().WithRuleProvider(...)`** - **IMPORTANT! If in your project the Designer Autocomplete Provider has changed (after the first initialization) using the method `workflowRuntime.WithDesignerAutocompleteProvider(...)` replace this code with the following call `workflowRuntime.ClearDesignerAutocompleteProvider().WithDesignerAutocompleteProvider(...)`** - **IMPORTANT! If in your project the Designer Parameter Format Provider has changed (after the first initialization) using the method `workflowRuntime.WithDesignerParameterFormatProvider(...)` replace this code with the following call `workflowRuntime.ClearDesignerParameterFormatProvider().WithDesignerParameterFormatProvider(...)`** - It is not necessary but suggested to change the Designer Controller the following way ```csharp public ActionResult API() { ... var res = WorkflowInit.Runtime.DesignerAPI(pars, out bool hasError, filestream, true); var operation = pars["operation"].ToLower(); if (operation == "downloadscheme" && !hasError) return File(Encoding.UTF8.GetBytes(res), "text/xml", "scheme.xml"); else if (operation == "downloadschemebpmn" && !hasError) return File(UTF8Encoding.UTF8.GetBytes(res), "text/xml", "scheme.bpmn"); return Content(res); } ``` See complete controller code - [ASP.NET MVC Core](https://github.com/optimajet/WorkflowEngine.NET/blob/master/Samples/ASP.NET%20Core/MSSQL/WF.Sample/Controllers/DesignerController.cs) - [ASP.NET MVC](https://github.com/optimajet/WorkflowEngine.NET/blob/master/Samples/ASP.NET%20MVC/MSSQL/WF.Sample/Controllers/DesignerController.cs) - [Web Forms](https://github.com/optimajet/WorkflowEngine.NET/blob/master/Samples/ASP.NET%20WebForms/WebFormsMSSQL/WF.Sample/Pages/Designer/WFEDesigner.ashx.cs) - It is not necessary but suggested to pass the scheme code when calling `wfdesigner.create()` method on the Designer page. ```javascript wfdesigner.create(schemecode); ``` See complete view code - [ASP.NET MVC Core](https://github.com/optimajet/WorkflowEngine.NET/blob/master/Samples/ASP.NET%20Core/MSSQL/WF.Sample/Views/Designer/Index.cshtml) - [ASP.NET MVC](https://github.com/optimajet/WorkflowEngine.NET/blob/master/Samples/ASP.NET%20MVC/MSSQL/WF.Sample/Views/Designer/Index.cshtml) - [Web Forms](https://github.com/optimajet/WorkflowEngine.NET/blob/master/Samples/ASP.NET%20WebForms/WebFormsMSSQL/WF.Sample/Pages/Designer/Index.aspx)