public static MoodleXmlElement get(HtmlNode node) { MoodleXmlElement result = null; string className = node.Attributes["class"].Value; Type type = Type.GetType(spaceName + className); if (type != null) { result = (MoodleXmlElement)Activator.CreateInstance(type); } return(result); }
private void notifyFirstRelatedElement(MoodleXmlElement child, RelationAttribute relatedTo) { foreach (MoodleXmlElement parentElement in this.moodleXmlElementsStack) { Type parentType = parentElement.GetType(); if (parentType.Equals(relatedTo.To) || parentType.IsSubclassOf(relatedTo.To)) { bool found = this.notifyRelatedElementProperties(parentType, parentElement, child); if (found) { break; } } } }
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); }
private void populateQuizByHtml() { HtmlNodeCollection nodes = this.html.DocumentNode.SelectNodes("//div/p"); foreach (HtmlNode node in nodes) { MoodleXmlElement currentMoodleXmlElement = Factory.get(node); if (currentMoodleXmlElement != null) { currentMoodleXmlElement.HtmlNode = node; Type currentMoodleXmlElementType = currentMoodleXmlElement.GetType(); RelationAttribute ralatedTo = RelationAttribute.get(currentMoodleXmlElementType); if (ralatedTo != null) { this.notifyFirstRelatedElement(currentMoodleXmlElement, ralatedTo); } this.moodleXmlElementsStack.Push(currentMoodleXmlElement); } } }