Exemple #1
0
        /// <summary> Loads the resources into the control's properties. </summary>
        protected override void LoadResources(IResourceManager resourceManager, IGlobalizationService globalizationService)
        {
            ArgumentUtility.CheckNotNull("resourceManager", resourceManager);
            ArgumentUtility.CheckNotNull("globalizationService", globalizationService);

            if (IsDesignMode)
            {
                return;
            }

            base.LoadResources(resourceManager, globalizationService);

            var key = ResourceManagerUtility.GetGlobalResourceKey(NullItemErrorMessage);

            if (!string.IsNullOrEmpty(key))
            {
                NullItemErrorMessage = resourceManager.GetString(key);
            }

            key = ResourceManagerUtility.GetGlobalResourceKey(OptionsTitle);
            if (!string.IsNullOrEmpty(key))
            {
                OptionsTitle = resourceManager.GetString(key);
            }

            if (Command != null)
            {
                Command.LoadResources(resourceManager, globalizationService);
            }

            OptionsMenuItems.LoadResources(resourceManager, globalizationService);
        }
Exemple #2
0
        /// <summary> Dispatches the resources passed in <paramref name="values"/> to the control's properties. </summary>
        /// <param name="values"> An <c>IDictonary</c>: &lt;string key, string value&gt;. </param>
        protected virtual void Dispatch(IDictionary values)
        {
            HybridDictionary optionsMenuItemValues = new HybridDictionary();
            HybridDictionary propertyValues        = new HybridDictionary();
            HybridDictionary commandValues         = new HybridDictionary();

            //  Parse the values

            foreach (DictionaryEntry entry in values)
            {
                string   key      = (string)entry.Key;
                string[] keyParts = key.Split(new[] { ':' }, 3);

                //  Is a property/value entry?
                if (keyParts.Length == 1)
                {
                    string property = keyParts[0];
                    propertyValues.Add(property, entry.Value);
                }
                //  Is compound element entry
                else if (keyParts.Length == 2)
                {
                    //  Compound key: "elementID:property"
                    string elementID = keyParts[0];
                    string property  = keyParts[1];

                    //  Switch to the right collection
                    switch (elementID)
                    {
                    case c_resourceKeyCommand:
                    {
                        commandValues.Add(property, entry.Value);
                        break;
                    }

                    default:
                    {
                        //  Invalid collection property
                        s_log.Debug(
                            GetType().Name + " '" + ID + "' in naming container '" + NamingContainer.GetType().FullName + "' on page '" + Page
                            + "' does not contain an element named '" + elementID + "'.");
                        break;
                    }
                    }
                }
                //  Is collection entry?
                else if (keyParts.Length == 3)
                {
                    //  Compound key: "collectionID:elementID:property"
                    string collectionID = keyParts[0];
                    string elementID    = keyParts[1];
                    string property     = keyParts[2];

                    IDictionary currentCollection = null;

                    //  Switch to the right collection
                    switch (collectionID)
                    {
                    case c_resourceKeyOptionsMenuItems:
                    {
                        currentCollection = optionsMenuItemValues;
                        break;
                    }

                    default:
                    {
                        //  Invalid collection property
                        s_log.Debug(
                            GetType().Name + " '" + ID + "' in naming container '" + NamingContainer.GetType().FullName + "' on page '" + Page
                            + "' does not contain a collection property named '" + collectionID + "'.");
                        break;
                    }
                    }

                    //  Add the property/value pair to the collection
                    if (currentCollection != null)
                    {
                        //  Get the dictonary for the current element
                        IDictionary elementValues = (IDictionary)currentCollection[elementID];

                        //  If no dictonary exists, create it and insert it into the elements hashtable.
                        if (elementValues == null)
                        {
                            elementValues = new HybridDictionary();
                            currentCollection[elementID] = elementValues;
                        }

                        //  Insert the argument and resource's value into the dictonary for the specified element.
                        elementValues.Add(property, entry.Value);
                    }
                }
                else
                {
                    //  Not supported format or invalid property
                    s_log.Debug(
                        GetType().Name + " '" + ID + "' in naming container '" + NamingContainer.GetType().FullName + "' on page '" + Page
                        + "' received a resource with an invalid or unknown key '" + key
                        + "'. Required format: 'property' or 'collectionID:elementID:property'.");
                }
            }

            //  Dispatch simple properties
            ResourceDispatcher.DispatchGeneric(this, propertyValues);

            //  Dispatch compound element properties
            if (Command != null)
            {
                ResourceDispatcher.DispatchGeneric(Command, commandValues);
            }

            //  Dispatch to collections
            OptionsMenuItems.Dispatch(optionsMenuItemValues, this, "OptionsMenuItems");
        }