简体   繁体   English

如何将数据集从活动传递到.net中的工作流?

[英]How to pass dataset from activity to workflow in .net?

I have created an activity to return dataset as below: 我创建了一个活动来返回数据集,如下所示:

public class DbQueryDataSet : AsyncCodeActivity<DataSet>
    {
        // private variables
        IDictionary<string, Argument> parameters;
        DbHelper dbHelper;


        // public arguments
        [DefaultValue(null)]
        public InArgument<string> ProviderName { get; set; }

        [DefaultValue(null)]
        public InArgument<string> ConnectionString { get; set; }

        [DefaultValue(null)]
        public InArgument<string> ConfigName { get; set; }

        [DefaultValue(null)]
        public CommandType CommandType { get; set; }

        [RequiredArgument]
        public InArgument<string> Sql { get; set; }

        [DependsOn("Sql")]
        [DefaultValue(null)]
        public IDictionary<string, Argument> Parameters
        {
            get
            {
                if (this.parameters == null)
                {
                    this.parameters = new Dictionary<string, Argument>();
                }
                return this.parameters;
            }
        }


        /*public DbQueryDataSet()
        {
            this.CommandType = CommandType.Text;
        }*/

        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            // configure the helper object to access the database
            dbHelper = new DbHelper();
            dbHelper.ConnectionString = this.ConnectionString.Get(context);
            dbHelper.ProviderName = this.ProviderName.Get(context);
            dbHelper.ConfigName = this.ConfigName.Get(context);
            dbHelper.Sql = this.Sql.Get(context);
            dbHelper.CommandType = this.CommandType;
            dbHelper.Parameters = this.parameters;
            dbHelper.Init(context);

            // create the action for doing the actual work
            Func<DataSet> action = () => dbHelper.GetDataSet();
            context.UserState = action;

            return action.BeginInvoke(callback, state);
        }

        protected override DataSet EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
        {
            Func<DataSet> action = (Func<DataSet>)context.UserState;
            DataSet dataSet = action.EndInvoke(result);


            // dispose the database connection
            dbHelper.Dispose();
            Result.Set(context, dataSet);
            // return the state
            return dataSet;
        }
    }

Then created a workflow sample and dropped this activity on workflow and set the required properties. 然后创建工作流程示例,并将此活动放在工作流程上并设置所需的属性。 But when I am trying to access this activity to get dataset as a result, it is returning nothing. 但是,当我尝试访问此活动以获取结果数据集时,它什么也不返回。 If I debug out the code, then it goes in the EndExecute method and fills the dataset properly. 如果我调试出代码,则它将进入EndExecute方法并正确填充数据集。 but nothing is returned to the workflow from where we are calling it, below is code used in program.cs of workflow application sample: 但是什么都没有从我们调用它的地方返回到工作流,下面是工作流应用程序示例的program.cs中使用的代码:

    Activity oActivity = new Workflow1();
    Dictionary<string, object> result = WorkflowInvoker.Invoke(oActivity);

Here it returns 0 keys in dictionary object result. 在这里,它在字典对象结果中返回0个键。 Can anyone help on how can I get Dataset back here? 任何人都可以帮助我如何将数据集恢复到此处?
I am using .Net 4.0 我正在使用.Net 4.0

WorkflowInvoker.Invoke() returns the OutAurgument and InOutArguments from the Workflow. WorkflowInvoker.Invoke()从工作流返回OutAurgument和InOutArguments。

I think you just have add an Argument with a direction of "Out" and hook up the result of your activity with that argument. 我认为您只是添加了一个方向为“ Out”的参数,并使用该参数关联了活动的结果。

John Vottero is correct but has not supplied all the steps explicitly. John Vottero是正确的,但没有明确提供所有步骤。

Create an In/Out Argument in your workflow called myWorkflowArgument (for example). 在您的工作流中创建一个名为MyWorkflowArgument的输入/输出参数(例如)。

Create an In/Out Argument in your activity called myActivityArgument. 在名为myActivityArgument的活动中创建一个输入/输出参数。

At the workflow level, in the properties for your activity, add myWorkflowArgument to the field for myActivityArgument 在工作流级别,在活动的属性中,将myWorkflowArgument添加到myActivityArgument的字段中

Now make sure that your activity code fills myActivityArgument. 现在确保您的活动代码填充了myActivityArgument。 This will mean that the values of myActivityArgument are available at workflow level as myWorkflowArgument. 这意味着myActivityArgument的值在工作流级别可用作myWorkflowArgument。

You can then use myWorkflowArgument with other activities or retrieve the value from Dictionary result, when the workflow completes using myWorkflowArgument as the key. 然后,当工作流程使用myWorkflowArgument作为键完成时,可以将myWorkflowArgument与其他活动一起使用或从Dictionary结果中检索值。

The argument names are up to you. 参数名称由您决定。 I generally use the same name for the workflow argument as I use for the activity argument so that I can tell when they are supposed to hold. 我通常为工作流参数使用与活动参数相同的名称,以便我可以知道何时应该保留它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM