Example #1
0
        /// <summary> Add a new metadata template element configuration to this class </summary>
        /// <param name="Type"> The 'type' value used in the template configuration files
        ///  to select this metadata template element </param>
        /// <param name="Subtype"> The 'subtype' value used in the template configuration files
        ///  to select this metadata template element </param>
        /// <param name="Class"> Fully qualified (including namespace) name of the class used
        /// for this template element </param>
        /// <param name="Assembly"> Name of the assembly within which this class resides, unless this
        /// is one of the default elements included in the core code </param>
        /// <returns> Built and added <see cref="TemplateElementConfig" /> object </returns>
        public TemplateElementConfig Add_Element(string Type, string Subtype, string Class, string Assembly)
        {
            // Ensure the dictionary is built
            if (elementDictionary == null)
            {
                elementDictionary = new Dictionary <string, TemplateElementConfig>(StringComparer.OrdinalIgnoreCase);
            }

            // Does the element dictionary match the current elements list?
            if (elementDictionary.Count != Elements.Count)
            {
                foreach (TemplateElementConfig existing in Elements)
                {
                    if (!String.IsNullOrEmpty(existing.Subtype))
                    {
                        elementDictionary[existing.Type + "|" + existing.Subtype] = existing;
                    }
                    else
                    {
                        elementDictionary[existing.Type] = existing;
                    }
                }
            }

            // Create the dictionary match key
            string key = Type;

            if (!String.IsNullOrEmpty(Subtype))
            {
                key = Type + "|" + Subtype;
            }

            // Does this already exist?
            if (elementDictionary.ContainsKey(key))
            {
                // Already exists
                TemplateElementConfig existing = elementDictionary[key];
                existing.Type     = Type;
                existing.Subtype  = Subtype;
                existing.Assembly = Assembly;
                existing.Class    = Class;
                return(existing);
            }


            // New, so add it
            TemplateElementConfig newElement = new TemplateElementConfig
            {
                Type     = Type,
                Subtype  = Subtype,
                Assembly = Assembly,
                Class    = Class
            };

            Elements.Add(newElement);
            elementDictionary[key] = newElement;

            // Return the newly built element
            return(newElement);
        }
