CSharpFeeds - All your C# feeds in one place.

Sponsors

Saturday, November 04, 2006

An Hierarchical CAB WorkItem Activation Service

by Paulo Morgado via Paulo Morgado : C# on 11/4/2006 11:15:34 PM

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;
                    }
                }
            }
        }
    }
}
Share this post: email it! | bookmark it! | digg it! | live it!
email it!bookmark it!digg it!

Original Post: An Hierarchical CAB WorkItem Activation Service

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us