public WorkflowService( IUsersService users ) { _users = users; T = NullLocalizer.Instance; Logger = NullLogger.Instance; SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(_users.ApplicationConnectionString); _wfApp = new WorkflowApplication(new XODB.Workflow.AssignResponsibility()); _wfApp.InstanceStore = store; XName wfHostTypeName = XName.Get("XODB", _users.ApplicationID.ToString()); Dictionary<XName, object> wfScope = new Dictionary<XName, object> { { workflowHostTypePropertyName, wfHostTypeName } }; _wfApp.AddInitialInstanceValues(wfScope); _wfApp.Extensions.Add(new ResponsibilityExtension()); List<XName> variantProperties = new List<XName>() { ResponsibilityExtension.xNS.GetName("CompanyID"), ResponsibilityExtension.xNS.GetName("ContactID") }; store.Promote("Responsibility", variantProperties, null); InstanceHandle handle = store.CreateInstanceHandle(null); var cmd = new CreateWorkflowOwnerCommand { InstanceOwnerMetadata = { {workflowHostTypePropertyName, new InstanceValue(wfHostTypeName)} } }; InstanceOwner owner = store.Execute(handle, cmd, TimeSpan.MaxValue).InstanceOwner; store.DefaultInstanceOwner = owner; handle.Free(); _wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e) { return PersistableIdleAction.Persist; }; _wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { foreach (var item in e.Outputs) { System.Diagnostics.Debug.WriteLine("Variable:{0} has value: {1}", item.Key, item.Value); } } }; var trackingParticipant = new TrackingHelper.DebugTrackingParticipant { TrackingProfile = TrackingHelper.SimpleProfile }; _wfApp.Extensions.Add(trackingParticipant); }
// Creates and configures a new instance of WorkflowApplication private static WorkflowApplication CreateWorkflowApplication(Activity rootActivity, InstanceStore store, XName wfHostTypeName) { WorkflowApplication wfApp = new WorkflowApplication(rootActivity); wfApp.InstanceStore = store; Dictionary<XName, object> wfScope = new Dictionary<XName, object> { { WorkflowHostTypePropertyName, wfHostTypeName } }; // Add the WorkflowHostType value to workflow application so that it stores this data in the instance store when persisted wfApp.AddInitialInstanceValues(wfScope); // This statement is optional (see the comments in AbsoluteDelay.CacheMetadata details for more info). // wfApp.Extensions.Add<DurableTimerExtension>(() => new DurableTimerExtension()); // For demonstration purposes the workflow is unloaded as soon as it is idle (and able to persist) wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs idleArgs) { Console.WriteLine("Workflow unloading..."); return PersistableIdleAction.Unload; }; // Configure some tracing and synchronization for the other WorkflowApplication events wfApp.Unloaded = delegate(WorkflowApplicationEventArgs eargs) { if (!workflowCompleted) { Console.WriteLine("Workflow unloaded"); } else { Console.WriteLine("Workflow unloaded after completing"); } workflowUnloadedEvent.Set(); }; wfApp.Completed = delegate { Console.WriteLine("Workflow completed"); workflowCompleted = true; }; wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs abortArgs) { Console.WriteLine("Workflow aborted (expected in this sample)"); }; return wfApp; }
private static WorkflowApplication CreateWorkflowApplication(WorkflowHandlerBase workflowInstance, WorkflowApplicationCreationPurpose purpose, IDictionary<string, object> parameters) { string version; WorkflowApplication wfApp = null; var workflow = workflowInstance.CreateWorkflowInstance(out version); switch (purpose) { case WorkflowApplicationCreationPurpose.StartNew: Dictionary<string, object> arguments = workflowInstance.CreateParameters(); arguments.Add(STATECONTENT, new WfContent(workflowInstance)); if (parameters != null) foreach (var item in parameters) arguments.Add(item.Key, item.Value); wfApp = new WorkflowApplication(workflow, arguments); workflowInstance.WorkflowDefinitionVersion = version; workflowInstance.WorkflowInstanceGuid = wfApp.Id.ToString(); break; default: wfApp = new WorkflowApplication(workflow); break; } var store = CreateInstanceStore(workflowInstance); Dictionary<XName, object> wfScope = new Dictionary<XName, object> { { GetWorkflowHostTypePropertyName(), GetWorkflowHostTypeName(workflowInstance) } }; wfApp.InstanceStore = store; wfApp.AddInitialInstanceValues(wfScope); wfApp.PersistableIdle = a => { Debug.WriteLine("##WF> Pidle"); return PersistableIdleAction.Unload; }; wfApp.Unloaded = b => { Debug.WriteLine("##WF> Unload"); }; wfApp.Completed = OnWorkflowCompleted; wfApp.Aborted = OnWorkflowAborted; wfApp.OnUnhandledException = HandleError; wfApp.Extensions.Add(new ContentWorkflowExtension() { WorkflowInstancePath = workflowInstance.Path }); return wfApp; }