public void Export(TicketExportFormat format) { string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (format == TicketExportFormat.PLAINTEXT) { using (TextWriter tw = new StreamWriter(path + @"\Order_" + orderNr + ".txt", false)) { foreach (MovieTicket ticket in tickets) { tw.WriteLine(ticket.ToString()); tw.WriteLine(); } } } if (format == TicketExportFormat.JSON) { var json = JsonConvert.SerializeObject(tickets); using (TextWriter tw = new StreamWriter(path + @"\Order_" + orderNr + ".json", false)) { tw.Write(json); } } }
public void export(TicketExportFormat exportFormat) { // Bases on the string respresentations of the tickets (toString), write // the ticket to a file with naming convention Order_<orderNr>.txt of // Order_<orderNr>.json string fileName = "Order_" + orderNr; string fileContent = ""; switch (exportFormat) { case TicketExportFormat.JSON: fileName = fileName + ".json"; //TODO JSON CONVERT fileContent = JsonSerializer.Serialize(tickets); File.WriteAllText(fileName, fileContent); break; case TicketExportFormat.PLAINTEXT: fileName = fileName + ".txt"; fileContent = string.Join("\n", tickets); File.WriteAllText(fileName, fileContent); break; case TicketExportFormat.CONSOLE: fileContent = string.Join("\n", tickets); Console.WriteLine(fileContent); break; } }
public void Export(TicketExportFormat exportFormat) { switch (exportFormat) { case TicketExportFormat.Json: Exporter.ExportToJson(this); return; case TicketExportFormat.Plaintext: Exporter.ExportToText(this); return; } }