Exemplo n.º 1
0
        private static void LoadModulesFromXml(Dictionary<string, ModuleDefinition> modules, string path)
        {
            // open xml document
            XmlDocument xml = new XmlDocument();
            xml.Load(path);

            // select nodes
            XmlNodeList xmlModules = xml.SelectNodes("ModuleDefinitions/ModuleDefinition");
            foreach (XmlNode xmlModule in xmlModules)
            {
                ModuleDefinition module = new ModuleDefinition();
                if (xmlModule.Attributes["id"] == null)
                    throw new Exception(String.Format("Module ID is not specified. File: {0}, Node: {1}",
                        path, xmlModule.OuterXml));

				module.Id = xmlModule.Attributes["id"].Value.ToLower(CultureInfo.InvariantCulture);
                modules.Add(module.Id, module);
                
                // controls
                XmlNodeList xmlControls = xmlModule.SelectNodes("Controls/Control");
                foreach (XmlNode xmlControl in xmlControls)
                {
                    ModuleControl control = new ModuleControl();
                    if (xmlControl.Attributes["icon"] != null)
                        control.IconFile = xmlControl.Attributes["icon"].Value;

                    if(xmlControl.Attributes["key"] != null)
						control.Key = xmlControl.Attributes["key"].Value.ToLower(CultureInfo.InvariantCulture);

                    if (xmlControl.Attributes["src"] == null)
                        throw new Exception(String.Format("Control 'src' is not specified. File: {0}, Node: {1}",
                            path, xmlControl.ParentNode.OuterXml));
                    control.Src = xmlControl.Attributes["src"].Value;

                    if (xmlControl.Attributes["title"] == null)
                        throw new Exception(String.Format("Control 'title' is not specified. File: {0}, Node: {1}",
                            path, xmlControl.ParentNode.OuterXml));
                    control.Title = xmlControl.Attributes["title"].Value;

                    if (xmlControl.Attributes["type"] != null)
                        control.ControlType = (ModuleControlType)Enum.Parse(typeof(ModuleControlType), xmlControl.Attributes["type"].Value, true);
                    else
                        control.ControlType = ModuleControlType.View;

                    if (String.IsNullOrEmpty(control.Key))
                        module.DefaultControl = control;

                    module.Controls.Add(control.Key, control);
                }
            }
        }