Beispiel #1
0
        public override void Parse(XElement definition)
        {
            ChildrenAreUnique = TryParseBool(definition, "ChildrenAreUnique");
            Collapse          = TryParseBool(definition, "Collapse");
            Seperator         = definition.Attribute("Seperator")?.Value;
            if (Seperator == null)
            {
                Seperator = ",";
            }

            MinCount = TryParseInt(definition, "MinCount", 0);
            MaxCount = TryParseInt(definition, "MaxCount", int.MaxValue);

            var currentGroup = "Items";

            var childDefs = definition.Nodes();

            foreach (var childDef in childDefs)
            {
                if (childDef is XComment)
                {
                    currentGroup = (childDef as XComment).Value;
                }
                else if (childDef is XElement)
                {
                    var xel = childDef as XElement;
                    if (xel.Name == "Attributes" || xel.Name == "AdditionalDefs")
                    {
                        continue;
                    }

                    var cdef = new CollectionChildDefinition();
                    cdef.Parse(xel);

                    ChildDefinitions.Add(cdef);
                    Keys.Add(new Tuple <CollectionChildDefinition, string>(cdef, currentGroup));
                }
            }

            if (ChildDefinitions.Count == 0)
            {
                throw new Exception("No child definitions in collection '" + Name + "'!");
            }

            var addEls = definition.Element("AdditionalDefs");

            if (addEls != null)
            {
                foreach (var addEl in addEls.Elements())
                {
                    var addDef = LoadDefinition(addEl);
                    AdditionalDefs.Add(addDef);
                }
            }
        }
        public override void Parse(XElement definition)
        {
            ChildrenAreUnique = TryParseBool(definition, "ChildrenAreUnique");

            MinCount = TryParseInt(definition, "MinCount", 0);
            MaxCount = TryParseInt(definition, "MaxCount", int.MaxValue);

            AllowReferenceLinks = TryParseBool(definition, "AllowReferenceLinks", true);
            AllowCircularLinks  = TryParseBool(definition, "AllowCircularLinks", false);
            FlattenData         = TryParseBool(definition, "FlattenData", false);
            NodeStoreName       = definition.Attribute("NodeStoreName")?.Value?.ToString() ?? "Nodes";

            var backgroundCol = definition.Attribute("Background")?.Value?.ToString();

            if (backgroundCol != null)
            {
                var split = backgroundCol.Split(new char[] { ',' });

                byte r = 0;
                byte g = 0;
                byte b = 0;
                byte a = 0;

                byte.TryParse(split[0], out r);
                byte.TryParse(split[1], out g);
                byte.TryParse(split[2], out b);
                byte.TryParse(split[3], out a);

                var col = Color.FromArgb(a, r, g, b);
                Background = new SolidColorBrush(col);
                Background.Freeze();
            }

            var currentGroup = "Items";

            var childDefs = definition.Nodes();

            foreach (var childDef in childDefs)
            {
                if (childDef is XComment)
                {
                    currentGroup = (childDef as XComment).Value;
                }
                else if (childDef is XElement)
                {
                    var xel = childDef as XElement;
                    if (xel.Name == "Attributes")
                    {
                        continue;
                    }

                    var cdef = new CollectionChildDefinition();
                    cdef.Parse(xel);

                    ChildDefinitions.Add(cdef);
                    Keys.Add(new Tuple <CollectionChildDefinition, string>(cdef, currentGroup));
                }
            }

            if (ChildDefinitions.Count == 0)
            {
                throw new Exception("No child definitions in collection '" + Name + "'!");
            }
        }
Beispiel #3
0
        protected override void DoRecursivelyResolve(Dictionary <string, DataDefinition> local, Dictionary <string, DataDefinition> global, Dictionary <string, Dictionary <string, DataDefinition> > referenceableDefinitions)
        {
            if (DefKey != null)
            {
                var key = DefKey.ToLower();

                Dictionary <string, DataDefinition> defs = null;
                if (local.ContainsKey(key))
                {
                    defs = local;
                }
                else if (global.ContainsKey(key))
                {
                    defs = global;
                }

                if (defs != null)
                {
                    var def = defs[key] as ReferenceDefinition;

                    foreach (var keydef in def.Keys)
                    {
                        var childDef        = def.Definitions[keydef.Item1];
                        var childWrapperDef = new CollectionChildDefinition();
                        childWrapperDef.WrappedDefinition = childDef;

                        ChildDefinitions.Add(childWrapperDef);
                        Keys.Add(new Tuple <CollectionChildDefinition, string>(childWrapperDef, keydef.Item2));
                    }
                }
                else
                {
                    throw new Exception("Failed to find key " + DefKey + "!");
                }
            }

            foreach (var key in DefKeys)
            {
                Dictionary <string, DataDefinition> defs = null;
                if (local.ContainsKey(key.Item1.ToLower()))
                {
                    defs = local;
                }
                else if (global.ContainsKey(key.Item1.ToLower()))
                {
                    defs = global;
                }

                if (defs != null)
                {
                    var childDef        = defs[key.Item1.ToLower()];
                    var childWrapperDef = new CollectionChildDefinition();
                    childWrapperDef.WrappedDefinition = childDef;

                    ChildDefinitions.Add(childWrapperDef);
                    Keys.Add(new Tuple <CollectionChildDefinition, string>(childWrapperDef, key.Item2));
                }
                else if (key.Item1 != "---")
                {
                    throw new Exception("Failed to find key " + key.Item1 + "!");
                }
            }

            foreach (var def in ChildDefinitions)
            {
                def.WrappedDefinition.RecursivelyResolve(local, global, referenceableDefinitions);
            }
        }
