Paulo Morgado

.NET Development & Architecture

Test Content

<p>Test</p>

This Blog

Syndication

Search

Sponsored By

Tags

Visitor Locations

<p><a href="http://www4.clustrmaps.com/counter/maps.php?url=http://PauloMorgado.NET/Blogs/EN" title="Visitor Locations"><img src="http://www4.clustrmaps.com/counter/index2.php?url=http://PauloMorgado.NET/Blogs/EN" alt="Visitor Locations" /></a></p>

News

Unit Test Today! Get Typemock Isolator!

Visitor Locations

Community

Email Notifications

Archives

An Hierarchical CAB WorkItem Activation Service

The application I'm currently working on has a rather complex UI. It's something like two tabbed work spaces and an outlook-like work space, that make one workspace by itself, that can have several instances inside another tabbed workspace, that can have several instances inside another tabbed workspace. Imagine something like Visual Studio, inside a tab.

Each work space is controlled by its own work item and the same goes to every smart part.

With a UI like this, the work item activation service supplied by the CAB is of no use for me because I need to know what is the active work item at various levels.

What I came up with to solve my problem is the following implementation of the work item activation service:

public class HierarchicalWorkItemActivationService : IWorkItemActivationService
{
    private object syncroot = new object();
    private WorkItem activeWorkItem;
    private WorkItem hostingWorkItem;

    public HierarchicalWorkItemActivationService()
    {
    }

    [ServiceDependency]
    public WorkItem HostingWorkItem
    {
        set
        {
            Debug.Assert(value != null);
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            Debug.Assert(this.hostingWorkItem == null);
            if (this.hostingWorkItem != null)
            {
                throw new InvalidOperationException("HostingWorkItem already set.");
            }
            this.hostingWorkItem = value;
        }
    }

    public void ChangeStatus(WorkItem item)
    {
        lock (syncroot)
        {
            if (item == this.hostingWorkItem)
            {
                WorkItem hostingParentWorkItem = this.hostingWorkItem.Parent;
                if (hostingParentWorkItem != null)
                {
                    IWorkItemActivationService parentWorkItemActivationService = hostingParentWorkItem.Services.Get<IWorkItemActivationService>();
                    if (parentWorkItemActivationService != null)
                    {
                        parentWorkItemActivationService.ChangeStatus(this.hostingWorkItem);
                    }
                }
            }
            else
            {
                if (item.Status == WorkItemStatus.Active)
                {
                    if (item != this.activeWorkItem)
                    {
                        if (this.activeWorkItem != null && this.activeWorkItem.Status != WorkItemStatus.Terminated)
                        {
                            this.activeWorkItem.Deactivate();

                            // If the activeWorkItem is still active deactivates the item and aborts.
                            if (this.activeWorkItem.Status == WorkItemStatus.Active)
                            {
                                item.Deactivate();
                                return;
                            }
                        }
                        this.activeWorkItem = item;
                    }
                }
            }
        }
    }
}

Published Sat, Nov 4 2006 23:15 by Paulo Morgado

Comments

# http://gotdotnet.com/codegallery/messageboard/thread.aspx?id=22f72167-af95-44ce-a6ca-f2eafbf2653c&mbid=f095dc16-95cc-4b64-9229-3510390aa521&threadid=659e5f07-bd06-42d1-aee2-e113802ba1e7@ Thursday, November 09, 2006 5:45 PM

TrackBack

# re: An Hierarchical CAB WorkItem Activation Service@ Friday, June 01, 2007 7:46 AM

and how do you use this beauty?

olivier

# re: An Hierarchical CAB WorkItem Activation Service@ Friday, June 01, 2007 9:41 AM

Suppose you have a WorkItem wiA and you want to track its active child work items (wiA1, wiA2, wiA3, ...).

To do that, you must register this service in wiA and the activation of its children will be controlled by this service independently of the other work items.

Paulo Morgado

# re: An Hierarchical CAB WorkItem Activation Service@ Wednesday, June 13, 2007 2:36 PM

This works great! All your posts on CAB/SCSF are very informative, hope to see more in the future, thanks Paulo!

steve

# re: An Hierarchical CAB WorkItem Activation Service@ Wednesday, June 13, 2007 6:20 PM

Thanks Steve.

Paulo Morgado

# re: An Hierarchical CAB WorkItem Activation Service@ Thursday, July 26, 2007 10:07 AM

Your blogs are great and need a word of appreciation. Keep up the good work.

What I understand from the case discussed here is the need to have a hierarchy of Workitems to be tracked as Active at the same time?

I have two queries to know the need for the same:

1. Why would we need to have a workitem for every Workspace and Smart Part that we create? As per the MS P&P we are supposed to create a workitem per UseCase, and the workspaces which are generally shared between the modules are added to the rootworkitem.

2. In a hierarchy of Workitems like

Root->Child1->GrandChild2->GrandGrandChild3 if GrandGrandChild3 is Active, we can comprehend the complete hierarchy to be Active? How different is this scenario?

Hope I am not asking too silly queries......as I have just jumped into SCSF and am relatively new.

C.R.Parameshwaran

# re: An Hierarchical CAB WorkItem Activation Service@ Thursday, July 26, 2007 7:45 PM

Thank you for your kind words, Parameshwaran.

Yes. Take Outlook as an example. You have the left Outlook bar where you have one item selected. Each of that items have items themselves that might be selected (a folder in the folder list, a day or week in the calendar, etc.) and for a particular forlder you have one e-mail selected.

1. There's no mandatory need to have one work item for every smart part, but nothing forbides you from having just one smart part for work item.

2. With the CAB/SCSF provided activation service you have only one active work item. So, if GrandGrandChild3 is active no other work item is active, not even Root, Child1 or GrandChild2 are active.

Feel free to ask more questions, but there's an active community and team members at http://www.codeplex.com/smartclient/Project/ListForums.aspx.

Paulo Morgado

# ControlActivationService and SimpleWorkItemActivationService@ Tuesday, July 22, 2008 4:16 PM

ControlActivationService and SimpleWorkItemActivationService

Notes

Leave a Comment

(required) 
(required) 
(optional)
(required)