Example #1
0
        private static void LoadStyleCollection(StyleCollection collection, String xmlFilename)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(xmlFilename);

            XmlNode root = null;

            foreach (XmlNode node in doc.ChildNodes)
            {
                if (node.Name == "Style")
                {
                    root = node;
                    break;
                }
            }

            Dictionary <String, bool> loadedStyles = new Dictionary <string, bool>();

            foreach (var obj in collection.AllStyles)
            {
                loadedStyles[obj.Name] = false;
            }

            var allStyles = new List <StyleObject>(collection.AllStyles);

            foreach (XmlNode node in root.ChildNodes)
            {
                StyleObject match = allStyles.Find(styleObject => styleObject.Name.ToLower() == node.Name.ToLower());

                if (match != null)
                {
                    LoadStyle(match, node);
                    loadedStyles[match.Name] = true;
                }
            }

            foreach (StyleObject obj in collection.AllStyles)
            {
                if (!loadedStyles[obj.Name])
                {
                    throw new ApplicationException("Failed to load some sections from style file");
                }
            }
        }
Example #2
0
        private static void LoadStyle(StyleObject obj, XmlNode xml)
        {
            Dictionary <String, bool> loadedFields = new Dictionary <string, bool>();

            foreach (var val in obj.Properties)
            {
                loadedFields[val.Key] = false;
            }

            var allProps = new List <KeyValuePair <String, StylePropertyType> >(obj.Properties);

            foreach (XmlNode subEl in xml.ChildNodes)
            {
                var found = allProps.Find(rec => rec.Key == subEl.Name);

                if (found.Value == StylePropertyType.propMaterial)
                {
                    obj.SetProperty(found.Key, LoadMaterialParameter(subEl));
                }
                else if (found.Value == StylePropertyType.propDouble)
                {
                    obj.SetProperty(found.Key, LoadDoubleParameter(subEl));
                }
                else
                {
                    throw new ApplicationException("Internal error - unknown section in style file");
                }

                loadedFields[found.Key] = true;
            }

            foreach (var val in loadedFields.Values)
            {
                if (!val)
                {
                    throw new ApplicationException("Internal error - failed to load some section");
                }
            }
        }