Example #2
0
        /// <summary> Add a new metadata template element configuration to this class </summary>
        public void Add_Element(TemplateElementConfig NewElement)
        {
            // Ensure the dictionary is built
            if (elementDictionary == null)
            {
                elementDictionary = new Dictionary <string, TemplateElementConfig>(StringComparer.OrdinalIgnoreCase);
            }

            // Does the element dictionary match the current elements list?
            if (elementDictionary.Count != Elements.Count)
            {
                foreach (TemplateElementConfig existing in Elements)
                {
                    if (!String.IsNullOrEmpty(existing.Subtype))
                    {
                        elementDictionary[existing.Type + "|" + existing.Subtype] = existing;
                    }
                    else
                    {
                        elementDictionary[existing.Type] = existing;
                    }
                }
            }

            // Create the dictionary match key
            string key = NewElement.Type;

            if (!String.IsNullOrEmpty(NewElement.Subtype))
            {
                key = NewElement.Type + "|" + NewElement.Subtype;
            }

            // Does this already exist?  If so, remove it
            if (elementDictionary.ContainsKey(key))
            {
                // Already exists
                if (Elements.Contains(elementDictionary[key]))
                {
                    Elements.Remove(elementDictionary[key]);
                }
            }

            // New, so add it
            Elements.Add(NewElement);
            elementDictionary[key] = NewElement;
        }
        /// <summary> Add a new metadata template element configuration to this class </summary>
        public void Add_Element(TemplateElementConfig NewElement )
        {
            // Ensure the dictionary is built
            if (elementDictionary == null)
                elementDictionary = new Dictionary<string, TemplateElementConfig>(StringComparer.OrdinalIgnoreCase);

            // Does the element dictionary match the current elements list?
            if (elementDictionary.Count != Elements.Count)
            {
                foreach (TemplateElementConfig existing in Elements)
                {
                    if (!String.IsNullOrEmpty(existing.Subtype))
                        elementDictionary[existing.Type + "|" + existing.Subtype] = existing;
                    else
                        elementDictionary[existing.Type] = existing;
                }
            }

            // Create the dictionary match key
            string key = NewElement.Type;
            if (!String.IsNullOrEmpty(NewElement.Subtype))
                key = NewElement.Type + "|" + NewElement.Subtype;

            // Does this already exist?  If so, remove it
            if (elementDictionary.ContainsKey(key))
            {
                // Already exists
                if (Elements.Contains(elementDictionary[key]))
                    Elements.Remove(elementDictionary[key]);
            }

            // New, so add it
            Elements.Add(NewElement);
            elementDictionary[key] = NewElement;
        }
        /// <summary> Add a new metadata template element configuration to this class </summary>
        /// <param name="Type"> The 'type' value used in the template configuration files
        ///  to select this metadata template element </param>
        /// <param name="Subtype"> The 'subtype' value used in the template configuration files
        ///  to select this metadata template element </param>
        /// <param name="Class"> Fully qualified (including namespace) name of the class used 
        /// for this template element </param>
        /// <param name="Assembly"> Name of the assembly within which this class resides, unless this
        /// is one of the default elements included in the core code </param>
        /// <returns> Built and added <see cref="TemplateElementConfig" /> object </returns>
        public TemplateElementConfig Add_Element(string Type, string Subtype, string Class, string Assembly)
        {
            // Ensure the dictionary is built
            if (elementDictionary == null)
                elementDictionary = new Dictionary<string, TemplateElementConfig>(StringComparer.OrdinalIgnoreCase);

            // Does the element dictionary match the current elements list?
            if (elementDictionary.Count != Elements.Count)
            {
                foreach (TemplateElementConfig existing in Elements)
                {
                    if (!String.IsNullOrEmpty(existing.Subtype))
                        elementDictionary[existing.Type + "|" + existing.Subtype] = existing;
                    else
                        elementDictionary[existing.Type] = existing;
                }
            }

            // Create the dictionary match key
            string key = Type;
            if (!String.IsNullOrEmpty(Subtype))
                key = Type + "|" + Subtype;

            // Does this already exist?
            if (elementDictionary.ContainsKey(key))
            {
                // Already exists
                TemplateElementConfig existing = elementDictionary[key];
                existing.Type = Type;
                existing.Subtype = Subtype;
                existing.Assembly = Assembly;
                existing.Class = Class;
                return existing;
            }

            // New, so add it
            TemplateElementConfig newElement = new TemplateElementConfig
            {
                Type = Type,
                Subtype = Subtype,
                Assembly = Assembly,
                Class = Class
            };
            Elements.Add(newElement);
            elementDictionary[key] = newElement;

            // Return the newly built element
            return newElement;
        }
        private static bool read_template_elements_details(XmlReader ReaderXml, InstanceWide_Configuration Config)
        {
            bool errorEncountered = false;

            try
            {
                while (ReaderXml.Read())
                {
                    if (ReaderXml.NodeType == XmlNodeType.Element)
                    {
                        switch (ReaderXml.Name.ToLower())
                        {
                            case "clearall":
                                Config.UI.TemplateElements.Clear();
                                break;

                            case "templateelement":

                                // Build the new template element info
                                TemplateElementConfig newElement = new TemplateElementConfig();
                                if (ReaderXml.MoveToAttribute("type"))
                                    newElement.Type = ReaderXml.Value.Trim().ToLower();
                                if (ReaderXml.MoveToAttribute("subtype"))
                                    newElement.Subtype = ReaderXml.Value.Trim().ToLower();
                                if (ReaderXml.MoveToAttribute("assembly"))
                                    newElement.Assembly = ReaderXml.Value.Trim();
                                if (ReaderXml.MoveToAttribute("class"))
                                    newElement.Class = ReaderXml.Value.Trim();
                                if (ReaderXml.MoveToAttribute("image"))
                                    newElement.Image = ReaderXml.Value.Trim();
                                if (ReaderXml.MoveToAttribute("adminUri"))
                                    newElement.AdminUri = ReaderXml.Value.Trim();
                                if (ReaderXml.MoveToAttribute("helpUri"))
                                    newElement.HelpUri = ReaderXml.Value.Trim();

                                // add if the minimum requirements are met
                                if ((!String.IsNullOrEmpty(newElement.Type)) && (!String.IsNullOrEmpty(newElement.Class)))
                                    Config.UI.TemplateElements.Add_Element(newElement);

                                break;

                        }
                    }
                }
            }
            catch (Exception ee)
            {
                Config.Source.Add_Log("EXCEPTION CAUGHT in Configuration_Files_Reader.read_template_elements_details");
                Config.Source.Add_Log(ee.Message);
                Config.Source.Add_Log(ee.StackTrace);

                Config.Source.ErrorEncountered = true;
                errorEncountered = true;
            }

            // If there was an error while reading, use the system defaults
            if (errorEncountered)
            {
                Config.Metadata.Clear();
                Config.Metadata.Set_Default_Values();
            }

            return !errorEncountered;
        }