static void Main(string[] args) { var neoConnectionString = "http://localhost:7474/db/data"; var neoConnection = new GraphClient(new Uri(neoConnectionString)); //setup persistence var storeId = new Guid("c068fd97-117e-4bac-b93a-613d7baaa088"); Console.WriteLine("Store ID: " + storeId); var store = new Neo4jInstanceStore(neoConnection, storeId); var instanceId = CreateAndStartWorkflowInstance(store, new TestWorkflow2()); Console.WriteLine("Instance ID: " + instanceId); store.Dispose(); //resume var bookmarkName = "OrderNameBookmark"; var name = Console.ReadLine(); var store2 = new Neo4jInstanceStore(neoConnection, storeId); ResumeWorkflowInstance(store2, new TestWorkflow2(), instanceId, bookmarkName, name); store2.Dispose(); Console.ReadLine(); }
private WorkflowStatus runWorkflow(string workflowName, IDictionary <string, object> parameters, Guid?workflowInstanceId, string bookmarkName, bool response) { Activity workflowDefinition = GetWorkflow(workflowName); using (var store = new Neo4jInstanceStore(client, workflowStoreId)) { WorkflowStatusEnum status = WorkflowStatusEnum.InProgress; string bookmark = null; bool?result = null; var instanceUnloaded = new AutoResetEvent(false); WorkflowApplication app; if (parameters == null) { app = new WorkflowApplication(workflowDefinition); } else { // Only pass in parameters that the appear in the workflow var parametersDefinedInThisWorkflow = getAvailableSettingsForWorkflow(workflowDefinition); var applicableParameters = parameters .Where(a => parametersDefinedInThisWorkflow.Contains(a.Key)) .ToDictionary(a => a.Key, a => a.Value); app = new WorkflowApplication(workflowDefinition, applicableParameters); } app.InstanceStore = store; app.PersistableIdle = (e) => { return(PersistableIdleAction.Unload); }; app.Completed = (arg) => { Console.WriteLine("Workflow has Completed in the {0} state.", arg.CompletionState); status = WorkflowStatusEnum.Completed; // If the result of the workflow is a boolean, use that value, otherwise the workflow must be so // simple that it doesn't return anything, so we'll set the result to true. if (arg.Outputs.ContainsKey("Result") && arg.Outputs["Result"] is bool) { result = (bool)arg.Outputs["Result"]; } else { result = true; } }; app.Unloaded = (arg) => { Console.WriteLine("Workflow has Unloaded."); instanceUnloaded.Set(); }; app.Idle = (idle) => { bookmark = idle.Bookmarks.Select(a => a.BookmarkName).FirstOrDefault(); Console.WriteLine("Workflow has Idled."); }; if (workflowInstanceId.HasValue) { app.Load(workflowInstanceId.Value); app.ResumeBookmark(bookmarkName, response); } else { workflowInstanceId = app.Id; app.Run(); Console.WriteLine("Started instance #" + workflowInstanceId.Value); } // Wait for the workflow to complete before returning the data instanceUnloaded.WaitOne(); return(new WorkflowStatus { InstanceId = workflowInstanceId.Value, Status = status, Bookmark = bookmark, Result = result }); } }