Multiple WorkItem Managment

Topics: CAB & Smart Client Software Factory
Mar 9, 2006 at 9:36 AM
originally posted by: mxavier

I am building an app that will have multiple workitems that I will want to activate or deactive bases on user interaction with the program. The hope would be that as a user navigates to different areas of the program, the seperate areas would be encompassed in the seperate WorkItems.

Currently, controlledWorkItem starts the module run code, and the views with their smartparts are all places in the workspaces. I am hoping to figure out how to delay that loading until the necessary user interaction.

I have tried changing the Load code in Module.cs so that it deactivates the workitem after adding it, and then activates it once I get a Event message requesting the work item, but that doesn't seem to work.

I realize that I am probably heading in the wrong direction on this, so I was hoping someone could shed some light on how to do this correctly. Thanks
Mar 9, 2006 at 10:54 AM
originally posted by: fengdu

Here is what I did to use a subworkitem (User double click an item to open a new window for editing):

1. Create a class MyFormController similar to ModuleController and add views in the Run() method.
2. In the ModuleController class, add an EventSubscription handler for a double click event and another one for form closed.
3. Inside the 1st handler, use WorkItem.WorkItems.AddNew<ControlledWorkItem<ModuleController>>(key) to add the subworkitem and then Show() it. (You can Show it in a WorkSpace if the view is a UserControl).
4. Inside the 2nd handler, use WorkItem.Items.Get<ControlledWorkItem<ModuleController>>(key) to find the subworkitem, and then call subworkitem.Dispose() method to remove it.
Mar 9, 2006 at 4:01 PM
originally posted by: mxavier

I am having a weird problem in that when I add an EventSubsciption to the ModuleContoller class, the event is not being caught. I added a subscription to Module.cs just for testing, and that one catches the event just fine, but no luck with the ModuleController class. Any ideas?
Mar 9, 2006 at 5:53 PM
originally posted by: DeivaShankar

The subscription works fine in the ModuleController for me. If it is still a problem give more info about what you are trying to do.
Mar 9, 2006 at 5:54 PM
originally posted by: RolandLi

Did you forget to set you EventHandler 's property to public ?
I mean the EventHandler in the ModuleController.

That's an usual mistake when you just begin to use CAB.
Mar 10, 2006 at 8:06 AM
originally posted by: mxavier

Still no luck with the event subscription. I used the smart client recipe to set it up. I have the event publication in ShellForm. cs:

EventPublication(EventTopicNames.ActivatePeople, PublicationScope.Global)
public event EventHandler<EventArgs> ActivatePeople;

which is getting called with:

protected virtual void OnActivatePeople(EventArgs eventArgs)
if (ActivatePeople != null)
ActivatePeople(this, eventArgs);

In EventTopicNames.cs in the constants folder of the common assembly I have:

public const string ActivatePeople = "ActivatePeople";

and in the ModuleController.cs class of my module I have the declarations for:

using System;
using System.Windows.Forms;
using Ohana.Common;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.EventBroker;
using Ohana.Common.Constants;

and then the event subscription of:

EventSubscription(EventTopicNames.ActivatePeople, ThreadOption.UserInterface)
public void OnActivatePeople(object sender, System.EventArgs eventArgs)
WorkItem subWorkItem;
string key = "PeopleWorkItem";

subWorkItem = WorkItem.WorkItems.AddNew<ControlledWorkItem<ModuleController>>(key);
//TODO: add the subworkItem


As I mentioned before, this seems to be working fine within the module.cs class but not within modulecontroller.cs. My intent with all this is to be able to load subWorkItems based on user interaction. I will end up having multiple modules that will have their own workitems that will represent different areas of the program. My desire is not to have to load workItems until I want them.

Any ideas? Am I just missing something really obvious here? I hope so.
Mar 10, 2006 at 8:25 AM
originally posted by: fengdu

When is OnActivatePeople method in ShellForm called? Could it be possible that it was called before calling Module.Run() method which will create the workitem ControlledWorkItem<ModuleController>?
Mar 10, 2006 at 10:12 AM
originally posted by: mxavier

I went ahead and removed all the event code again, and then readded it and now I seem to be working. I'm sure I had something out of wack or else I stumbled across a weird bug, either way, I'm good to go now. Thanks for your help!
Mar 10, 2006 at 4:54 PM
originally posted by: RolandLi

View the code then I know your problems.
The ModuleController in fact is a workItem controller.
So it doesn't exist until you created the workItem,
The workItem creates the ModuleController , that's the right sequence.
You should put your code in the Module Class because it will have be created after the Shell Load the Module's dll.

I think the Class Name "ModuleController" is a little misleading .
Mar 11, 2006 at 2:12 AM
originally posted by: GiriT


I am intrigued as to why you created another modulecontroller and not just a specific workitem class that derives from workitem. I was thinking along the lines of a modulecontroller being there really to perform the "setup" of the module and that fact that it is wrapped inside a workitem itself is really just to separate the workitem plumbing from the code you add yourself for the specific module (services, menu configuration, toolbar configuration, views and command handlers)... maybe your approach is more common in which case I'd be interested in hearing peoples thoughts..