簡體   English   中英

如何將數據集從活動傳遞到.net中的工作流?

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

我創建了一個活動來返回數據集,如下所示:

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;
        }
    }

然后創建工作流程示例,並將此活動放在工作流程上並設置所需的屬性。 但是,當我嘗試訪問此活動以獲取結果數據集時,它什么也不返回。 如果我調試出代碼,則它將進入EndExecute方法並正確填充數據集。 但是什么都沒有從我們調用它的地方返回到工作流,下面是工作流應用程序示例的program.cs中使用的代碼:

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

在這里,它在字典對象結果中返回0個鍵。 任何人都可以幫助我如何將數據集恢復到此處?
我正在使用.Net 4.0

WorkflowInvoker.Invoke()從工作流返回OutAurgument和InOutArguments。

我認為您只是添加了一個方向為“ Out”的參數,並使用該參數關聯了活動的結果。

John Vottero是正確的,但沒有明確提供所有步驟。

在您的工作流中創建一個名為MyWorkflowArgument的輸入/輸出參數(例如)。

在名為myActivityArgument的活動中創建一個輸入/輸出參數。

在工作流級別,在活動的屬性中,將myWorkflowArgument添加到myActivityArgument的字段中

現在確保您的活動代碼填充了myActivityArgument。 這意味着myActivityArgument的值在工作流級別可用作myWorkflowArgument。

然后,當工作流程使用myWorkflowArgument作為鍵完成時,可以將myWorkflowArgument與其他活動一起使用或從Dictionary結果中檢索值。

參數名稱由您決定。 我通常為工作流參數使用與活動參數相同的名稱,以便我可以知道何時應該保留它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM