1
votes

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

2
This question makes no sense. If you know enough to create an activity extending from NativeActivity you should be able to figure out how in/out arguments, variables and even workflow extensions work. - user1228
hey Will, its not about sense, I'm obstruct here, thats why asked the question, in your words it can b senseless, but for me, i might be missing something.. If you know the something called sensible answer for it, do let me know, may be it gonna be useful for me. your help can add words to my thoughts. - Manjeet Singh
Then bind an outargument of activity1 to a variable of the workflow, and then bind an inargument of activity2 to that same variable. - user1228
exactly this i need of, see will, you might surprise, but i started working on WF just 2 weeks ago, thou i came to this level, but you know sometimes the baisc things get ignored. So if you can brief me by mere example, I will be glad. - Manjeet Singh

2 Answers

3
votes
        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.

0
votes
        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..