Question

Short Version

I want to use an activity in another activity, the only solution that I find is to use Interop Activity. But now i got some problem with the Workflow Fundation 4.5 Interop.

Long Version

My project is in C# .NET 4.5.
My first activity do a simple addition between two doubles. I did this one with the xaml designer tools.
My second activity is just calling the first activity with the Interop Activity.

Here my ViewModel: MyMain.cs:

public class MyMain : INotifyPropertyChanged
    {
        private double a, b, c, d, e, f, g;
    public double A
    {
        get { return a; }
        set
        {
            if (a == value) return;
            a = value;
            OnPropertyChanged("A");
        }
    }

    public double B
    {
        get { return b; }
        set
        {
            if (b == value) return;
            b = value;
            OnPropertyChanged("B");
        }
    }


    public double G
    {
        get { return g; }
        set
        {
            if (g == value) return;
            g = value;
            OnPropertyChanged("G");
        }
    }

    public void Do()
    {
        Activity act = testing();
        Dictionary<string, object> ins = new Dictionary<string, object>();
        ins.Add("A", A);
        ins.Add("B", B);
        var output = WorkflowInvoker.Invoke(act, ins);
        MessageBox.Show(output["G"].ToString());

    }
    public DynamicActivity testing()
    {

        A = 5.3;
        B = 2.1;


        // Define the Input and Output arguments that the DynamicActivity binds to
        var aa = new InArgument<double>(A);
        var bb = new InArgument<double>(B);
        var gg = new OutArgument<double>();
        return new DynamicActivity()
        {
            Properties = 
            {
                new DynamicActivityProperty() {Name = "AA", Type = typeof (InArgument<double>), Value = aa},
                new DynamicActivityProperty() {Name = "BB", Type = typeof (InArgument<double>), Value = bb},

                new DynamicActivityProperty() {Name = "GG", Type = typeof (OutArgument<double>), Value = gg}
            },
            Implementation = () =>
                new Sequence
                {
                  Activities =
                  {
                      new Interop()
                      {
                          ActivityType = typeof(Adds),
                          ActivityProperties =
                          {
                              {"A", new InArgument<double>(env => aa.Get(env))},
                              {"B", new InArgument<double>(env => bb.Get(env))},
                              {"C", new OutArgument<double>(env => gg.Get(env))}
                          }
                      }
                  }
                }
        };
    }
    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged(string propName)
    {
        if (PropertyChanged != null)
        {
            MessageBox.Show(propName);
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }
    #endregion
}

My xaml: MainWindow.xaml:

<Window x:Class="ActWpf.MainWindow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Label Content="Resultat" HorizontalAlignment="Left" Height="26" Margin="34,78,0,0" VerticalAlignment="Top" Width="102"/>
        <Button Content="Button" HorizontalAlignment="Left" Height="26" Margin="367,78,0,0" VerticalAlignment="Top" Width="88" Click="Calculate"/>
        <Label Content="Label" HorizontalAlignment="Left" Height="26" Margin="160,78,0,0" VerticalAlignment="Top" Width="148"/>

    </Grid>
</Window>

I got that warning which I find nothing to fix it:

System.Activities.Statements.Interop is obsolete: The WF3 Types are deprecated. Instead, please use the new WF4 Types from System.Activities.*

My execution error(I translate the error because normally it's in french):

DynamicActivity': The private implementation of the activity
'1: DynamicActivity' gives the follow validation error : Invalid value specify for the property 'ActivityType' of the Interop Activity 'Interop'.
 The value of this property have to be System.Type which herite ofSystem.Workflow.ComponentModel.Activity.

here the french, if that can help:

'DynamicActivity': L'implémentation privée de l'activité '1: DynamicActivity' présente l'erreur de validation suivante :   Valeur incorrecte spécifiée pour la propriété 'ActivityType' de l'activité Interop 'Interop'.

La valeur de cette propriété doit être un System.Type qui hérite de System.Workflow.ComponentModel.Activity.

Was it helpful?

Solution

I fix my problem. Normally, if your activity work well you can find them in a specify div in the xaml workflow in Toolbox.
A specify div will be add foreach of your projects/namespaces and you can find and drag/drop your activities from those namespaces.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top