【问题标题】:How to pass the In-argument parameters of windows workflow to a custom code activity properties?如何将 Windows 工作流的 In-argument 参数传递给自定义代码活动属性?
【发布时间】:2015-08-28 06:30:38
【问题描述】:
        //adding parameters and invoking workflow but the properties inside the codeactivity is all
    static void Main(string[] args)
    {
      Activity workflow1 = new Workflow1();//activity
      IDictionary<string, object> parameters = new Dictionary<string, object>();
      parameters.Add("toFolder", @"C:\BackupByWorkFlow");//param1
      parameters.Add("fromFolder", @"C:\");//param2
       WorkflowInvoker.Invoke(workflow1, parameters);//invoke
    }

// workflow1 contains sequence of activities

// sequence->WhileBackup activity -> and  other custom activities

      //Custom code activity in workflow is as below
    public sealed class WhileBackup : CodeActivity
     {
       // Defining properties
           public InArgument<string> Text { get; set; }
            public InArgument<string> toFolder { get; set; }//property is null
            public InArgument<string> fromFolder { get; set; }//property is null
            public int totalFiles { get; set; }
            public int currentFile;
            public  FileInfo[] files;

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
          protected override void Execute(CodeActivityContext context)
                  {
                       // Obtain the runtime value of the Text input argument
                       string text = context.GetValue(this.Text);
                 }
    }

工作流的in-argument值不为null,但同一工作流中的代码活动相同为null。因此我想知道如何将工作流的in参数的值传递给代码活动属性。

【问题讨论】:

    标签: c# asp.net workflow-foundation-4


    【解决方案1】:

    您传递给 Invoke 的参数作为参数传递给工作流,但它们不会自动传递到工作流中的活动。

    在工作流定义中,您必须定义要传递给工作流的参数,并且必须将 toFolder 和 fromFolder 参数显式映射到活动的 toFolder 和 fromFolder 属性。

    请注意,参数和属性的名称不必匹配,使它们匹配并不意味着什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-13
      • 2015-01-21
      • 1970-01-01
      • 2021-07-04
      • 2014-10-30
      • 1970-01-01
      相关资源
      最近更新 更多