探索flutter框架开发的app在移动应用市场的潜力与挑战
644
2022-08-31
DDD工作流持久化(十六)
找到对应的sql文件执行sql语句
产生如下的表:
添加引用:
添加命名空间:
using System.Activities.DurableInstancing;using System.Runtime.DurableInstancing;
对持久化的存储进行配置:
WorkflowApplication instance; SqlWorkflowInstanceStore instancestore; private void InstanceConfig() { instance = new WorkflowApplication(new ApprovalWorkflow.ApprovalWorkflow()); instancestore = new SqlWorkflowInstanceStore(); instancestore.ConnectionString = ConfigurationManager.AppSettings["constr"]; instance.InstanceStore = instancestore; instance.Idle = new Action
private PersistableIdleAction workflowpersist(WorkflowApplicationIdleEventArgs args) { return PersistableIdleAction.Unload; }
执行查询语句:
SqlConnection conn = null; SqlCommand cmd = null; private void ResumeActivity(string bookmarkname,string cb) { conn = new SqlConnection(); conn.ConnectionString = ConfigurationManager.AppSettings["constr"]; conn.Open(); cmd = new SqlCommand("select Id from [System.Activities.DurableInstancing].[InstancesTable]", conn); var instanceid=(Guid)cmd.ExecuteScalar(); InstanceConfig(); instance.Load(instanceid); if (instance != null) { if(instance.GetBookmarks().Count(p=>p.BookmarkName==bookmarkname)==1) instance.ResumeBookmark(bookmarkname, cb); } }
WF的跟踪:
定义一个跟踪的参与者类:
引入命名空间:
using System.Activities.Tracking;
public class WFTrackParticipent:TrackingParticipant { ///
定义筛选的类:
public class WFTracking { public static WFTrackParticipent GetTrackingInfo() { TrackingProfile trackingprofiler = new TrackingProfile(); trackingprofiler.Name = "wf tracking profiler"; WorkflowInstanceQuery workflowinstancequery = new WorkflowInstanceQuery(); workflowinstancequery.States.Add(WorkflowInstanceStates.Started);//开始的状态 workflowinstancequery.States.Add(WorkflowInstanceStates.Completed);//完成的状态 workflowinstancequery.States.Add(WorkflowInstanceStates.Persisted); workflowinstancequery.States.Add(WorkflowInstanceStates.Resumed); ActivityStateQuery activitystatequery = new ActivityStateQuery(); activitystatequery.ActivityName = "*"; activitystatequery.Arguments.Add("*"); activitystatequery.Variables.Add("*"); activitystatequery.States.Add(ActivityStates.Executing); activitystatequery.States.Add(ActivityStates.Closed); trackingprofiler.Queries.Add(workflowinstancequery); trackingprofiler.Queries.Add(activitystatequery); WFTrackParticipent wftrackparticipent = new WFTrackParticipent(); wftrackparticipent.TrackingProfile = trackingprofiler; return wftrackparticipent; } }
启动程序监听的代码:
instance.Extensions.Add(WFTracking.GetTrackingInfo());
异步线程执行代码:
public class Compute { AsyncCallback callback; IAsyncResult asyncResult; int n; int result; public IAsyncResult BeginmyCall(int n, AsyncCallback callback, object asyncState) { this.n = n; this.callback = callback; this.asyncResult = new myAsyncResult() { AsyncState = asyncState }; Thread thread = new Thread(new ThreadStart(myProcessThread)); thread.Start(); return asyncResult; } public void EndmyCall(IAsyncResult r) { } public void myProcessThread() { for (int i = 1; i <= n; i++) { Thread.Sleep(1000); result = result + i; Console.WriteLine(i); } Console.WriteLine(result.ToString()); this.callback(this.asyncResult); } }
public class myAsyncResult : IAsyncResult { public object AsyncState { get; set; } public System.Threading.WaitHandle AsyncWaitHandle { get; set; } public bool CompletedSynchronously { get { return true; } } public bool IsCompleted { get { return true; } } }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~