locked
Create scope for custom Activity RRS feed

  • Question

  • What is required to create an Activity scope for my custom Activities derrived from NativeActivity?  All the MS container activities create an independant scope so it should be possible, but I can't find anything which explains how to do it.

    Saturday, November 14, 2009 5:10 AM

Answers

  • The "For" example shows what I was looking for:

            // The variables accessible by all 3 clauses and the body of For.
            [DefaultValue(null)]
            public Collection<Variable> Variables
            {
                get
                {
                    if (this.variables == null)
                    {
                        this.variables = new Collection<Variable>();
                    }
                    return this.variables;
                }
            }
            private Collection<Variable> variables;

    Friday, November 20, 2009 7:10 AM

All replies

  • Hi Mike,
    Is all you are wanting to do schedule a few child activities for execution, or do you want your scope to do something more than this, like have contextual data attached, or be a scope for declaring new Variables?
    Tim
    Wednesday, November 18, 2009 7:39 AM
  • You can find some samples that show you how to write composite activities in the WF 4 SDK.

    If you are trying to write a Scope activity (like CancelationScope or TransactionScope) you can take a look at NoPersistScope activity sample (it is located at %SampleRoot%\WF\scenarios\ActivityLibrary\NoPersistScope). If you just want to write a composite activity, you can take a look at the For or SwitchRange, ThrottledParallelForEachSample (both under WF\Scenarios\ActivityLibrary). If what you want is to create something like Sequence, there is a sample at %SampleRoot%\WF\Basic\CustomActivities\Code-Bodied\CustomCompositeNativeActivity\ that shows how to write your own Sequence activity.

    Leon Welicki
    Program Manager, ASG

    Wednesday, November 18, 2009 8:46 AM
  • I'm not having any difficulty creating composite activities.  What I'm trying to figure out is how to make a new variable scope for my activities.  For all the MS composite activites when you add them to the workflow you then will see them listed in the "scope" drop down under variables.  I don't see how to acheive this. 

    Thursday, November 19, 2009 6:59 PM
  • Please do check the CustomCompositeNativeActivity sample that Leon mentioned.

    Also good to know:
    -your variables panel behavior (and which activities show in the Scope dropdown) depends on which activity in the workflow is currently selected
    -designer seems to have a limitation right now that your Variables collection has to actually be called 'Variables'
    Tim
    Thursday, November 19, 2009 11:43 PM
  • I can't find any CustomCompositeNativeActivity sample.  This is what I tried which does not get a new variable scope:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Activities;
    using System.Collections.ObjectModel;
    using System.ComponentModel;

    namespace FaxBack.Workflow.Activities
    {
        [Designer(typeof(DefaultCompositeDesigner))]
        public sealed class MyCustomActivity : NativeActivity
        {
            public Activity Activities { get; set; }
            public Collection<Variable> Variables { get; set; }

            protected override void CacheMetadata(NativeActivityMetadata metadata)
            {
                metadata.AddChild(Activities);
                base.CacheMetadata(metadata);
            }
            protected override void Execute(NativeActivityContext context)
            {
                // execute children...
                context.ScheduleActivity(Activities, new CompletionCallback(OnEvaluateConditionCompleted));
            }
            void OnEvaluateConditionCompleted(NativeActivityContext context, ActivityInstance instance)
            {

            }
        }
    }

    Friday, November 20, 2009 3:30 AM
  • The "For" example shows what I was looking for:

            // The variables accessible by all 3 clauses and the body of For.
            [DefaultValue(null)]
            public Collection<Variable> Variables
            {
                get
                {
                    if (this.variables == null)
                    {
                        this.variables = new Collection<Variable>();
                    }
                    return this.variables;
                }
            }
            private Collection<Variable> variables;

    Friday, November 20, 2009 7:10 AM