# Interface IWorkflowBuilder OptimaJet.Workflow.Core.Builder.IWorkflowBuilder Converts raw process scheme media into [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/) instances and coordinates scheme loading, parsing, generation, and build-step execution. Namespace: [OptimaJet.Workflow.Core.Builder](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Builder/) ```csharp public interface IWorkflowBuilder ``` ## Type Hierarchy - IWorkflowBuilder Current type - Implementing types - [WorkflowBuilder](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Builder/WorkflowBuilder-TSchemeMedium/) ## Properties `WorkflowRuntime Runtime { get; set; }` Gets or sets the runtime used by this builder. ## Methods `Task CreateNewProcessAsync(Guid processId, string schemeCode, string? tenantId)` Creates a new process instance object for the specified scheme code. If the scheme does not exist, the builder generates and stores it before creating the instance. ### Parameters | Name | Type | Description | | --- | --- | --- | | `processId` | `Guid` | Identifier for the new process instance. | | `schemeCode` | `String` | Code of the scheme to instantiate. | | `tenantId` | `String` | Optional tenant identifier that selects the exact tenant scheme. If not specified, a shared scheme is used. | ### Returns | Type | Description | | --- | --- | | `Task` | A new [ProcessInstance](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessInstance/). | `Task CreateNewSubprocessAsync(Guid processId, ProcessInstance parentProcessInstance, TransitionDefinition startingTransition)` Creates a subprocess process instance for the transition from a parent process. ### Parameters | Name | Type | Description | | --- | --- | --- | | `processId` | `Guid` | Identifier for the new subprocess instance. | | `parentProcessInstance` | `ProcessInstance` | The parent [ProcessInstance](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessInstance/) that starts the subprocess. | | `startingTransition` | `TransitionDefinition` | The [TransitionDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/TransitionDefinition/) that starts the subprocess. | ### Returns | Type | Description | | --- | --- | | `Task` | A new subprocess [ProcessInstance](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessInstance/). | `Task CreateNewProcessSchemeAsync(string schemeCode, string? tenantId = null)` Generates a new process scheme, runs the registered build steps, and stores the resulting scheme. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the scheme to create. | | `tenantId` | `String` | Optional tenant identifier. If not specified, a shared scheme is used. | ### Returns | Type | Description | | --- | --- | | `Task` | The generated [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/). | `Task CreateNewSubprocessSchemeAsync(ProcessDefinition parentProcessScheme, TransitionDefinition startingTransition)` Creates and stores a parsed subprocess scheme for the given parent scheme and transition. ### Parameters | Name | Type | Description | | --- | --- | --- | | `parentProcessScheme` | `ProcessDefinition` | The parent [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/) from which the subprocess is derived. | | `startingTransition` | `TransitionDefinition` | The [TransitionDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/TransitionDefinition/) that starts the subprocess. | ### Returns | Type | Description | | --- | --- | | `Task` | The parsed subprocess [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/). | `Task GetProcessInstanceAsync(Guid processId)` Gets an existing process instance by process identifier. ### Parameters | Name | Type | Description | | --- | --- | --- | | `processId` | `Guid` | Identifier of the process instance to load. | ### Returns | Type | Description | | --- | --- | | `Task` | The loaded [ProcessInstance](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessInstance/). | `Task GetProcessSchemeAsync(Guid schemeId)` Gets a parsed process scheme by scheme identifier. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeId` | `Guid` | Identifier of the scheme to load. | ### Returns | Type | Description | | --- | --- | | `Task` | The loaded [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/). | `void SetCache(IParsedProcessCache cache)` Configures a cache for parsed [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/) instances. ### Parameters | Name | Type | Description | | --- | --- | --- | | `cache` | `IParsedProcessCache` | The [IParsedProcessCache](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Cache/IParsedProcessCache/) used for parsed process definitions. | `void RemoveCache()` Clears and disables the parsed process definition cache. `Task GetProcessSchemeAsync(string schemeCode, string? tenantId = null)` Gets a process scheme by code and tenant, creating it if it does not exist. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the scheme. | | `tenantId` | `String` | Optional tenant identifier. If not specified, a shared scheme is used. | ### Returns | Type | Description | | --- | --- | | `Task` | The requested [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/). If missing, a new scheme is generated, stored, and returned. | `Task SetSchemeIsObsoleteAsync(string schemeCode, string? tenantId = null)` Marks schemes with the specified code as obsolete. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the scheme. | | `tenantId` | `String` | Tenant id of the scheme. If null, marks schemes with the specified code obsolete in all tenants. | ### Returns | Type | Description | | --- | --- | | `Task` | | `Task GetProcessSchemeForDesignerAsync(string code, string? tenantId = null)` Gets a parsed process scheme from the persistence store by code for designer operations. ### Parameters | Name | Type | Description | | --- | --- | --- | | `code` | `String` | Code of the scheme. | | `tenantId` | `String` | Optional tenant identifier. | ### Returns | Type | Description | | --- | --- | | `Task` | The loaded [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/). | `Task<(bool success, List? errors, string? failedStep)> SaveProcessSchemeAsync(string schemeCode, ProcessDefinition pd)` Runs the registered build steps on a clone of the process definition to validate it and determine its inline scheme dependencies, then saves the supplied definition when validation succeeds. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the scheme. | | `pd` | `ProcessDefinition` | The parsed [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/) to save. | ### Returns | Type | Description | | --- | --- | | `Task` | A tuple containing: `success` is [true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) when validation succeeds; `errors` contains validation messages when validation fails; `failedStep` contains the name of the build step that failed, if any. | `ProcessDefinition Parse(string scheme, SchemeParsingType schemeParsingType = SchemeParsingType.Strict)` Parses a raw scheme string into a [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/). ### Parameters | Name | Type | Description | | --- | --- | --- | | `scheme` | `String` | Raw scheme content to parse. | | `schemeParsingType` | `SchemeParsingType` | Parse mode. Use [SchemeParsingType.Soft](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Builder/SchemeParsingType/) only for relaxed validation. | ### Returns | Type | Description | | --- | --- | | `ProcessDefinition` | The parsed [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/). | `string Serialize(ProcessDefinition processDefinition)` Serializes a process definition into raw scheme text. ### Parameters | Name | Type | Description | | --- | --- | --- | | `processDefinition` | `ProcessDefinition` | The [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/) to serialize. | ### Returns | Type | Description | | --- | --- | | `String` | String representation of the unparsed scheme. | `void AddBuildStep(int order, BuildStepPosition buildStepPosition, BuildStep step)` Adds a build step at the specified position and order. ### Parameters | Name | Type | Description | | --- | --- | --- | | `order` | `Int32` | Order value used to sort build-step execution. | | `buildStepPosition` | `BuildStepPosition` | The [BuildStepPosition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Builder/BuildStepPosition/) relative to system steps. | | `step` | `BuildStep` | The [BuildStep](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Builder/BuildStep/) to add. | `void AddSystemBuildStepAtTheEnd(BuildStep step, int startOrder = 0, int endOrder = 1000)` Adds a system build step after the highest existing system step in the specified search range. ### Parameters | Name | Type | Description | | --- | --- | --- | | `step` | `BuildStep` | The [BuildStep](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Builder/BuildStep/) to add. | | `startOrder` | `Int32` | The order used when the search range contains no existing system steps. | | `endOrder` | `Int32` | The exclusive upper bound of the range searched for existing system steps. | `void AddBuildStepAtTheEnd(BuildStep step)` Adds a build step after all existing build steps. ### Parameters | Name | Type | Description | | --- | --- | --- | | `step` | `BuildStep` | The [BuildStep](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Builder/BuildStep/) to add. | `Task GenerateProcessDefinitionAsync(string schemeCode, string? tenantId = null)` Generates and parses a process definition without reading or writing persistence, using the cache, or executing build steps. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the scheme to generate. | | `tenantId` | `String` | Optional tenant identifier. | ### Returns | Type | Description | | --- | --- | | `Task` | The generated [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/). | `bool ContainsBuildStep(string name)` Determines whether a build step with the specified name is already registered. ### Parameters | Name | Type | Description | | --- | --- | --- | | `name` | `String` | Name of the build step to check. | ### Returns | Type | Description | | --- | --- | | `Boolean` | [true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) when a build step with this name exists. | `Task> GetInlinedSchemeCodesAsync(string? tenantId = null)` Gets codes of schemes that may be inlined by other schemes. ### Parameters | Name | Type | Description | | --- | --- | --- | | `tenantId` | `String` | Optional tenant identifier. If specified, both shared and tenant-specific schemes are returned. If omitted, only shared schemes are returned. | ### Returns | Type | Description | | --- | --- | | `Task` | The list of scheme codes. | `Task> GetInlinedSchemeParametersAsync(string? tenantId = null)` Gets inlined scheme parameters by scheme code. ### Parameters | Name | Type | Description | | --- | --- | --- | | `tenantId` | `String` | Optional tenant identifier. If specified, both shared and tenant-specific schemes are resolved. If omitted, only shared schemes are included. | ### Returns | Type | Description | | --- | --- | | `Task` | A dictionary keyed by scheme code containing non-system parameters for each inlined scheme. | `Task> GetRelatedByInliningSchemeCodesAsync(string schemeCode, string? tenantId = null)` Gets scheme codes that currently inline the specified scheme. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the inlined scheme. | | `tenantId` | `String` | Tenant id of the parent scheme. If null, searches in all tenants and shared schemes. | ### Returns | Type | Description | | --- | --- | | `Task` | Scheme codes that inline the specified scheme. | `Task RemoveSchemeTagsAsync(string schemeCode, IEnumerable tags)` Removes tags from the shared scheme with the specified code. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the shared scheme. | | `tags` | `IEnumerable` | Tags to remove. | ### Returns | Type | Description | | --- | --- | | `Task` | | `Task RemoveSchemeTagsAsync(string schemeCode, string? tenantId, IEnumerable tags)` Removes tags from a scheme in the exact tenant scope. If tenantId is null, updates only the shared scheme. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the scheme. | | `tenantId` | `String` | Tenant identifier or `null` for shared scope. | | `tags` | `IEnumerable` | Tags to remove. | ### Returns | Type | Description | | --- | --- | | `Task` | | `Task SetSchemeTagsAsync(string schemeCode, IEnumerable tags)` Replaces tags for the shared scheme with the specified code. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the shared scheme. | | `tags` | `IEnumerable` | Tags to set. | ### Returns | Type | Description | | --- | --- | | `Task` | | `Task SetSchemeTagsAsync(string schemeCode, string? tenantId, IEnumerable tags)` Replaces tags for a scheme in the exact tenant scope. If tenantId is null, updates only the shared scheme. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the scheme. | | `tenantId` | `String` | Tenant identifier or `null` for shared scope. | | `tags` | `IEnumerable` | Tags to set. | ### Returns | Type | Description | | --- | --- | | `Task` | | `Task> SearchSchemesByTagsAsync(IEnumerable? tags)` Gets shared scheme codes matching a tag list. ### Parameters | Name | Type | Description | | --- | --- | --- | | `tags` | `IEnumerable` | Optional tags to filter schemes. If `null`, returns all shared scheme codes. | ### Returns | Type | Description | | --- | --- | | `Task` | Codes of matching shared schemes. | `Task> SearchSchemesByTagsAsync(string? tenantId, IEnumerable? tags)` Gets scheme codes in a tenant scope matching a tag list. ### Parameters | Name | Type | Description | | --- | --- | --- | | `tenantId` | `String` | Tenant identifier. If `null`, only shared schemes are searched. | | `tags` | `IEnumerable` | Optional tags to filter schemes. If `null`, all codes in scope are returned. | ### Returns | Type | Description | | --- | --- | | `Task` | Codes of matching schemes in the specified scope. | `Task AddSchemeTagsAsync(string schemeCode, IEnumerable tags)` Adds tags to the shared scheme with the specified code. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the shared scheme. | | `tags` | `IEnumerable` | Tags to add. | ### Returns | Type | Description | | --- | --- | | `Task` | | `Task AddSchemeTagsAsync(string schemeCode, string? tenantId, IEnumerable tags)` Adds tags to a scheme in the exact tenant scope. If tenantId is null, updates only the shared scheme. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeCode` | `String` | Code of the scheme. | | `tenantId` | `String` | Tenant identifier or `null` for shared scope. | | `tags` | `IEnumerable` | Tags to add. | ### Returns | Type | Description | | --- | --- | | `Task` | | `Task<(List? codes, List? errors, string? failedStep)> GetInlineSchemesAsync(ProcessDefinition pd)` Runs the registered build steps on a clone of the process definition and gets the codes represented by the resulting inlined activities. ### Parameters | Name | Type | Description | | --- | --- | --- | | `pd` | `ProcessDefinition` | The [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/) to inspect. | ### Returns | Type | Description | | --- | --- | | `Task` | A tuple containing: `codes` list of inlined scheme codes, `errors` validation errors when build steps fail, and `failedStep` the failing build step name. | `[Obsolete("Do not use this API. It was used only by the deprecated Assignment plugin and will be removed soon.")] Task UpsertProcessInstanceScheme(ProcessDefinition processDefinition)` Obsolete Executes build steps and upserts the parsed scheme into the persistence store. ### Parameters | Name | Type | Description | | --- | --- | --- | | `processDefinition` | `ProcessDefinition` | The [ProcessDefinition](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Model/ProcessDefinition/) to save. | ### Returns | Type | Description | | --- | --- | | `Task` | | `[Obsolete("Do not use this API. It was used only by the deprecated Assignment plugin and will be removed soon.")] void RemoveSchemeFromCache(Guid schemeId)` Obsolete Removes a parsed process definition from the cache by scheme identifier. ### Parameters | Name | Type | Description | | --- | --- | --- | | `schemeId` | `Guid` | Identifier of the scheme cache entry to remove. | [Previous InlineSchemesStep](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Builder/InlineSchemesStep/) [Next SchemeInlineUtils](https://api.workflowengine.io/core/OptimaJet.Workflow.Core.Builder/SchemeInlineUtils/)