首页 新闻 会员 周边 捐助

WF创建工作流、给对象赋值,创建活动实例后,活动中取值为Null,求助

0
悬赏园豆:20 [已关闭问题] 关闭于 2011-10-25 13:34

   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

求大虾解答

_劍客的主页 _劍客 | 初学一级 | 园豆:94
提问于:2011-10-25 11:01
< >
分享
所有回答(1)
0

[ 自己解决 ] 了

_劍客 | 园豆:94 (初学一级) | 2011-10-25 13:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册