'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
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
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
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.
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.
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?