Exemple #1
0
 public virtual void prepareData()
 {
     if (MoodleXmlElementAttribute.get(this.GetType()).HasFiles)
     {
         var images = this.HtmlNode.Descendants("img");
         foreach (HtmlNode img in images)
         {
             FileElement file = new FileElement();
             file.HtmlNode = img;
             this.FileElements.Add(file);
         }
     }
 }
Exemple #2
0
        private bool notifyRelatedElementProperties(Type parentType, MoodleXmlElement parentElement, MoodleXmlElement child)
        {
            PropertyInfo[] properties = parentType.GetProperties();
            bool           found      = false;

            foreach (PropertyInfo property in properties)
            {
                MoodleXmlElementAttribute xmlAttributes = MoodleXmlElementAttribute.get(property);

                if (xmlAttributes != null && xmlAttributes.Children == true)
                {
                    List <MoodleXmlElement> includedElements = (List <MoodleXmlElement>)property.GetValue(parentElement);
                    includedElements.Add(child);
                    found = true;
                    break;
                }
            }

            return(found);
        }
Exemple #3
0
        public virtual XmlElement toXml(XmlDocument doc)
        {
            this.doc = doc;
            this.prepareData();

            Type thisType = this.GetType();

            string thisElementNodeName = MoodleXmlElementAttribute.get(thisType).Name.ToLower();

            this.xmlElement = doc.CreateElement(thisElementNodeName);
            PropertyInfo[] thisProperties = thisType.GetProperties();

            foreach (PropertyInfo thisProperty in thisProperties)
            {
                if (Attribute.IsDefined(thisProperty, typeof(MoodleXmlElementAttribute)))
                {
                    MoodleXmlElementAttribute thisPropertyAttribute = MoodleXmlElementAttribute.get(thisProperty);
                    this.reactToAttribute(thisPropertyAttribute, thisProperty);
                }
            }
            return(this.xmlElement);
        }
Exemple #4
0
        private void reactToAttribute(MoodleXmlElementAttribute attribute, PropertyInfo property)
        {
            if (attribute.Attr)
            {
                this.xmlElement.SetAttribute(property.Name.ToLower(), property.GetValue(this).ToString());
            }

            if (attribute.Children)
            {
                List <MoodleXmlElement> children = (List <MoodleXmlElement>)property.GetValue(this);
                foreach (MoodleXmlElement child in children)
                {
                    if (child != null)
                    {
                        XmlElement el = child.toXml(this.doc);

                        if (el != null)
                        {
                            this.xmlElement.AppendChild(el);
                        }
                    }
                }
            }

            if (attribute.Node)
            {
                MoodleXmlElement childNode = (MoodleXmlElement)property.GetValue(this);
                this.xmlElement.AppendChild(childNode.toXml(this.doc));
            }

            if (attribute.Content)
            {
                Text            textElement = (Text)this;
                XmlCDataSection cdata       = this.doc.CreateCDataSection(textElement.Content);

                this.xmlElement.AppendChild(cdata);
            }
        }