Exemplo n.º 1
0
        public static OutlineItem LoadFromClipboard()
        {
            if (Clipboard.ContainsText())
            {
                var clipboardText = Clipboard.GetText();

                try
                {
                    var xmlElement = XElement.Parse(clipboardText);

                    var item = OutlineItem.CreateFromXmlElement(xmlElement);

                    return(item);
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(null);

            /*
             * var clipboardAdapter = new OutlineItemCollectionClipboardAdapter();
             * var itemCollection = clipboardAdapter.GetItemCollection();
             *
             * if (itemCollection != null && itemCollection.Count > 0)
             * {
             *  return itemCollection[0];
             * }
             *
             * return null;*/
        }
Exemplo n.º 2
0
        public OutlineItem Clone()
        {
            //Temporary solution. Todo: Implement  copy constructor.

            var thisItemAsXmlElement = ToXmlElement();
            var clone = OutlineItem.CreateFromXmlElement(thisItemAsXmlElement);

            return(clone);
        }
Exemplo n.º 3
0
        public static OutlineDocument CreateFromXmlElement(XElement xmlElement)
        {
            if (xmlElement == null)
            {
                throw new ArgumentNullException(nameof(xmlElement));
            }

            if (xmlElement.Name != "SimpleOutlineDocument")
            {
                throw new DecodingException();
            }

            if (xmlElement.Attributes().Count() > 0)
            {
                throw new DecodingException();
            }

            if (xmlElement.Elements().SingleOrDefault(e => e.Name != "Outline") != null)
            {
                throw new DecodingException();
            }

            if (xmlElement.Elements().SingleOrDefault(e => e.Name == "Outline") == null)
            {
                throw new DecodingException();
            }

            var xmlOutlineElement = xmlElement.Element("Outline");

            if (xmlOutlineElement.Attributes().Count() > 0)
            {
                throw new DecodingException();
            }

            if (xmlOutlineElement.Elements("Item").Count() != 1)
            {
                throw new DecodingException();
            }

            var thisOutlineDocument = new OutlineDocument();

            var rootItemXmlElement = xmlOutlineElement.Element("Item");
            var rootOutlineItem    = OutlineItem.CreateFromXmlElement(rootItemXmlElement);

            thisOutlineDocument.Items[0] = rootOutlineItem;

            return(thisOutlineDocument);
        }
Exemplo n.º 4
0
        public static OutlineItem CreateFromXmlElement(XElement xmlElement)
        {
            if (xmlElement == null)
            {
                throw new ArgumentNullException(nameof(xmlElement));
            }

            if (xmlElement.Name != "Item")
            {
                throw new DecodingException();
            }

            if (xmlElement.Attributes().SingleOrDefault(attr => attr.Name == "Name") == null)
            {
                throw new DecodingException();
            }

            if (xmlElement.Attributes().SingleOrDefault(attr => attr.Name != "Name") != null)
            {
                throw new DecodingException();
            }

            if (xmlElement.Elements().SingleOrDefault(elem => elem.Name != "Item") != null)
            {
                throw new DecodingException();
            }

            var thisOutlineItemName = xmlElement.Attribute("Name").Value.ToString();
            var thisOutlineItem     = new OutlineItem(thisOutlineItemName);

            foreach (XElement childOutlineItemXmlElement in xmlElement.Elements("Item"))
            {
                var childOutlineItem = OutlineItem.CreateFromXmlElement(childOutlineItemXmlElement);
                thisOutlineItem.Items.Add(childOutlineItem);
            }

            return(thisOutlineItem);
        }