'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 withSystem.Workflow.Activities.Sequence and set each of the child itemsVisible property toFalse. But when my activity is placed in the workflow, someone can still drop additional activities onto my own because it derives fromSequence. I want this activity to appear as a logical whole and don't want items added to it.

If I start withSystem.Workflow.ComponentModel.CompositeActivity, it appears I will have to create a customToolboxItem 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

[829 byte] By [JaredBienz] at [2008-2-20]
# 1
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

Chethan at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2
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

ArjunBanker at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 3

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.

vihang at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 4
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

JaredBienz at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 5
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.
JaredBienz at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 6
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.

BobSchmidt at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 7
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?
JaredBienz at 2007-9-9 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified