locked
Container Activity RRS feed

  • Question

  • I'm trying to design a container Activity.
    The container Activity is verry simple here is the code:

     

     [ContentProperty("Body")]
    [Designer(typeof(ContainerDesigner))]
    public class MyContainer : NativeActivity
    {
    [RequiredArgument]
    public InArgument<string> ArgOne { get; set; }

    [RequiredArgument]
    public InArgument<string> ArgTwo { get; set; }

    [Browsable(false)] public Activity Body { get; set; }

    [Browsable(false)] public Collection<Variable> Variables { get; set; }

    public MyContainer()
    {
    //collection initialisieren
    this.Variables = new Collection<Variable>();
    }

    protected override void CacheMetadata(System.Activities.NativeActivityMetadata metadata)
    {
    //caching metadata aus performance gründen
    metadata.AddChild(Body);

    RuntimeArgument aktArt = new RuntimeArgument("MyArgOne", typeof(string),ArgumentDirection.In);
    metadata.Bind(this.ArgOne, aktArt);
    metadata.AddArgument(aktArt);


    RuntimeArgument aktBez = new RuntimeArgument("MyArgTwo", typeof(string), ArgumentDirection.In);
    metadata.Bind(this.ArgTwo, aktBez);
    metadata.AddArgument(aktBez);


    if (this.Variables.Count > 0)
    {
    foreach (var variable in this.Variables)
    {
    metadata.AddVariable(variable);
    metadata.AddImplementationVariable(variable);
    }
    }

    base.CacheMetadata(metadata);
    }



    protected override void Execute(System.Activities.NativeActivityContext context)
    {
    context.ScheduleActivity(Body);
    }
    }


     

    The designer simply allows yout to drop an activity to the Body.
    If i understand it wright the Arguments are available for all ChildActivities.
    Now i'm trying to create a new Activity in VS with the Designer using for example an FlowChart and at a point im assigning the ContentActivity.
    The designer recognise the Required Arguments and show validation error.

    The problem is when i assing a WriteLine, for example, to the Body and trying to access the ArgOne argument.
    The validation say, "ArgOne" is not Assigned. Cannot access Object because of the SecurityLevel. (Translated Manuall, i am German original message: "Beim Verarbeiten des Ausdrucks"ArgOne" ist mindestens ein Compilierfehler aufgetreten. "ArgOne" ist nicht deklariert. Auf das Objekt kann aufgrund der Schutzstufe möglicherweise nicht zugegriffen werden.)

    So the problem i have is that Intellisense do not support my arguments parsed to the Body(Content) and i cannot access the Argument from my Content cause of the Validation Error.

    Friday, February 18, 2011 2:08 PM

Answers

All replies

  • Hello Roland,
    Let me start by saying that I feel your pain.  Some time back I too was hoping to provide very similiar functionality.  I remember spending a lot of hours trying to figure out a way to accomplish it from a number of approaches but never got anything to work that I was satisfied with.  What I ultimately determined was that while i thought I needed this functionality I really didn't.  I realized that any activity that I dropped into the body of my container was being defined on the same xaml activity as my container itself.  Therefore, if my body needed the value passed into my container, the value could also be passed directly into my body from its original source. 

    Of course, its never really that simple.  What I was personally after was establishing a context so that I wouldn't have to pass along an argument through layers of children.  This was important to me because the activities that would ultimately be placed in the body weren't supposed to know about my property.  For this particular problem I found my solution was ExecutionProperties that could be set and retrieved through NativeActivityContext::Properties.

    Regretfully, I never really researched further and just concluded it wasn't possible. Hopefully somebody else will chime in with a happier story.  :)

    -Mike

    Saturday, February 19, 2011 4:33 AM
  • Hi,

    To create a composite activity and its activity designer, please see this blog entry I wrote sometime ago:
    http://xhinker.com/post/WF4My-Composite-Activity.aspx

    Hope this helps
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Friday, February 25, 2011 2:28 AM
    Tuesday, February 22, 2011 3:38 AM