public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var item = new GraphCollectionItem(this, undoRedo);

            item.X       = TryParseFloat(element, MetaNS + "X");
            item.Y       = TryParseFloat(element, MetaNS + "Y");
            item.GUID    = element.Attribute("GUID")?.Value?.ToString();
            item.Comment = element.Attribute(MetaNS + "Comment")?.Value?.ToString();

            foreach (var el in element.Elements())
            {
                var prev = el.PreviousNode as XComment;
                if (prev != null)
                {
                    var comment = new CommentDefinition().LoadData(prev, undoRedo);
                    item.Children.Add(comment);
                }

                var cdef  = ChildDefinitions.FirstOrDefault(e => e.Name == el.Name);
                var child = cdef.LoadData(el, undoRedo);
                item.Children.Add(child);

                if (item.Children.Count == MaxCount)
                {
                    break;
                }
            }

            if (element.LastNode is XComment)
            {
                var comment = new CommentDefinition().LoadData(element.LastNode as XComment, undoRedo);
                item.Children.Add(comment);
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            return(item);
        }
Beispiel #2
0
        public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var item = new CollectionItem(this, undoRedo);

            if (Collapse && ChildDefinitions.Count == 1 && ChildDefinitions[0].WrappedDefinition is PrimitiveDataDefinition)
            {
                var primDef = ChildDefinitions[0].WrappedDefinition as PrimitiveDataDefinition;
                var split   = element.Value.Split(new string[] { Seperator }, StringSplitOptions.None);
                foreach (var s in split)
                {
                    var child = primDef.LoadFromString(s, undoRedo);
                    var citem = ChildDefinitions[0].CreateData(undoRedo) as CollectionChildItem;
                    citem.WrappedItem = child;

                    item.Children.Add(citem);

                    if (item.Children.Count == MaxCount)
                    {
                        break;
                    }
                }
            }
            else
            {
                var uncreatedAdds = AdditionalDefs.ToList();

                foreach (var el in element.Elements())
                {
                    var prev = el.PreviousNode as XComment;
                    if (prev != null)
                    {
                        var comment = new CommentDefinition().LoadData(prev, undoRedo);
                        item.Children.Add(comment);
                    }

                    var cdef = ChildDefinitions.FirstOrDefault(e => e.Name == el.Name);
                    if (cdef != null)
                    {
                        var child = cdef.LoadData(el, undoRedo);
                        item.Children.Add(child);
                    }
                    else
                    {
                        var def = AdditionalDefs.FirstOrDefault(e => e.Name == el.Name);
                        if (def != null)
                        {
                            var child = def.LoadData(el, undoRedo);
                            item.Children.Insert(0, child);

                            uncreatedAdds.Remove(def);
                        }
                        else if (ChildDefinitions.Count == 1)
                        {
                            var child = ChildDefinitions[0].LoadData(el, undoRedo);
                            item.Children.Add(child);
                        }
                        else
                        {
                            throw new Exception("Unable to find def for '" + el.Name + "' in collection '" + Name + "'!");
                        }
                    }
                }

                foreach (var def in uncreatedAdds)
                {
                    var child = def.CreateData(undoRedo);
                    item.Children.Insert(0, child);
                }

                if (element.LastNode is XComment)
                {
                    var comment = new CommentDefinition().LoadData(element.LastNode as XComment, undoRedo);
                    item.Children.Add(comment);
                }
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            return(item);
        }