Search code examples
c#.networkflow-foundation

How to add arguments to a workflow properly?


I am trying to add a simple argument to one of my activities which is OpenBrowser in a sequence, afterwards I create a simple workflow that has owns that sequence, then I run it.

Although the variables are added to the Sequence, the dictionary is properly created and the variables named properly as well as the dictionary being passed to the workflow, it still gives me the error at the bottom of the post.

I have been trying to figure this out for a few days now with no success, how should this be written?

    private void Button_Click(object sender, RoutedEventArgs e)
    {

        Variable<String> myVariable = new Variable<string>(Name = "Hehe");

        Dictionary<string, object> mainInputs = new Dictionary<string, object>();
        mainInputs.Add("Hehe","www.youtube.com");

        OpenBrowser samsungPortalBrowser = new OpenBrowser();
        samsungPortalBrowser.NewSession = true;
        samsungPortalBrowser.BrowserType = BrowserType.Chrome;
        samsungPortalBrowser.Url = myVariable;

        Sequence createSequence = new Sequence();
        createSequence.Activities.Add(samsungPortalBrowser);
        createSequence.Variables.Add(myVariable);
        WorkflowApplication app = new WorkflowApplication(createSequence, mainInputs);

        app.Run();


    }



System.ArgumentException: 'The values provided for the root activity's arguments did not satisfy the root activity's requirements:
'Sequence': The following keys from the input dictionary do not map to arguments and must be removed: Hehe.  Please note that argument names are case sensitive.
Parameter name: rootArgumentValues'

Solution

  • No need for comments, try the snip by yourself!

    internal class Program
    {
    static void Main(string args)
    {
    IDictionary<string, object> input = new Dictionary<string, object>();
    input.Add(“inMSG”, “www.youtube.com”);
    //input.Add(“myBrowser”, null);
    
            IDictionary<string, object> output = new Dictionary<string, object>();
    
            MyCodeWorkflow activity = new MyCodeWorkflow();
            output = WorkflowInvoker.Invoke(activity, input);
            //wtf
        }
    
        public class MyCodeWorkflow : Activity
        {
            public InArgument<String> inMSG { get; set; }
            public OutArgument<String> outMSG { get; set; }
    
            public OutArgument<Browser> myBrowser { get; set; }
    
            public MyCodeWorkflow()
            {
                this.Implementation = () => new Sequence
                {
                    Activities =
                    {
                        new OpenBrowser()
                        {
                            BrowserType = BrowserType.Chrome,
                            NewSession = true,
                            Url = new InArgument<string>((activityContext)=>this.inMSG.Get(activityContext)),
                            UiBrowser = new OutArgument<Browser>((ActivityContext)=> this.myBrowser.Get(ActivityContext))
                        },
    
                        new Assign<String>
                        {
                            To=new ArgumentReference<String>("outMSG"),
                            Value=new InArgument<String>((activityContext)=>this.inMSG.Get(activityContext))
                        }
                    }
                };
            }
        }
    }