Beispiel #4
0
        public override void Parse(XElement definition)
        {
            ChildrenAreUnique = TryParseBool(definition, "ChildrenAreUnique");

            MinCount = TryParseInt(definition, "MinCount", 0);
            MaxCount = TryParseInt(definition, "MaxCount", int.MaxValue);

            AllowReferenceLinks = TryParseBool(definition, "AllowReferenceLinks", true);
            AllowCircularLinks  = TryParseBool(definition, "AllowCircularLinks", false);
            FlattenData         = TryParseBool(definition, "FlattenData", false);
            NodeStoreName       = definition.Attribute("NodeStoreName")?.Value?.ToString() ?? "Nodes";

            var backgroundCol = definition.Attribute("Background")?.Value?.ToString();

            if (backgroundCol != null)
            {
                var split = backgroundCol.Split(new char[] { ',' });

                byte r = 0;
                byte g = 0;
                byte b = 0;
                byte a = 0;

                byte.TryParse(split[0], out r);
                byte.TryParse(split[1], out g);
                byte.TryParse(split[2], out b);
                if (split.Length == 4)
                {
                    byte.TryParse(split[3], out a);
                }
                else
                {
                    a = 75;
                }

                var col = Color.FromArgb(a, r, g, b);
                Background = new SolidColorBrush(col);
                Background.Freeze();
            }

            var currentGroup = "Items";

            DefKey = definition.Attribute("DefKey")?.Value?.ToString();
            var keyString = definition.Attribute("Keys")?.Value?.ToString();

            if (!string.IsNullOrWhiteSpace(keyString))
            {
                if (!keyString.Contains('('))
                {
                    DefKeys.AddRange(keyString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(e => new Tuple <string, string>(e.Trim(), "Type")));
                }
                else
                {
                    var categories = keyString.Split(new char[] { ')' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var categoryString in categories)
                    {
                        var split    = categoryString.Split('(');
                        var category = split[0].Trim();
                        if (category.StartsWith(","))
                        {
                            category = category.Substring(1);
                        }
                        DefKeys.AddRange(split[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(e => new Tuple <string, string>(e.Trim(), category)));
                    }
                }
            }

            var childDefs = definition.Nodes();

            foreach (var childDef in childDefs)
            {
                if (childDef is XComment)
                {
                    currentGroup = (childDef as XComment).Value;
                }
                else if (childDef is XElement)
                {
                    var xel = childDef as XElement;
                    if (xel.Name == "Attributes")
                    {
                        continue;
                    }

                    var cdef = new CollectionChildDefinition();
                    cdef.Parse(xel);

                    ChildDefinitions.Add(cdef);
                    Keys.Add(new Tuple <CollectionChildDefinition, string>(cdef, currentGroup));
                }
            }

            if (ChildDefinitions.Count == 0 && DefKey == null && DefKeys.Count == 0)
            {
                throw new Exception("No child definitions in collection '" + Name + "'!");
            }
        }
Beispiel #5
0
        public override void Parse(XElement definition)
        {
            ChildrenAreUnique = TryParseBool(definition, "ChildrenAreUnique");
            Collapse          = TryParseBool(definition, "Collapse");
            Seperator         = definition.Attribute("Seperator")?.Value;
            if (Seperator == null)
            {
                Seperator = ",";
            }

            MinCount = TryParseInt(definition, "MinCount", 0);
            MaxCount = TryParseInt(definition, "MaxCount", int.MaxValue);

            DefKey = definition.Attribute("DefKey")?.Value?.ToString();
            var keyString = definition.Attribute("Keys")?.Value?.ToString();

            if (!string.IsNullOrWhiteSpace(keyString))
            {
                if (!keyString.Contains('('))
                {
                    DefKeys.AddRange(keyString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(e => new Tuple <string, string>(e.Trim(), "Type")));
                }
                else
                {
                    var categories = keyString.Split(new char[] { ')' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var categoryString in categories)
                    {
                        var split    = categoryString.Split('(');
                        var category = split[0].Trim();
                        if (category.StartsWith(","))
                        {
                            category = category.Substring(1);
                        }
                        DefKeys.AddRange(split[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(e => new Tuple <string, string>(e.Trim(), category)));
                    }
                }
            }

            var currentGroup = "Items";

            var childDefs = definition.Nodes();

            foreach (var childDef in childDefs)
            {
                if (childDef is XComment)
                {
                    currentGroup = (childDef as XComment).Value;
                }
                else if (childDef is XElement)
                {
                    var xel = childDef as XElement;
                    if (xel.Name == "Attributes" || xel.Name == "AdditionalDefs")
                    {
                        continue;
                    }

                    var cdef = new CollectionChildDefinition();
                    cdef.Parse(xel);

                    ChildDefinitions.Add(cdef);
                    Keys.Add(new Tuple <CollectionChildDefinition, string>(cdef, currentGroup));
                }
            }

            if (ChildDefinitions.Count == 0 && DefKey == null && DefKeys.Count == 0)
            {
                throw new Exception("No child definitions in collection '" + Name + "'!");
            }

            var addEls = definition.Element("AdditionalDefs");

            if (addEls != null)
            {
                foreach (var addEl in addEls.Elements())
                {
                    var addDef = LoadDefinition(addEl);
                    AdditionalDefs.Add(addDef);
                }
            }
        }