Exemplo n.º 1
0
        void save(string filename, List <FlightExport> flights)
        {
            var header = FlightExport.OpenFlightsHeader();

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(new FileStream(filename, FileMode.Create)))
            {
                file.WriteLine(header);
                foreach (var row in flights)
                {
                    file.WriteLine(row.OpenFlightsString());
                }
            }
        }
Exemplo n.º 2
0
        public List <FlightExport> GetCurrent(string folder)
        {
            var sDiary       = System.IO.Path.Combine(folder, "flightdiary.csv");
            var sOpenFlights = System.IO.Path.Combine(folder, "openflights.csv");
            var res          = new List <FlightExport>();

            if (File.Exists(sDiary))
            {
                foreach (var line in File.ReadAllText(sDiary).Split('\n').Skip(1))
                {
                    var cols = line.Split(',').ToList();
                    if (cols.Count > 1)
                    {
                        if (DateTime.TryParse(cols[0], out DateTime dt))
                        {
                            var x = new FlightExport
                            {
                                Date   = dt,
                                Flight = cols[1].Trim('"')
                            };
                            res.Add(x);
                        }
                    }
                }
            }
            if (File.Exists(sOpenFlights))
            {
                foreach (var line in File.ReadAllText(sOpenFlights).Split(new[] { "\r\n" }, StringSplitOptions.None).Skip(1))
                {
                    var cols = line.Split(',').ToList();
                    if (cols.Count > 1)
                    {
                        if (DateTime.TryParse(cols[0], out DateTime dt))
                        {
                            var x = new FlightExport
                            {
                                Date   = dt,
                                Flight = cols[3]
                            };
                            res.Add(x);
                        }
                    }
                }
            }
            return(res);
        }