internal void NextPage(params Object[] args) { List<int?> points; switch (currentPage) { case 0: round = RoundData.Load(args[0] as String); break; case 1: winnerPoints = Math.Max(pointsA, pointsB); break; case 2: points = args[0] as List<int?>; points.ForEach(delegate(int? i) { if (i.HasValue) winnerPoints += i.Value; }); break; case 3: points = args[0] as List<int?>; points.ForEach(delegate(int? i) { if (i.HasValue) winnerPoints += i.Value; }); this.client.LoadLastPage(); return; } MainFrame.Navigate(pages[++currentPage]); }
public static void Save(RoundData round, string path) { XmlWriterSettings settings = new XmlWriterSettings { NewLineHandling = NewLineHandling.Entitize, Indent = true, CloseOutput = true }; XmlWriter writer = XmlWriter.Create(path, settings); writer.WriteStartDocument(false); writer.WriteStartElement("RoundData"); writer.WriteStartElement("NormalMode"); foreach (var q in round.normal) { writer.WriteStartElement("Question"); writer.WriteAttributeString("Title", q.question); foreach (var pair in q.answers) { writer.WriteStartElement("Answer"); writer.WriteAttributeString("Points", pair.Key.ToString()); writer.WriteString(pair.Value); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteStartElement("FinalMode"); foreach (var q in round.final) { writer.WriteStartElement("Question"); writer.WriteAttributeString("Title", q.question); foreach (var pair in q.answers) { writer.WriteStartElement("Answer"); writer.WriteAttributeString("Points", pair.Key.ToString()); writer.WriteString(pair.Value); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); }
public static RoundData Load(string path) { RoundData d = new RoundData(); XmlReaderSettings settings = new XmlReaderSettings { CloseInput = true, IgnoreComments = true }; XmlReader reader = XmlReader.Create(path, settings); // TODO: For the God's sake, could someone rewrite it so it's not the same things twice? DRY, man, DRY. reader.ReadToFollowing("NormalMode"); reader.ReadToDescendant("Question"); int i = 0; do { reader.MoveToAttribute("Title"); string questionString = reader.ReadContentAsString(); Question q = new Question(questionString); reader.MoveToElement(); reader.ReadToDescendant("Answer"); do { reader.MoveToAttribute("Points"); int points = reader.ReadContentAsInt(); reader.MoveToElement(); string answer = reader.ReadElementContentAsString(); q.AddAnswer(answer, points); } while (reader.ReadToNextSibling("Answer")); d.normal[i++] = q; } while (reader.ReadToNextSibling("Question")); reader.ReadToFollowing("FinalMode"); reader.ReadToDescendant("Question"); i = 0; do { reader.MoveToAttribute("Title"); string questionString = reader.ReadContentAsString(); Question q = new Question(questionString); reader.MoveToElement(); reader.ReadToDescendant("Answer"); do { reader.MoveToAttribute("Points"); int points = reader.ReadContentAsInt(); reader.MoveToElement(); string answer = reader.ReadElementContentAsString(); q.AddAnswer(answer, points); } while (reader.ReadToNextSibling("Answer")); d.final[i++] = q; } while (reader.ReadToNextSibling("Question")); return d; }