Ejemplo n.º 1
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 tabValues      = new HybridDictionary();
            HybridDictionary propertyValues = 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 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_resourceKeyTabs:
                    {
                        currentCollection = tabValues;
                        break;
                    }

                    default:
                    {
                        //  Invalid collection property
                        s_log.Warn(
                            "WebTabStrip '" + 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.Warn(
                        "WebTabStrip '" + 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 to collections
            Tabs.Dispatch(tabValues, this, "Tabs");
        }