internal static void ExportMoviesToXML(string filename, Stick stick) { using (XmlWriter writer = XmlWriter.Create(filename)) { writer.WriteStartDocument(); writer.WriteStartElement("Movies"); var movies = stick.Films; List <Film> allInXml = new List <Film>(); foreach (var movie in movies) { if (!allInXml.Contains(movie)) { allInXml.Add(movie); writer.WriteStartElement("Movie"); if (movie.HeeftSequel) { allInXml.Add(movie.Sequels.First()); writer.WriteElementString("Titel", movie.Sequels.First().Titel); writer.WriteElementString("ReleaseYear", movie.Sequels.First().Jaar.ToString()); writer.WriteElementString("Size", movie.Sequels.First().size.ToString()); writer.WriteElementString("HasSequel", movie.HeeftSequel.ToString()); writer.WriteStartElement("Sequels"); foreach (var m in movie.Sequels) { if (!allInXml.Contains(m)) { allInXml.Add(m); writer.WriteStartElement("Sequel"); writer.WriteElementString("Titel", m.Titel); writer.WriteElementString("ReleaseYear", m.Jaar.ToString()); writer.WriteElementString("Size", m.size.ToString()); writer.WriteEndElement(); } } writer.WriteEndElement(); } else { writer.WriteElementString("Titel", movie.Titel); writer.WriteElementString("ReleaseYear", movie.Jaar.ToString()); writer.WriteElementString("Size", movie.size.ToString()); writer.WriteElementString("HasSequel", movie.HeeftSequel.ToString()); } //writer.WriteElementString("Salary", employee.Salary.ToString()); writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteEndDocument(); } }
static void Main() { Console.BufferHeight = Int16.MaxValue - 1; Console.WriteLine("Selecteer de map die de films bevat:"); FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() != DialogResult.OK) { Console.WriteLine("Geen map gekozen, programma wordt afgesloten."); Console.ReadKey(); return; } Console.Clear(); Stick stick = new Stick(fbd.SelectedPath); Console.WriteLine("In welke mappen zitten geen films?"); Toolbox.PrintList(stick.GetAllFolders(), '\t'); Console.Write("Mappen die beginnen met: "); stick.SetUitzondering(Console.ReadLine()); int code = -1; while (code != 0) { do { Console.Clear(); Console.WriteLine("Kies wat je wil doen:"); Console.WriteLine("1) Toon alle films"); Console.WriteLine("2) Toon alle film mappen"); Console.WriteLine("3) Toon films die ... in naam hebben"); Console.WriteLine("4) Toon een random film om te kijken"); Console.WriteLine("5) Toon resultaten"); Console.WriteLine("6) Schrijf resultaten naar bestand"); Console.WriteLine("7) Verander mappen die films bevatten"); Console.WriteLine("8) Export alle films naar XML"); Console.WriteLine("0) Afsluiten"); try { code = int.Parse(Console.ReadLine().ToString()); } catch { code = -1; } } while (code < 0 || code > 8); switch (code) { case 0: break; case 1: Toolbox.PrintList(stick.Films, charVoorString: '\t'); break; case 2: Toolbox.PrintList(stick.GetMovieFolders()); break; case 3: Console.WriteLine("Film moet ... bevatten:"); string par = Console.ReadLine(); Toolbox.PrintList(stick.Films, contains: par); break; case 4: Random rand = new Random(); int film = rand.Next(0, stick.Films.Count); Console.WriteLine("Gekozen film:"); Console.WriteLine("\t" + stick.Films[film].Titel + " - " + stick.Films[film].Jaar); break; case 5: Toolbox.PrintList(stick.Errors); break; case 6: stick.PrintFilmsToFile(); stick.PrintErrorsToFile(); break; case 7: stick = new Stick(fbd.SelectedPath); Console.WriteLine("In welke mappen zitten geen films?"); Toolbox.PrintList(stick.GetAllFolders(), '\t'); Console.Write("Mappen die beginnen met: "); stick.SetUitzondering(Console.ReadLine()); Console.Clear(); break; case 8: Toolbox.ExportMoviesToXML("films.xml", stick); break; } if (code != 0) { Console.WriteLine("Enter om door te gaan"); Console.Read(); } } }