For those who might stumble upon this, this is what I understood ...
First, when creating a workflow designer, you need to subscribe to the ModelChanged event.
_workflowDesigner = new WorkflowDesigner(); _workflowDesigner.Load(new Sequence()); ModelService ms = _workflowDesigner.Context.Services.GetService<ModelService>(); if (ms != null) ms.ModelChanged += new EventHandler<ModelChangedEventArgs>(ms_ModelChanged);
My event handler looks like this:
void ms_ModelChanged(object sender, ModelChangedEventArgs e) { if (e.ItemsAdded != null && e.ItemsAdded.Count<ModelItem>() == 1) { ModelItem item = e.ItemsAdded.FirstOrDefault<ModelItem>(); var test = item.GetCurrentValue() as MyActivityType; if (test != null && test.Id == null) {
I need to give this source to point me in the right direction.
One thing to take care of is that when you move an activity inside the model, two things happen: delete and add. Right now I donβt have to worry about whether I am adding or moving activity, how can I determine if it was initialized, but if you need to know if something is really added to the model, you may need to track both events .
source share