Example #1
0
        public async Task ProcessFlightsAsync()
        {
            var uploadedFiles = flightLogFileService.GetUploadedFlightLogFiles();

            foreach (var flightLog in uploadedFiles) //amelyek még nem voltak feldolgozva
            {
                string path = flightLog.FilePath;
                try
                {   // Open the text file using a stream reader.
                    using (StreamReader sr = new StreamReader(path))
                    {
                        string line;
                        Flight flight = new Flight();
                        flight.ApplicationUserId = flightLog.ApplicationUserId; //kinek a repülese
                        flight.FlightStatus      = FlightStatus.WaitingForAcceptance;
                        while ((line = sr.ReadLine()) != null)
                        {
                            flightService.ParseString(line, flight);
                        }
                        await flightService.SetAirportsAsync(flight);

                        flightLog.FlightLogFileStatus = FlightLogFileStatus.Processed;
                        await flightService.AddFlightAsync(flight);

                        gPSRecordService.SetColor(flight);
                        var optimizedGPSRecords = GetApproximatingNodes(flight.GPSRecords.ToList());
                        foreach (var gpsRecord in optimizedGPSRecords)
                        {
                            flight.GPSRecords.Single(ent => ent.GPSRecordId == gpsRecord.GPSRecordId).IsOptimized = true;;
                        }

                        await applicationContext.SaveChangesAsync();
                    }
                }
                catch (IOException e)
                {
                    Console.WriteLine("The file could not be read:");
                    Console.WriteLine(e.Message);
                }
            }
        }