예제 #1
0
파일: Order.cs 프로젝트: Justnuked/SOA3
        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);
                }
            }
        }
예제 #2
0
        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;
            }
        }
예제 #3
0
        public void Export(TicketExportFormat exportFormat)
        {
            switch (exportFormat)
            {
            case TicketExportFormat.Json:
                Exporter.ExportToJson(this);
                return;

            case TicketExportFormat.Plaintext:
                Exporter.ExportToText(this);
                return;
            }
        }