/// <summary> /// Constructor for editing topic mode /// </summary> /// <param name="editor"></param> /// <param name="sectionId"></param> /// <param name="id"></param> public TopicEditor(Editor editor, Content.Section section, Content.Topic topic) { InitializeComponent(); this.editor = editor; this.topic = topic; this.section = section; titleBox.Text = topic.GetTitle(); isOpenCheckbox.Checked = topic.IsOpen(); int i = 0; foreach (Content.Section item in editor.content.GetSections()) { sectionBox.Items.Add(item.GetTitle()); if (item.GetId() == section.GetId()) { sectionIndex = i; } i++; } sectionBox.SelectedIndex = sectionIndex; }
public static Content.Content LoadContent(string path) { XDocument doc = XDocument.Load(path); XElement content = doc.Element("content"); XElement meta = content.Element("meta"); XElement idCount = meta.Element("idCount"); int _idCount = int.Parse(idCount.Value); Content.Content _content = new Content.Content(_idCount); foreach (XElement section in content.Elements("section")) { int _sectionId = int.Parse(section.Element("id").Value); string _sectionTitle = section.Element("title").Value; bool _sectionIsOpen = false; if (section.Element("isOpen") != null) { _sectionIsOpen = bool.Parse(section.Element("isOpen").Value); } Content.Section _section = new Content.Section(_sectionId, _sectionTitle, _sectionIsOpen); foreach (XElement topic in section.Elements("topic")) { int _topicId = int.Parse(topic.Element("id").Value); string _topicTitle = topic.Element("title").Value; bool _topicIsOpen = false; if (topic.Element("isOpen") != null) { _topicIsOpen = bool.Parse(topic.Element("isOpen").Value); } Content.Topic _topic = new Content.Topic(_topicId, _topicTitle, _topicIsOpen); foreach (XElement entry in topic.Elements()) { if (entry.Name == "theory" || entry.Name == "challenge") { int _entryId = int.Parse(entry.Element("id").Value); string _entryText = entry.Element("text").Value; bool _entryIsOpen = false; if (entry.Element("isOpen") != null) { _entryIsOpen = bool.Parse(entry.Element("isOpen").Value); } if (entry.Name == "theory") { Content.Theory _theory = new Content.Theory(_entryId, _entryText, _entryIsOpen); _topic.AddEntry(_theory); } else { Content.Challenge.Type _challengeType = (Content.Challenge.Type)Enum.Parse(typeof(Content.Challenge.Type), entry.Element("type").Value); List <string> _answers = new List <string>(); foreach (XElement answer in entry.Element("answers").Elements()) { _answers.Add(answer.Value); } Content.Challenge _challenge = new Content.Challenge(_entryId, _entryText, _entryIsOpen, _challengeType, _answers); _topic.AddEntry(_challenge); } } } _section.AddTopic(_topic); } _content.AddSection(_section); } return(_content); }