PublicationScope.Descendants

Topics: CAB & Smart Client Software Factory
Nov 11, 2005 at 12:46 PM
originally posted by: DLorenz

It looks like decendants include items of the parent workitem and all children, but doens't include the workitem itself. None of the events on the workitem get called with this scope. The bug is in EventTopic.cs here:

private EventTopicFireDelegate[] GetDescendantsHandlers(WorkItem workItem)
{
List<WorkItem> descendants = new List<WorkItem>();
List<EventTopicFireDelegate> handlers = new List<EventTopicFireDelegate>();
Descendants.Add(workItem);
for (int i = 0; i < descendants.Count; i++)
{
handlers.AddRange(GetWorkItemHandlers(descendantsi));
foreach (KeyValuePair<string, WorkItem> pair in descendantsi.WorkItems)
{
descendants.Add(pair.Value);
}
}
return handlers.ToArray();
}

Not sure exactly where the error is, but the events of the actual workitem aren't getting added.
Nov 11, 2005 at 1:08 PM
originally posted by: DLorenz

It looks like a complicated bug. Everything is fine up to:

private WorkItemSubscriptions FindWorkItemSubscription(WorkItem workItem)
{
Clean();
return workItemSubscriptions.Find(delegate(WorkItemSubscriptions match)
{
return match.WorkItem == workItem;
});
}

When Clean() gets called, you do
workItemSubscriptions.ForEach(delegate(WorkItemSubscriptions wis)
For whatever reason, the actual workitem we want is not in this collection, so wis comes back as null and its subscriptions are lost.
Nov 11, 2005 at 1:16 PM
originally posted by: DLorenz

It looks like the AddSubscription is lagging behind by one. When I create a child off of a workitem, that workitem's subscriptions get added. The child's controllers and other items get added, but none of the subscriptions on the child itself get added.
Nov 17, 2005 at 7:32 AM
originally posted by: DLorenz

This bug wasn't addressed in the RTW. Thanks.
Nov 17, 2005 at 12:20 PM
originally posted by: francode

Making this change in the EventTopic class seems to fix the problem (see "change"):

public virtual void Fire(object sender, EventArgs e, WorkItem workItem, PublicationScope scope)
{
Guard.EnumValueIsDefined(typeof(PublicationScope), scope, "scope");

if (enabled)
{
if (traceSource != null)
traceSource.TraceInformation(Properties.Resources.EventTopicTraceFireStarted, name);

switch (scope)
{
case PublicationScope.WorkItem:
CallSubscriptionHandlers(sender, e, GetWorkItemHandlers(workItem));
break;
case PublicationScope.Global:
CallSubscriptionHandlers(sender, e, GetAllHandlers());
break;
case PublicationScope.Descendants:
//"change" CallSubscriptionHandlers(sender, e, GetDescendantsHandlers(workItem);
CallSubscriptionHandlers(sender, e, GetDescendantsHandlers((WorkItem)sender)); //"change"
break;
default:
throw new ArgumentException(Properties.Resources.InvalidPublicationScope);
}

if (traceSource != null)
traceSource.TraceInformation(Properties.Resources.EventTopicTraceFireCompleted, name);
}
}
Nov 17, 2005 at 12:24 PM
originally posted by: DLorenz

I'm not sure that'll fix my problem because when I publicize the event myself, sender and workItem will actually be the same thing.