Dynamic WorkItems

Topics: CAB & Smart Client Software Factory
Mar 11, 2006 at 7:38 PM
originally posted by: saregama

I'm having XML datasource that stores the name of workitems to activate when a user selects the appropriate task from a tree view. What would be the syntax to nest a new workitem to the parent workitem based on the string, which is the name of the new workitem?
Mar 14, 2006 at 4:17 AM
originally posted by: jbarmash

Can you please elaborate? What do you mean by syntax to nest a workitem - are you asking about how to design your xml, or what's the C# code to nest a workitem?
Mar 14, 2006 at 7:46 AM
originally posted by: saregama

I have a method that returns a string that represents a workitem name (say "CustomerWorkItem"). I would like to know the C# syntax to nest a workitem of type CustomerWorkItem to my root workitem?
Mar 14, 2006 at 8:46 AM
originally posted by: jbarmash

oh, ok. i don't have the time now to code and test an example, but basically, two things have to happen

1 - Get the String, i.e. CustomerWorkItem", figure out what the exact type is, then use the ObjectBuilder to build it up (you need that so all the dependencies get injected correctly),
2. You need to add the workitem to the list of workitems on the root workitem.

here is some psudocode that you would add to your rootworkitem:

RootWorkItem.AddCustomItem() {
string workItemName = customServce.getCustomWorkItemName();
Type workItemType = //convert workItemName to type using reflection
WorkItem newWorkItem = this.innerBuilder.BuildUp<workItemType>;
this.WorkItems.AddNew<newWorkItem>;
newworkItem.activate(); //should activate the workitem
}

hope this helps.
Mar 14, 2006 at 11:30 AM
originally posted by: saregama

Thanks a lot!
Mar 16, 2006 at 12:46 PM
originally posted by: saregama

I get the type from the string
System.Type workItemType = System.Type.GetType(sWorkItem);

However, it breaks when on this line:
WorkItem newWorkItem = this.innerBuilder.BuildUp<workItemType>;

with these errors:
1. The type or namespace name 'workItemType' could not be found (are you missing a using directive or an assembly reference?)
2. Cannot convert method group 'BuildUp' to non-delegate type 'Microsoft.Practices.CompositeUI.WorkItem'. Did you intend to invoke the method?

Is there anything incorrect with my syntax? or the way the type is passed in.