Exemplo n.º 1
0
		public void SaveCompletedPuzzle (Puzzle puzzle) {
			var documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
			var filePath = Path.Combine (documentsPath, "XamWordsCompletion.xml");

			List<Puzzle> puzzles = new List<Puzzle>();
			if (File.Exists (filePath)) {
				using (Stream reader = new FileStream (filePath, FileMode.Open)) {
					XmlSerializer serializer = new XmlSerializer(typeof(List<Puzzle>));
					puzzles = (List<Puzzle>)serializer.Deserialize (reader);
				}

				if (puzzles.Find (p => p.Name.ToUpper () == puzzle.Name.ToUpper ()) == null) {
					using (Stream writer = new FileStream (filePath, FileMode.Create)) {
						puzzles.Add(puzzle);
						XmlSerializer serializer = new XmlSerializer(typeof(List<Puzzle>));
						serializer.Serialize (writer, puzzles);
					}
				}
			} else {
				using (Stream writer = new FileStream (filePath, FileMode.OpenOrCreate)) {
					puzzles.Add(puzzle);
					XmlSerializer serializer = new XmlSerializer(typeof(List<Puzzle>));
					serializer.Serialize (writer, puzzles);
				}
			}
		}
Exemplo n.º 2
0
		public List<Word> GetWords (Puzzle puzzle)
		{
			var assembly = typeof(DatabaseService).GetTypeInfo().Assembly;
			Stream stream = assembly.GetManifestResourceStream("XamWords.Assets.Puzzles.xml");
			List<Word> words = new List<Word>();
			using (var reader = new System.IO.StreamReader (stream)) {
				XDocument xmlDoc = XDocument.Load(reader);
				var q = from xml in xmlDoc.Descendants("word") where xml.Parent.Attribute("name").Value == puzzle.Name select xml;
				foreach( XElement word in q )
				{
					try
					{
						words.Add(new Word{
							Text = word.Attribute("text").Value,
							Found = false
						});
					}
					catch (Exception ex)
					{

					}
				}
			}

			return words;
		}