在工作流活动之间共享数据

发布于 2024-12-04 01:42:30 字数 305 浏览 1 评论 0原文

我有一个自定义活动列表(用 C# 代码编写),其中每个活动都派生自 NativeActivity,现在我借助 foreach 循环将所有这些活动添加到序列中。 现在的问题是,如果我需要从一项活动中获取一些价值并将其传递给另一项活动,我应该如何进行。

比方说,activity1 将字符串属性值设置为“某个文件名”(提供图像文件路径),并基于它旁边的活动(借助 for 循环将其添加到序列中),将其作为输入翻转该图像。

获取文件的逻辑在activity1的execute方法中,与activity2的execute方法中翻转图像的逻辑相同。

提前致谢

I m with a list of custom activities(written in code behind, C#) where each is derived from NativeActivity, now I'm adding all these activities to a sequence with the help of a foreach loop.
now the question is, how I should proceed if I need to get some value from an activity and to pass it on to another activity.

Say, activity1 sets a string property value to "some file name"(lets an image file path) and based on that the activity next to it which so ever is added into the sequence with the help of for loop, takes it as input to flip that image.

Logic for getting the file is thre in Execute method of activity1 and the same to flip the image in Execute method of activity2.

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆追雨的时光 2024-12-11 01:42:30
        var workflow = new Sequence();           
        Variable<Dictionary<string,object>> variable = new Variable<Dictionary<string,object>>
        {
            Name = "SharedData"
        };
        workflow.Variables.Add(variable);
        foreach (MyCustomActivity activity in mAddedActivities)
        {                
            workflow.Activities.Add(activity);                                      
        }

        WorkflowInvoker invoker = new WorkflowInvoker(workflow);
        invoker.Invoke();

这就是我在实际实现中所做的,不需要任何争论/争论,变量“共享数据”足以保存跨活动的数据。

现在,在重写代码活动“执行”方法的每个活动级别,您必须使用此代码摘录来获取输入/获取此工作流变量“SharedData”的值。

        WorkflowDataContext dataContext = context.DataContext;
        PropertyDescriptorCollection propertyDescriptorCollection = dataContext.GetProperties();
        foreach (PropertyDescriptor propertyDesc in propertyDescriptorCollection)
        {
            if (propertyDesc.Name == "SharedData")
            {
                myData = propertyDesc.GetValue(dataContext) as Dictionary<string, object>;
                if (myData == null) //this to check if its the initial(1st) activity.
                    myData = new Dictionary<string, object>();
                //I'm adding here an additional value into the workflow variable 
                //its having signature same as that of workflow variable
                //dictionary's key as what it is and value as an object
                //which user can cast to what actually one wants.
                myData.Add("islogonrequired", Boolean.TrueString);


                //here I'm fetching some value, as i entered it in my previous activity. 
                string filePath = myData["filepath"].ToString();
                propertyDesc.SetValue(dataContext, myData);
                break;
            }
        }

希望这可以帮助其他人..
感谢其他人的帮助和支持。

        var workflow = new Sequence();           
        Variable<Dictionary<string,object>> variable = new Variable<Dictionary<string,object>>
        {
            Name = "SharedData"
        };
        workflow.Variables.Add(variable);
        foreach (MyCustomActivity activity in mAddedActivities)
        {                
            workflow.Activities.Add(activity);                                      
        }

        WorkflowInvoker invoker = new WorkflowInvoker(workflow);
        invoker.Invoke();

This is what i Did for the actual implementation, there is no need of any inargument/outargument, The variable "Shared Data" is capable enough to hold the data across activities.

Now at each activity level in overridden code activity "Execute" method, you must use this excerpt of code to fetch input/fetch the value of this workflow variable, "SharedData".

        WorkflowDataContext dataContext = context.DataContext;
        PropertyDescriptorCollection propertyDescriptorCollection = dataContext.GetProperties();
        foreach (PropertyDescriptor propertyDesc in propertyDescriptorCollection)
        {
            if (propertyDesc.Name == "SharedData")
            {
                myData = propertyDesc.GetValue(dataContext) as Dictionary<string, object>;
                if (myData == null) //this to check if its the initial(1st) activity.
                    myData = new Dictionary<string, object>();
                //I'm adding here an additional value into the workflow variable 
                //its having signature same as that of workflow variable
                //dictionary's key as what it is and value as an object
                //which user can cast to what actually one wants.
                myData.Add("islogonrequired", Boolean.TrueString);


                //here I'm fetching some value, as i entered it in my previous activity. 
                string filePath = myData["filepath"].ToString();
                propertyDesc.SetValue(dataContext, myData);
                break;
            }
        }

Hope this might help others..
Thanks everyone else out there for their help n support.

反目相谮 2024-12-11 01:42:30
        var workflow = new Sequence();
        //Variable<string> v = new Variable<string>
        //{
        //    Name = "str" 
        //};

        //workflow.Variables.Add(v);

        Dictionary<string, object> abc = new Dictionary<string, object>();
        abc.Add("thedata", "myValue");

        foreach (MyCustomActivity activity in mAddedActivities)
        {
            if (activity.ActivityResult == null)
                activity.ActivityResult = new Dictionary<string, object>();
            activity.ActivityResult = abc;                
            workflow.Activities.Add(activity);

            //new Assign<string>
            //           {
            //               To = v,
            //               Value = activity.ActivityResult["thedata"].ToString()
            //           };                

        }
        WorkflowInvoker invoker = new WorkflowInvoker(workflow);
        invoker.Invoke();

这就是我所做的,并且不知何故它正在发挥作用。我不确定它的正确方法,建议我一些建议!!,这里 ActivityResult 是通过某种接口成员在各种添加的活动之间共享的属性。

        var workflow = new Sequence();
        //Variable<string> v = new Variable<string>
        //{
        //    Name = "str" 
        //};

        //workflow.Variables.Add(v);

        Dictionary<string, object> abc = new Dictionary<string, object>();
        abc.Add("thedata", "myValue");

        foreach (MyCustomActivity activity in mAddedActivities)
        {
            if (activity.ActivityResult == null)
                activity.ActivityResult = new Dictionary<string, object>();
            activity.ActivityResult = abc;                
            workflow.Activities.Add(activity);

            //new Assign<string>
            //           {
            //               To = v,
            //               Value = activity.ActivityResult["thedata"].ToString()
            //           };                

        }
        WorkflowInvoker invoker = new WorkflowInvoker(workflow);
        invoker.Invoke();

this is what I did, and somehow it is working. I'm not sure as its right approach, suggest me something Will!!, here ActivityResult is property which is shared among the various added activities, via some sort of Interface member..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文