private void btnBegin_Click(object sender, EventArgs e) { // Sql workflow persistence SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore("Server=.;Initial Catalog=MAPOADb;uid=sa;pwd=a5576279;"); // Create a workflow application // Pass the bookmark name as parameter to the DemoActivity activity WorkflowApplication workflowApplication = new WorkflowApplication( new WFStateMachineActivity(), new Dictionary <string, object>() { { "InBookmarkName", this.textBoxBookmark.Text } }); workflowApplication.InstanceStore = store; // This method must be used to serialize data workflowApplication.PersistableIdle = a => { return(PersistableIdleAction.Unload); }; workflowApplication.Idle += OnWorkflowAppIdle; workflowApplication.OnUnhandledException += OnWorkflowException; workflowApplication.Unloaded = a => { Console.WriteLine("workflow unload..."); }; workflowApplication.Aborted = a => { Console.WriteLine("workflow abort"); }; workflowApplication.Run(); this.textBoxGuid.Text = workflowApplication.Id.ToString(); WFApplication = workflowApplication; }
private static void WakeupReadyInstances() { var store = new SqlWorkflowInstanceStore(ConfigurationManager.GetWfStoreConnectionString()); // Create an InstanceStore owner that is associated with the workflow type InstanceHandle ownerHandle = CreateInstanceStoreOwner(store, WfHostTypeName); // This loop handles re-loading workflows that have been unloaded due to durable timers while (true) { // Wait for a timer registered by the delay to expire and the workflow instance to become "runnable" again WaitForRunnableInstance(store, ownerHandle); // Create a new WorkflowApplication instance to host the re-loaded workflow var wfApp = CreateWorkflowApplication(new HandleEmailActivity(), store, WfHostTypeName); try { // Re-load the runnable workflow instance and run it wfApp.LoadRunnableInstance(); wfApp.Run(); Thread.Sleep(3000); // Give it some time to start before starting another one } catch (InstanceNotReadyException) { Console.WriteLine("Handled expected InstanceNotReadyException, retrying..."); } } }
private void btnContinue_Click(object sender, EventArgs e) { #region Old version // Continue the workflow and pass a bookmark name and amount of the funding application // Pass those data direct to Wait4InputDataCodeActivity.InputDataCallback method //WFApplication.ResumeBookmark(this.textBoxBookmark.Text, int.Parse(this.textBoxContinue.Text)); #endregion // Get the data info from database and continues the process // Sql workflow persistence SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore("Server=.;Initial Catalog=MAPOADb;uid=sa;pwd=a5576279;"); // Create a workflow application WorkflowApplication workflowApplication = new WorkflowApplication(new WFStateMachineActivity()); workflowApplication.InstanceStore = store; // This method must be used to serialize data workflowApplication.PersistableIdle = a => { return(PersistableIdleAction.Unload); }; workflowApplication.Idle += OnWorkflowAppIdle; workflowApplication.OnUnhandledException += OnWorkflowException; workflowApplication.Unloaded = a => { Console.WriteLine("workflow unload..."); }; workflowApplication.Aborted = a => { Console.WriteLine("workflow abort"); }; // Load the instance status from database workflowApplication.Load(Guid.Parse(this.textBoxGuid.Text)); // Continue the workflow and pass a bookmark name and amount of the funding application // Pass those data direct to Wait4InputDataCodeActivity.InputDataCallback method workflowApplication.ResumeBookmark(this.textBoxBookmark.Text, int.Parse(this.textBoxContinue.Text)); }
public ApplicationBuilder(string storeConnectionString) { // Initialize the store and configure it so that it can be used for // multiple WorkflowApplication instances. _store = new SqlWorkflowInstanceStore(storeConnectionString); WorkflowApplication.CreateDefaultInstanceOwner(_store, null, WorkflowIdentityFilter.Any); }
public static void RunReviewApply(Guid id, ReviewUseCarApplyForm Form) { SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(@"server=.\SQLEXPRESS;database=aspnetdb;uid=sa;pwd=123456"); WorkflowApplication application2 = new WorkflowApplication(new UseCarApply()); application2.InstanceStore = instanceStore; application2.Completed = (workflowApplicationCompletedEventArgs) => { Console.WriteLine("\nWorkflowApplication has Completed in the {0} state.", workflowApplicationCompletedEventArgs.CompletionState); instanceUnloaded.Set(); }; application2.PersistableIdle = (e) => { instanceUnloaded.Set(); return(PersistableIdleAction.Unload); }; application2.Unloaded = (workflowApplicationEventArgs) => { Console.WriteLine("WorkflowApplication has Unloaded\n"); instanceUnloaded.Set(); }; application2.Load(id); application2.ResumeBookmark("WaitForExamine", Form); instanceUnloaded.WaitOne(); Console.ReadLine(); }
internal static InstanceStore InitializeWorkflowInstanceStore() { //return new XmlWorkflowInstanceStore(); string connectionString = ConfigurationManager.ConnectionStrings["wf"].ConnectionString; var store = new SqlWorkflowInstanceStore(connectionString); //TODO: выставить после отладки //store.InstanceEncodingOption = InstanceEncodingOption.GZip; // про настройки тут: https://msdn.microsoft.com/ru-ru/library/ee395770(v=vs.110).aspx store.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry; store.InstanceCompletionAction = InstanceCompletionAction.DeleteAll; store.HostLockRenewalPeriod = new TimeSpan(0, 0, 5); store.RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 10); InstanceHandle handle = null; try { handle = store.CreateInstanceHandle(); var view = store.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(5)); store.DefaultInstanceOwner = view.InstanceOwner; } finally { if (handle != null) { handle.Free(); } } return(store); }
public void Run() { wfHostTypeName = XName.Get("Version" + Guid.NewGuid().ToString(), typeof(Workflow1).FullName); this.instanceStore = SetupSqlpersistenceStore(); this.instanceHandle = CreateInstanceStoreOwnerHandle( instanceStore, wfHostTypeName); WorkflowApplication wfApp = CreateWorkflowApp(); wfApp.Run(); while (true) { this.waitHandler.WaitOne(); if (completed) { break; } WaitForRunnableInstance(this.instanceHandle); wfApp = CreateWorkflowApp(); try { wfApp.LoadRunnableInstance(); waitHandler.Reset(); wfApp.Run(); } catch (InstanceNotReadyException) { Console.WriteLine("Handled expected InstanceNotReadyException, retrying..."); } } Console.WriteLine("workflow completed."); }
private void cmdUpdateInstance_Click(object sender, RoutedEventArgs e) { SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(); instanceStore.ConnectionString = @"Data Source=(LocalDB)\v11.0;Initial Catalog=WFPersist;Integrated Security=True"; WorkflowApplicationInstance wfInstance = WorkflowApplication.GetInstance(new Guid(txtUpdateInstance.Text), instanceStore); DataContractSerializer s = new DataContractSerializer(typeof(DynamicUpdateMap)); using (FileStream fs = File.Open(txtUpdateMapFile.Text, FileMode.Open)) { updateMap = s.ReadObject(fs) as DynamicUpdateMap; } var wfApp = new WorkflowApplication(new MovieRentalProcess(), new WorkflowIdentity { Name = "v2MovieRentalProcess", Version = new System.Version(2, 0, 0, 0) }); IList <ActivityBlockingUpdate> act; if (wfInstance.CanApplyUpdate(updateMap, out act)) { wfApp.Load(wfInstance, updateMap); wfApp.Unload(); } }
private static SqlWorkflowInstanceStore CreateInstanceStore(WorkflowHandlerBase workflowInstance, out InstanceHandle ownerHandle) { try { //WriteDebug("CreateInstanceStore: " + workflowInstance.WorkflowInstanceGuid + ", nodeId: " + workflowInstance.Id); var store = new SqlWorkflowInstanceStore(ConnectionString); ownerHandle = store.CreateInstanceHandle(); var wfHostTypeName = GetWorkflowHostTypeName(workflowInstance); var WorkflowHostTypePropertyName = GetWorkflowHostTypePropertyName(); var ownerCommand = new CreateWorkflowOwnerCommand() { InstanceOwnerMetadata = { { WorkflowHostTypePropertyName, new InstanceValue(wfHostTypeName) } } }; var owner = store.Execute(ownerHandle, ownerCommand, TimeSpan.FromSeconds(30)).InstanceOwner; ownerHandle.Free(); store.DefaultInstanceOwner = owner; return(store); } catch (Exception e) { WriteError("CreateInstanceStore", e); throw; } }
private static WorkflowApplication GetApp() { // Create a new workflow Activity workflow1 = new Workflow1(); // Create a new host WorkflowApplication app = new WorkflowApplication(workflow1); SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings["Demos"].ConnectionString); // Delete all when workflow instance is terminated // store.InstanceCompletionAction = InstanceCompletionAction.DeleteAll; // Pomote extensions properties (InstancePromotedPropertiesTable) store.Promote("MyExtension", MyExtension.GetValuesToPromote(), null); app.InstanceStore = store; // Add extension MyExtension extension = new MyExtension(); app.Extensions.Add(extension); app.PersistableIdle = PersistableIdle; app.Unloaded = Unloaded; return(app); }
public static void RunArrangeDrawOutFrom(ArrangeDrawOutFrom form) { SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(@"server=.\SQLEXPRESS;database=aspnetdb;uid=sa;pwd=123456"); WorkflowApplication application1 = new WorkflowApplication(new UseCarApply()); application1.InstanceStore = instanceStore; application1.Completed = (workflowApplicationCompletedEventArgs) => { Console.WriteLine("\nWorkflowApplication has Completed in the {0} state.", workflowApplicationCompletedEventArgs.CompletionState); }; application1.PersistableIdle = (e) => { instanceUnloaded.Set(); return(PersistableIdleAction.Unload); }; application1.Unloaded = (workflowApplicationEventArgs) => { Console.WriteLine("WorkflowApplication has Unloaded\n"); instanceUnloaded.Set(); }; application1.Load(form.WFID); application1.ResumeBookmark("WaitArrangeDrawOut", form); instanceUnloaded.WaitOne(); Console.ReadLine(); }
/// <summary> /// 创建工作流 /// </summary> /// <param name="flow"></param> /// <returns></returns> public static Guid CreateWorkflow(string OrderOID) { InstanceHandle instanceHandle = InstanceStoreObj.CreateInstanceHandle(); InstanceView view = InstanceStoreObj.Execute(instanceHandle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30)); InstanceStoreObj.DefaultInstanceOwner = view.InstanceOwner; IDictionary <string, object> input = new Dictionary <string, object> { { "OrderOID", OrderOID } }; //WorkflowApplication application = new WorkflowApplication(new AuthFlow(),input); WorkflowApplication application = new WorkflowApplication(new WorkflowService.OrderFlow.OrderFlow(), input); application.InstanceStore = InstanceStoreObj; application.PersistableIdle = (e) => { return(PersistableIdleAction.Unload); }; application.Unloaded = (e) => { //PersistableIdleAction.Unload; }; application.Run(); var deleteOwnerCmd = new DeleteWorkflowOwnerCommand(); //InstanceStoreObj.Execute(instanceHandle, deleteOwnerCmd, TimeSpan.FromSeconds(30)); InstanceStoreObj = null; return(application.Id); }
static void Main(string[] args) { var connStr = @"Data Source=.\sqlexpress;Initial Catalog=WorkflowInstanceStore;Integrated Security=True;Pooling=False"; SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(connStr); Workflow1 w = new Workflow1(); //instanceStore. //IDictionary<string, object> xx=WorkflowInvoker.Invoke(new Workflow1()); //ICollection<string> keys=xx.Keys; WorkflowApplication a = new WorkflowApplication(w); a.InstanceStore = instanceStore; a.GetBookmarks(); //a.ResumeBookmark("Final State", new object()); a.Run(); //a.ResumeBookmark( //a.Persist(); //a.Unload(); //Guid id = a.Id; //WorkflowApplication b = new WorkflowApplication(w); //b.InstanceStore = instanceStore; //b.Load(id); //WorkflowApplication a=new WorkflowApplication( }
private void btnStart_Click(object sender, EventArgs e) { SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(connectionString); WorkflowApplication wfApp = new WorkflowApplication( new StateMoneyActivity1xaml(), new Dictionary <string, object>() { { "InBookMarkName", this.txtBookMarkName.Text } }); wfApp.InstanceStore = store; wfApp.Idle += OnWfAppIdel; wfApp.OnUnhandledException += OnWfAppException; wfApp.Unloaded = a => { Console.WriteLine("工作流卸载了..."); }; wfApp.Aborted = a => { Console.WriteLine("Aborted"); }; //启用序列化必须使用此方法。 wfApp.PersistableIdle = a => { return(PersistableIdleAction.Unload); }; wfApp.Run();//启动工作流 this.txtAppId.Text = wfApp.Id.ToString(); WFApp = wfApp; //wfApp.ResumeBookmark(); }
/// <summary> /// 重新启动工作流,是审核过程中保存审核结果的必要流程 /// </summary> /// <param name="meeting">传入一个Meeting对象,主要是取里面的InstanceID和改变Status</param> public static void RunInstance(Model.Meeting meeting) { SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(connectionString); IDictionary <string, object> input = new Dictionary <string, object>() { { "Request", meeting } }; WorkflowApplication application1 = new WorkflowApplication(new MeetingApply()); application1.InstanceStore = instanceStore; application1.Completed = (workflowComplete) => { }; application1.Unloaded = (workflowUnloaded) => { instanceUnloaded.Set(); }; application1.PersistableIdle = (e) => { instanceUnloaded.Set(); return(PersistableIdleAction.Unload); }; application1.Load(meeting.WFID); application1.ResumeBookmark("MeetingApply", meeting.MeetingStatus); //instanceUnloaded.WaitOne(); }
/// <summary> /// /// </summary> /// <param name="definitionPath"></param> /// <param name="mapPath"></param> /// <param name="connectionString"></param> /// <param name="instanceId"></param> public static void Update(String definitionPath, String mapPath, String connectionString, Guid instanceId) { // Store SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore { ConnectionString = connectionString }; // Instance to update WorkflowApplicationInstance wfInstance = WorkflowApplication.GetInstance(instanceId, instanceStore); // Load update map DynamicUpdateMap updateMap; DataContractSerializer s = new DataContractSerializer(typeof(DynamicUpdateMap)); using (FileStream fs = File.Open(mapPath, FileMode.Open)) { updateMap = s.ReadObject(fs) as DynamicUpdateMap; } // if (updateMap == null) return; // Throw WorkflowApplication wfApp = new WorkflowApplication(LoadActivityBuilder(definitionPath).Implementation); IList <ActivityBlockingUpdate> act; if (wfInstance.CanApplyUpdate(updateMap, out act)) { wfApp.Load(wfInstance, updateMap); wfApp.Unload(); } }
static RegistrationVerification() { // ReSharper disable AssignNullToNotNullAttribute WorkflowHostTypeName = XName.Get(typeof(TActivity).FullName, "MVCRegistration"); // ReSharper restore AssignNullToNotNullAttribute var instanceDetectionSetting = ConfigurationManager.AppSettings["InstanceDetectionPeriod"]; if (!string.IsNullOrWhiteSpace(instanceDetectionSetting)) { if (!int.TryParse(instanceDetectionSetting, out InstanceDetectionPeriod)) { throw new InvalidOperationException( "Invalid InstanceDetectionPeriod in configuration. Must be a number in seconds"); } } InstanceStore = new SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings["InstanceStore"].ConnectionString) { RunnableInstancesDetectionPeriod = TimeSpan.FromSeconds(InstanceDetectionPeriod) }; RegistrationPeristenceParticipant.Promote(InstanceStore); CreateInstanceStoreOwner(); }
private static InstanceStore CreateInstanceStore() { var connectionString = ConfigurationManager.ConnectionStrings["WorkflowDb"].ConnectionString; var store = new SqlWorkflowInstanceStore(connectionString); return(store); }
/// <summary> /// Drain-stops the workflow host by waiting for the /// workflows complete /// </summary> public void Stop(TimeSpan timeout) { lock (syncRoot) { if (stopRequested) { throw new InvalidOperationException(); } stopRequested = true; } // Wait until all workflows complete while (true) { lock (syncRoot) { if (workflows.Count == 0) { break; } } Thread.Sleep(100); // TODO: use constant } graywulfLogger = null; workflowInstanceStore = null; stopRequested = false; }
//创建工作流 并持久化到数据库中 public static WorkflowApplication CreateWorkflowApp(Activity activity, Dictionary <string, object> dictParm) { AutoResetEvent atuoResetEvent = new AutoResetEvent(false); WorkflowApplication wfApp; if (dictParm == null) { wfApp = new WorkflowApplication(activity);//根据指定的工作流 创建WorkflowAppdu对象 } else { wfApp = new WorkflowApplication(activity, dictParm); } wfApp.Idle += a =>//当工作流停下来的时候,执行此事件响应方法 { Console.WriteLine("工作流停下来了。。"); LogHelper.WriteLog("工作流停下来了"); }; //当咱们工作流停顿下来的时候,进行什么操作。如果返回是Unload。那么就卸载当前 //工作流实例,持久化到数据库里面去。 wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e2) { Console.WriteLine("工作卸载进行持久化,书签被创建时候就会执行序列化到数据库里面去。"); Common.LogHelper.WriteLog("工作卸载进行持久化"); return(PersistableIdleAction.Unload); }; wfApp.Unloaded += a => { atuoResetEvent.Set(); Console.WriteLine("工作流被卸载了"); LogHelper.WriteLog("工作流被卸载了"); }; wfApp.OnUnhandledException += a =>//工作流异常的时候 响应的方法 { atuoResetEvent.Set(); Console.WriteLine("出现了异常"); LogHelper.WriteLog(a.UnhandledException.ToString()); //记录异常信息 return(UnhandledExceptionAction.Terminate); //直接结束工作流 }; wfApp.Aborted += a => { atuoResetEvent.Set(); Console.WriteLine("Aborted"); }; //工作流持久化 //创建一个保存 工作流实例的sqlstore对象。 SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(StrSql); //在wfApp持久化的时候,保存到上面对象所配置的数据库里面去 wfApp.InstanceStore = store; wfApp.Run(); return(wfApp); }
public WorkflowManager(Activity wfDefinition, Version vrsn) { SqlWorkflowInstanceStore wfInstanceStore = InitializeInstanceStore(); WorkflowIdentity wfIdentity = InitializeIdentity(wfDefinition, vrsn); this.WFApplication = InitializeApplication(wfDefinition, wfIdentity, wfInstanceStore); }
private static SqlWorkflowInstanceStore SetupSqlPersistenceStore() { var sqlPersistenceDbConnectionString = @"Server=.\SQLEXPRESS;Initial Catalog=PersistenceDatabase;Integrated Security=True"; var sqlWFInstanceStore = new SqlWorkflowInstanceStore(sqlPersistenceDbConnectionString); return(sqlWFInstanceStore); }
//private static string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["workFlowDataBase"].ConnectionString; public static WorkflowApplication CreateWorkflowApplication(Activity activity, IDictionary <string, object> data, AutoResetEvent synEvent) { _syncEvent = synEvent; string strCon = ConfigurationManager.ConnectionStrings["workFlowDataBase"].ConnectionString; SqlWorkflowInstanceStore store1 = new SqlWorkflowInstanceStore(strCon); WorkflowApplication application = new WorkflowApplication(activity, data) { InstanceStore = store1 }; application.Run(); //application.Persist(); application.Completed = delegate(WorkflowApplicationCompletedEventArgs args) { Console.WriteLine("The workflow completed"); synEvent.Set(); }; application.Aborted = delegate(WorkflowApplicationAbortedEventArgs arg) { Console.WriteLine("Workflow aborted"); synEvent.Set(); }; application.Idle = delegate(WorkflowApplicationIdleEventArgs args) { Console.WriteLine("Workflow is idle"); synEvent.Set(); }; application.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs args) { Console.WriteLine(""); synEvent.Set(); return(PersistableIdleAction.Unload); }; application.Unloaded = delegate(WorkflowApplicationEventArgs eventArgs) { Console.WriteLine("Workflow {0} unloaded", eventArgs.InstanceId); synEvent.Set(); }; application.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs args) { Console.WriteLine("Workflow is on unhandled."); synEvent.Set(); return(UnhandledExceptionAction.Abort); }; //application.Unloaded += OnUnloaded; //application.Aborted += OnAborted; //application.Completed += OnCompleted; //application.Idle += OnIdle; //application.OnUnhandledException += OnUnhandledException; //application.PersistableIdle += OnPersistableIdle; return(application); }
//end protected void btnEdit_ServerClick(object sender, EventArgs e) { if (((this.txtName.Value.Length == 0) || (this.uploadurl.Value.Length == 0)) || (this.selWorkFlow.SelectedValue.Length == 0)) { MessageBox.Show(this, "请您填写完整的信息"); } else { Model.SelectRecord selectRecord = new Model.SelectRecord("WorkFlow", "", "*", "where id='" + this.selWorkFlow.SelectedValue + "'"); DataTable table = BLL.SelectRecord.SelectRecordData(selectRecord).Tables[0]; string content = File.ReadAllText(System.Web.HttpContext.Current.Request.MapPath("../") + table.Rows[0]["URL"].ToString()); //ziyunhx add 2013-8-5 workflow Persistence //old code //WorkFlowTracking.instance = engineManager.createInstance(content, null, null); //WorkFlowTracking.instance.Run(); //new code instance = engineManager.createInstance(content, null, null); if (instanceStore == null) { instanceStore = new SqlWorkflowInstanceStore(SqlHelper.strconn); view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30)); instanceStore.DefaultInstanceOwner = view.InstanceOwner; } instance.InstanceStore = instanceStore; instance.Run(); //end Model.Document documents = new Model.Document { ID = id.Trim(), Name = this.txtName.Value.Trim(), URL = this.uploadurl.Value.Trim(), Remark = this.txtReMark.Value.Trim(), WID = this.selWorkFlow.SelectedValue, WStep = "0", Result = "0", UID = this.Session["admin"].ToString(), //ziyunhx add 2013-8-5 workflow Persistence //old code //FlowInstranceID = WorkFlowTracking.instance.Id, //new code FlowInstranceID = instance.Id, //end }; if (BLL.Document.DocumentUpdate(documents) == 1) { UserOperatingManager.InputUserOperating(this.Session["admin"].ToString(), "工作流管理", "编辑工作流" + documents.Name + "的信息成功"); MessageBox.ShowAndRedirect(this, "编辑公文成功!", "/document/DocumentList.aspx"); } else { UserOperatingManager.InputUserOperating(this.Session["admin"].ToString(), "工作流管理", "编辑工作流" + documents.Name + "的信息失败"); MessageBox.Show(this, "编辑工作流失败"); } } }
private static void UpgradeExistingWorkflow(Guid id, DynamicUpdateMap map) { SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings["db"].ConnectionString); WorkflowApplicationInstance instance = WorkflowApplication.GetInstance(id, store); WorkflowApplication app = new WorkflowApplication(GetUpdatedWorkflow()); app.Load(instance, map); app.Unload(); }
public WorkflowHostHelper() { Debug.WriteLine(InstanceStoreConnectionString); store = new SqlWorkflowInstanceStore(InstanceStoreConnectionString); syncEvent = new AutoResetEvent(false); persistEvent = new AutoResetEvent(false); wfApp = new WorkflowApplication(new Germany()); wfApp.InstanceStore = store; }
private void InitializeMembers() { this.syncRoot = new object(); this.stopRequested = false; this.contextGuid = Guid.Empty; this.workflows = new Dictionary <Guid, WorkflowDetails>(); this.graywulfLogger = null; this.workflowInstanceStore = null; }
//恢复书签 拿到在数据库中的实例 继续执行 public static WorkflowApplication ResumeBookMark(Activity activity, Guid instanceid, string bookMarkName, object value) { AutoResetEvent autoResetEvent = new AutoResetEvent(false); WorkflowApplication wfApp = new WorkflowApplication(activity); wfApp.Idle += a =>//当工作流停下来的时候,执行此事件响应方法。 { Console.WriteLine("工作流停下来了..."); }; //工作流停下的时候,进行的操作 wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e3) { Console.WriteLine("工作卸载进行持久化"); return(PersistableIdleAction.Unload); }; wfApp.Unloaded += a => { LogHelper.WriteLog("工作流被卸载了。。"); autoResetEvent.Set(); Console.WriteLine("工作流被卸载了"); }; wfApp.OnUnhandledException += a =>//工作流异常的时候 响应的方法 { autoResetEvent.Set(); Console.WriteLine("出现了异常"); LogHelper.WriteLog(a.UnhandledException.ToString()); //记录异常信息 return(UnhandledExceptionAction.Terminate); //直接结束工作流 }; wfApp.Aborted += a =>//终止的时候 响应的方法 { autoResetEvent.Set(); Console.WriteLine("Aborted"); }; //创建一个保存 工作流实例的sqlstore对象。 SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(StrSql); //wfApp在进行持久化的时候,保存到上面对象配置的数据库里面去。 wfApp.InstanceStore = store; //从数据库中获得当前工作流实例的状态 wfApp.Load(instanceid); //工作流继续执行 wfApp.ResumeBookmark(bookMarkName, value); return(wfApp); }
private SqlWorkflowInstanceStore SetupSqlpersistenceStore() { string connectionString = ConfigurationManager. AppSettings["SqlWF4PersistenceConnectionString"].ToString(); SqlWorkflowInstanceStore sqlWFInstanceStore = new SqlWorkflowInstanceStore(connectionString); return(sqlWFInstanceStore); }
//<Snippet1> static void SetupInstanceStore() { instanceStore = new SqlWorkflowInstanceStore(@"Data Source=.\SQLEXPRESS;Initial Catalog=SampleInstanceStore;Integrated Security=True;Asynchronous Processing=True"); InstanceHandle handle = instanceStore.CreateInstanceHandle(); InstanceView view = instanceStore.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30)); handle.Free(); instanceStore.DefaultInstanceOwner = view.InstanceOwner; }