'Sealed' Sequence or Designable CompositeActivity

I want to create an activity with several child activities. I do not want the child activities to be modified and I do not want other activities added.

I could start with System.Workflow.Activities.Sequence and set each of the child items Visible property to False. But when my activity is placed in the workflow, someone can still drop additional activities onto my own because it derives from Sequence. I want this activity to appear as a logical whole and don't want items added to it.

If I start with System.Workflow.ComponentModel.CompositeActivity, it appears I will have to create a custom ToolboxItem that manually adds each of my child components and wires them up.

Is there not a better approach then either of these two

Regards,

Jared


Answer this question

'Sealed' Sequence or Designable CompositeActivity

  • VOEagain

    Okay, thanks for the note Bob. Can you give a quick suggestion as to the best way to validate it I could simply check to ensure there are an exact number of child tasks. Or I can check that only tasks I expect are there. Anything better or easier then that
  • AuzzieFlyBoy

    Oh, that's a very good one too Vihang. This would be good if I wanted to see the items in the sequence but not allow ones to be added. In my current scenario, I just want the whole thing to appear as a single item, so I think something based on ActivityDesigner would be best. But, your answer is probably more correct the way I initially posed the question.
  • ds12will

    Jared,

    I am pasting a sample code that shows you how to prevent dropping activities into your custom activity.

    [DesignerAttribute(typeof(MyDesigner))]
    [
    ToolboxItemAttribute(typeof(ActivityToolboxItem))]
    public partial class Activity1 : Sequence
    {
         public Activity1()
         {
              InitializeComponent();
          }
    }

    public class MyDesigner : SequenceDesigner
    {
       
    public override bool CanInsertActivities(HitTestInfo insertLocation, System.Collections.ObjectModel.ReadOnlyCollection<Activity> activitiesToInsert)
      {
          
    return false;
      }
    }

    Hope this helps.



  • SunilKannan

    Jared,

    You can write your own custom validator. 
    In SDK samples under custom activities there is a  sample that helps you write a custom validator. You can tweak it to match your needs.

    Hope it helps.
    Chethan

  • Doc Glazer

    One way you can achieve this is by associating a different designer class with your custom activity:

    [Designer(typeof(ActivityDesigner))]
    public partial class Activity2: Sequence
    {

       ...


    Note that the Activity designer will still show the Sequence Designer, but when you drop the activity into a workflow, the associated designer will be displayed.

    Hope this helps,
    Arjun

  • Tyler Frugia

    Jared,

    Please note that the custom designer approach achieves your goal in the UI, but does not ensure the integrity of your activity at the API level -- someone could still programmatically add activities.  To prevent this, you will need to write a custom validator (in addition to doing the IsEditable/IsVisible changes you described).

    Thanks for outlining your scenario, we'll consider if we can support it better.

  • King Gamo

    Thanks Arjun, that's what I needed.

    I'm curious about the suggestion of a custom validator as well. Would this just keep the user from adding another item Or complain if they did

    The designer is good. I will probably just plain old ActivityDesigner beause I want it to appear as a single contained step.

    Thanks,

    Jared

  • 'Sealed' Sequence or Designable CompositeActivity