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
        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 #4
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);
                }
            }
        }