Click here to Skip to main content
15,881,424 members
Articles / Desktop Programming / Windows Forms

Microsoft patterns & practices Composite UI Application Block (CAB) based Module Composite Mapper Service: An XML Configurable Builder for Workspaces, UIElements, Commands, and Event Publications/Subscriptions

Rate me:
Please Sign up or sign in to vote.
4.51/5 (17 votes)
30 Mar 2006CPOL16 min read 114.7K   1.1K   101  
A Microsoft patterns & practices Composite UI Application Block (CAB) based module composite mapper service is provided including C# source code that builds Workspaces, UIElements, Commands and Event Publications/Subscriptions using an XML configuration file specified with a module.
using System;
using System.Collections; 
using System.Collections.Generic;
using System.Text;

using Microsoft.Practices.CompositeUI.Collections; 
using Microsoft.Practices.CompositeUI.EventBroker;
using XtensibleSolutions.CompositeUI.Extensions; 
using XtensibleSolutions.CompositeUI.Extensions.SmartParts;
using XtensibleSolutions.CompositeUI.Extensions.Utility;

namespace XtensibleSolutions.CompositeUI.Extensions.Services.XSModuleCompMppr
{
    internal sealed class XSEventPubCompMppr   
    {
        private Dictionary<XSEventPubComp, XSEventPubComp> eventPubComps =
            new Dictionary<XSEventPubComp, XSEventPubComp>();

        internal XSEventPubCompMppr() { }

        internal Dictionary<XSEventPubComp, XSEventPubComp> EventPubComps
        {
            get { return eventPubComps; }
        }

        internal void ApplyCompositeMappings(IXSWorkItem thisWorkItem) 
        {
            // cast to XSWorkItem for property access and publication 
            XSWorkItem workItem = (XSWorkItem)thisWorkItem;
            // events are managed at the same-level WorkItem but 
            // are broadcast/received according to PublicationScopeEnum
            ManagedObjectCollection<EventTopic> events =
                workItem.EventTopics;
            foreach (XSEventPubComp eventPubComp in eventPubComps.Keys)
            {
                if (eventPubComp.PublisherTypeEnum == XSEventPubSubType.WorkItem)
                {
                    // accesses an existing Event, or a new one if there is not one 
                    // already present (the Get method does this automatically)
                    events[eventPubComp.EventTopic].AddPublication(
                        workItem, 
                        eventPubComp.PublicationHandlerName,
                        workItem,
                        eventPubComp.PublicationScopeEnum);
                }
            }
        }

        internal void ApplyCompositeMappings(IXSPresenter thisPresenter) 
        {
            XSWorkItem workItem = thisPresenter.WorkItem;
            // events are managed at the same-level WorkItem but 
            // are broadcast/received according to PublicationScopeEnum
            ManagedObjectCollection<EventTopic> events =
                workItem.EventTopics; 
            foreach (XSEventPubComp eventPubComp in eventPubComps.Keys)
            {
                if (eventPubComp.PublisherTypeEnum == XSEventPubSubType.Presenter)
                {
                    // accesses an existing Event, or a new one if there is not one 
                    // already present (the Get method does this automatically)
                    events[eventPubComp.EventTopic].AddPublication(
                        thisPresenter, 
                        eventPubComp.PublicationHandlerName,
                        workItem, 
                        eventPubComp.PublicationScopeEnum); 
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Tom Polanski, Senior Analyst
Homeland Security Team, Toyon Research Corporation

Toyon Research Corporation provides innovative solutions to national challenges with technical analyses, research and development.

Comments and Discussions