public static bool CreateApprovalWorkflow(string xaml, ExpenseData expData)
{
bool flag = true;
var mer = new ManualResetEvent(false);
IDictionary<string, object> dic = new Dictionary<string, object>
{
{"expenseData",expData}
};
SqlWorkflowInstanceStore instanceStore = new SqlWorkflowInstanceStore(@"Data Source=TC11080\SQLEXPRESS;Initial Catalog=FinancialAffairs;Integrated Security=True;");
InstanceView view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30));
instanceStore.DefaultInstanceOwner = view.InstanceOwner;
WorkflowApplication app = new WorkflowApplication(ActivityXamlServices.Load(xaml), dic);
app.InstanceStore = instanceStore;
app.PersistableIdle = (e) =>
{
mer.Set();
return PersistableIdleAction.Unload;
};
app.Unloaded = (e) =>
{
mer.Set();
};
app.OnUnhandledException = (e) =>
{
flag = false;
mer.Set();
return UnhandledExceptionAction.Terminate;
};
app.Completed = (e) =>
{
mer.Set();
};
//application.Extensions.Add(CustomTrackingProfile.GetTracking());
app.Run();
mer.WaitOne();
return flag;
}
下面是活动
public sealed class CreateCodeActivity : NativeActivity
{
// 定义一个字符串类型的活动输入参数
public InOutArgument<ExpenseData> expen { get; set; }
public InArgument<int> version { get; set; }
// 如果活动返回值,则从 CodeActivity<TResult>
// 派生并从 Execute 方法返回该值。
protected override void Execute(NativeActivityContext context)
{
ExpenseData epdata = context.GetValue(expen);
int workflowVersion = context.GetValue(version);
epdata.ExpenseId = new ExpenRule().AddExpen(epdata, context.WorkflowInstanceId, workflowVersion);
epdata.InstanceID = context.WorkflowInstanceId;
this.expen.Set(context, epdata);
}
}
epdata 为null,值丢失了,workflowVersion 应该为1,此次获取到值是0
求大虾解答