You can create new Workflow Instances from MVC or WPF apps, or from a BP service host. Start by adding to your project a reference to the Workflow Client Integration assembly, which is in the A4DN Maintenance path:
<Reference Include="A4DN.WF.BOS.ClientIntegration">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(A4DNMaintenanceHintPath)A4DN.WF.BOS.ClientIntegration.dll</HintPath>
</Reference>
This assembly provides two attributes, an interface, and a utility method that will be used to create a new Workflow Instance.
- [WF_WorkflowInstance("MyWorkflow")] is added to a class that contains properties which correspond to the workflow's custom fields. "MyWorkflow" is the namespace of the Workflow.
- [WF_WorkflowField] is added to each property. The property name should match the custom field name, but if it doesn't the field name can be specified in the attribute.
- WF_IWorkflowInstanceData is an interface that the class must implement. There are no properties or methods to add; this is used as a hook for extension methods.
- this.am_AddToWorkQueue() is an extension method that you call to create the new Workflow Instance.
Here's a simple example of a utility class that's only used for workflow:
[WF_WorkflowInstance("TrialConfirmation")] public class DemoConfirmation : WF_IWorkflowInstanceData { [WF_WorkflowField] public string Token { get; set; } [WF_WorkflowField] public string Email { get; set; } [WF_WorkflowField] public string IPAddress { get; set; } [WF_WorkflowField] public string UserAgent { get; set; } [WF_WorkflowField] public string Referer { get; set; } }
Another class can use this to create a new instance for the TrialConfirmation workflow:
new DemoConfirmation { Token = token, Email = email, IPAddress = HttpContext.Current.Request.UserHostAddress, UserAgent = HttpContext.Current.Request.UserAgent, Referer = HttpContext.Current.Request.UrlReferrer == null ? "" : HttpContext.Current.Request.UrlReferrer.OriginalString }.am_AddToWorkQueue(instanceName: "Trial Registration Confirmation for " + email);
The DemoConfirmation object is being created, its am_AddToWorkQueue() method is called, and then the object is destroyed. When used this way, there's no need to hold onto the object that's being passed to Workflow. The instanceName argument is used to set the text that will be displayed in the Workflow Instance search results grid; it can be set per-instance, or it can be set as a default in the [WF_WorkflowInstance] attribute.
Another typical approach is to add the workflow attributes and interface to an existing data model class, such as a data entity. That will give the model an am_AddToWorkQueue() method which can be called to add itself to a workflow. The attributes are designed so that they can be added to any class without interfering with the class or forcing any particular naming convention on the properties.