/// <summary> /// Gets the preview dictionary. /// </summary> /// <param name="path">The path.</param> /// <param name="user">The user.</param> /// <returns></returns> /// <remarks>Documented by Dev05, 2009-03-06</remarks> public static PreviewDictionary GetPreviewDictionary(string path, IUser user) { PreviewDictionary dic = new PreviewDictionary(user); using (XmlReader reader = XmlReader.Create(path)) { try { if (reader.ReadToFollowing("category")) { int oldId, newId; if (Int32.TryParse(reader.GetAttribute("id"), out newId) && (newId >= 0)) { dic.Category = new Category(newId); } else if (Int32.TryParse(reader.ReadElementContentAsString(), out oldId) && (oldId >= 0)) { dic.Category = new Category(oldId, false); } } } catch { dic.Category = new Category(0); } dic.Id = 1; dic.Connection = path; return dic; } }
/// <summary> /// Updates the preview dictionary. /// </summary> /// <param name="dictionary">The dictionary.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2009-03-30</remarks> public static PreviewDictionary UpdatePreviewDictionary(PreviewDictionary dictionary) { using (XmlReader reader = XmlReader.Create(dictionary.Connection)) { try { ICard card = null; IStatistic statistic = null; bool imageFound = false; while (reader.Read()) { if (reader.IsEmptyElement || reader.NodeType == XmlNodeType.EndElement) continue; switch (reader.Name) { case "category": int oldId, newId; if (Int32.TryParse(reader.GetAttribute("id"), out newId) && (newId >= 0)) { dictionary.Category = new Category(newId); } else if (Int32.TryParse(reader.ReadElementContentAsString(), out oldId) && (oldId >= 0)) { dictionary.Category = new Category(oldId, false); } break; case "author": dictionary.Author = reader.ReadElementContentAsString().Trim(); break; case "description": dictionary.Description = reader.ReadElementContentAsString().Trim(); break; case "sounddir": dictionary.MediaDirectory = reader.ReadElementContentAsString().Trim(); break; case "card": card = dictionary.Cards.AddNew(); break; case "answer": if (imageFound) continue; if (card != null) { card.Answer.AddWords(Helper.SplitWordList(reader.ReadElementContentAsString())); } break; case "question": if (imageFound) continue; if (card != null) { card.Question.AddWords(Helper.SplitWordList(reader.ReadElementContentAsString())); } break; case "answerexample": if (imageFound) continue; if (card != null) { card.AnswerExample.AddWords(Helper.SplitWordList(reader.ReadElementContentAsString())); } break; case "questionexample": if (imageFound) continue; if (card != null) { card.QuestionExample.AddWords(Helper.SplitWordList(reader.ReadElementContentAsString())); } break; case "questionimage": if (imageFound) continue; if (card != null) { IMedia qmedia = card.CreateMedia(EMedia.Image, reader.ReadElementContentAsString(), true, false, false); card.AddMedia(qmedia, Side.Question); imageFound = true; } break; case "answerimage": if (imageFound) continue; if (card != null) { IMedia amedia = card.CreateMedia(EMedia.Image, reader.ReadElementContentAsString(), true, false, false); card.AddMedia(amedia, Side.Question); } break; case "stats": statistic = new PreviewStatistic(); int sId; if (Int32.TryParse(reader.GetAttribute("id"), out sId) && (sId >= 0)) { (statistic as PreviewStatistic).Id = sId; } dictionary.Statistics.Add(statistic); break; case "start": if (statistic != null) { statistic.StartTimestamp = XmlConvert.ToDateTime(reader.ReadElementContentAsString(), XmlDateTimeSerializationMode.RoundtripKind); } break; case "end": if (statistic != null) { statistic.EndTimestamp = XmlConvert.ToDateTime(reader.ReadElementContentAsString(), XmlDateTimeSerializationMode.RoundtripKind); } break; case "right": if (statistic != null) { statistic.Right = XmlConvert.ToInt32(reader.ReadElementContentAsString()); } break; case "wrong": if (statistic != null) { statistic.Wrong = XmlConvert.ToInt32(reader.ReadElementContentAsString()); } break; default: break; } //System.Threading.Thread.Sleep(5); } } catch { dictionary.Category = new Category(0); } dictionary.Id = 1; return dictionary; } }
/// <summary> /// Gets the extended preview dictionary. /// </summary> /// <param name="path">The path.</param> /// <param name="user">The user.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2009-03-23</remarks> public static PreviewDictionary GetExtendedPreviewDictionary(string path, IUser user) { PreviewDictionary dic = new PreviewDictionary(user); dic.Connection = path; return UpdatePreviewDictionary(dic); }