private async Task UpdateMetarInfo(MetarResult response)
        {
            IsBusy      = false;
            AirportCode = string.Empty;
            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                DisplayError(Localization.Error_Occured, response.StatusCode.ToString());
                return;
            }

            var airport       = Airport.MapFromResponse(response.AirportIdentifier, response.MetarResponse);
            var alreadyExists = Airports.FirstOrDefault(x => x.Name == airport.Name);

            if (alreadyExists == null)
            {
                Airports.Add(airport);
            }
            else
            {
                alreadyExists.Copy(airport);
                OnPropertyChanged(nameof(Airports));
            }
            HasSavedItems = Airports != null && Airports.Any();
            await AirportService.SaveAirport(airport, new System.Threading.CancellationToken()).ConfigureAwait(false);
        }
Beispiel #2
0
        /// <summary>
        /// Create an airport
        /// </summary>
        /// <param name="name"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="minPassenger"></param>
        /// <param name="maxPassenger"></param>
        /// <param name="minMarchandise"></param>
        /// <param name="maxMarchandise"></param>
        public void CreateAirport(string name, int x, int y, int minPassenger, int maxPassenger, int minMarchandise, int maxMarchandise, string dms)
        {
            Airport airport = new Airport(name, x, y, minPassenger, maxPassenger, minMarchandise, maxMarchandise, dms);

            Airports.Add(airport);
            airportNotifier(airport.ToString());
        }
        private void ParseAirports()
        {
            Airports.Clear();

            using (var reader = new StreamReader(string.Format(PathToData, "airports.csv")))
                using (var csv = new CsvReader(reader))
                {
                    csv.Read();
                    csv.ReadHeader();
                    while (csv.Read())
                    {
                        var airport = new Airport
                        {
                            Name           = csv.GetField("Name"),
                            City           = csv.GetField("City"),
                            Country        = csv.GetField("Country"),
                            IATADesignator = csv.GetField("IATA 3"),
                            Latitude       = csv.GetField <double>("Latitute"),
                            Longitude      = csv.GetField <double>("Longitude")
                        };

                        Airports.Add(airport);
                    }
                }
        }
Beispiel #4
0
        public void LoadAirport()
        {
            Airports.Clear();
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = CONNECTION_STRING;
                conn.Open();

                SqlCommand command = conn.CreateCommand();
                command.CommandText = @"SELECT * FROM Airport";

                SqlDataAdapter daAirport = new SqlDataAdapter();
                DataSet        dsAirport = new DataSet();

                daAirport.SelectCommand = command;
                daAirport.Fill(dsAirport, "Airports");

                foreach (DataRow row in dsAirport.Tables["Airports"].Rows)
                {
                    Airport airport = new Airport();

                    airport.Id        = (int)row["Id"];
                    airport.AirportID = (string)row["AirportID"];
                    airport.Name      = (string)row["Name"];
                    airport.City      = (string)row["City"];
                    airport.Active    = (bool)row["Active"];

                    Airports.Add(airport);
                }
            }
        }
Beispiel #5
0
 public void LoadAirConnections()
 {
     AirConnections = connectionsReader.LoadDatabase(CsvPath);
     foreach (var conn in AirConnections)
     {
         Airports.Add(conn.AirportA);
         Airports.Add(conn.AirportB);
     }
 }
Beispiel #6
0
        internal void OnDeserializedMethod(StreamingContext context)
        {
            foreach (Airport airport in Airports.ToArray())
            {
                Airport newAirport = new Airport(
                    airport.AirportTitle,
                    airport.AirportRating,
                    airport.AllowedDT,
                    airport.AllowedAT,
                    this                  // При десериализации мы потеряем ссылку на город в аэропорте
                    );                    // поэтому нам его необходимо пересоздать

                Airports.Remove(airport); // Удаляем старый аэропорт без ссылки на город
                Airports.Add(newAirport); // Добавляем точно такой, но теперь со ссылкой на город
            }
        }
Beispiel #7
0
        //имя совпадает с именем класса + нет возвращаемого типа - функция AirportListViewModel - к*/онструктор
        public AirportListViewModel(Repository repository)                         //читаем данные из базы
        {
            this.repository = repository;                                          //это инициализация поля, так как поле лежит в this

            foreach (var airport in repository.Airports)                           //это же обращение к объекту другого класса
            {
                AirportViewModel airportViewModel = new AirportViewModel(airport); //создаем аэропорт для слоя WM
                Airports.Add(airportViewModel);                                    //добавляем аэропорт AirportViewModel
                FilteredAirports.Add(airportViewModel);                            // добавляем viewmodel airport
                //FilteredAirports -это  свойство из строки   public ObservableCollection<AirportViewModel> FilteredAirports
                filteredAirportsSet.Add(airportViewModel);                         //добавлен список аэропортов
                //filteredAirportsSet,где оно инициализировано
            }

            DeleteSelectedAirportCommand =
                new RelayCommand(OnDeleteSelectedAirport, CanDeleteSelectedAirport);
        }//тип Action представляет собой (ссылку на) функцию
        private void LoadSavedAirports()
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                var airports = await AirportService.GetAllAirports(new System.Threading.CancellationToken()).ConfigureAwait(false);
                foreach (var airport in airports)
                {
                    var item = Airports.FirstOrDefault(x => x.Name == airport.Name);
                    if (item != null)
                    {
                        continue;
                    }

                    Airports.Add(airport);
                }
                HasSavedItems = Airports != null && Airports.Any();
            });
        }
        private int MatchAirports(IEnumerable <airport> rgap)
        {
            int cUniqueAirports           = 0;
            HashSet <string> hsThisFlight = new HashSet <string>();

            foreach (airport ap in rgap)
            {
                // Dedupe as we go based on latitude/longitude, ignoring non-ports.
                // We don't actually need the facility name here - so we can just round off the latitude/longitude and distinguish by type code.
                // Note: this can differ slightly from Visited Airports counts because for achievements, we're ignoring flights in training devices; visited airports doesn't ignore them.
                if (ap.IsPort)
                {
                    string szHash = ap.GeoHashKey;
                    if (!Airports.Contains(szHash))
                    {
                        Airports.Add(ap.GeoHashKey);
                        cUniqueAirports++;
                    }
                    hsThisFlight.Add(szHash);

                    string szCountry = ap.CountryDisplay;
                    string szAdmin1  = ap.Admin1Display;

                    // Keep track of visited countries/regions
                    if (!String.IsNullOrWhiteSpace(szCountry))
                    {
                        if (!GeoRegions.ContainsKey(szCountry))
                        {
                            GeoRegions[szCountry] = new HashSet <string>();
                        }

                        if (!String.IsNullOrWhiteSpace(szAdmin1) && !GeoRegions[szCountry].Contains(szAdmin1))
                        {
                            GeoRegions[szCountry].Add(szAdmin1);
                        }
                    }
                }
            }

            return(hsThisFlight.Count);
        }
Beispiel #10
0
        public void AddAirport(string name, int cap, PointF location, int lanes)
        {
            Airport airport = new Airport(name, cap, location, lanes);

            Airports.Add(airport);
        }
Beispiel #11
0
        public override void ExamineFlight(ExaminerFlightRow cfr)
        {
            if (cfr == null)
            {
                throw new ArgumentNullException("cfr");
            }
            DateTime dtFlight = cfr.dtFlight.Date;

            if (AutoDateRange)
            {
                StartDate = StartDate.EarlierDate(dtFlight);
                EndDate   = EndDate.LaterDate(dtFlight);
            }

            // ignore anything not in a real aircraft or outside of our date range
            if (!cfr.fIsRealAircraft || dtFlight.CompareTo(StartDate) < 0 || dtFlight.CompareTo(EndDate) > 0)
            {
                return;
            }

            miFlightCount.AddEvent(1);

            string szDateKey = dtFlight.YMDString();

            // Initialize the current streak, if needed
            if (FirstDayOfCurrentStreak == null || LastDayOfCurrentStreak == null)
            {
                FirstDayOfCurrentStreak = LastDayOfCurrentStreak = dtFlight;
            }

            // Extend the current streak if this flight is either on the first date or on a day before the first date; if it isn't one of those, then end the current streak
            if (dtFlight.CompareTo(FirstDayOfCurrentStreak.Value.Date) == 0 || dtFlight.CompareTo(FirstDayOfCurrentStreak.Value.AddDays(-1).Date) == 0)
            {
                FirstDayOfCurrentStreak = dtFlight;
            }
            else
            {
                FirstDayOfCurrentStreak = LastDayOfCurrentStreak = dtFlight;
            }

            int cDaysCurrentStreak = CurrentFlyingDayStreak;

            if (cDaysCurrentStreak > 1 && cDaysCurrentStreak > FlyingDayStreak)
            {
                FirstFlyingDayOfStreak = FirstDayOfCurrentStreak;
                LastFlyingDayOfStreak  = LastDayOfCurrentStreak;
            }

            // Distinct flights on dates
            if (FlightDates.ContainsKey(szDateKey))
            {
                FlightDates[szDateKey] = FlightDates[szDateKey] + 1;
            }
            else
            {
                FlightDates[szDateKey] = 1;
            }

            if (FlightDates[szDateKey] > MaxFlightsPerDay)
            {
                int cFlights = FlightDates[szDateKey];
                MaxFlightsPerDay                     = cFlights;
                miMostFlightsInDay.Progress          = cFlights;
                miMostFlightsInDay.MatchingEventText = String.Format(CultureInfo.InvariantCulture, Resources.Achievements.RecentAchievementMostFlightsInDay, cFlights, cfr.dtFlight);
                miMostFlightsInDay.Query             = new FlightQuery(Username)
                {
                    DateRange = FlightQuery.DateRanges.Custom, DateMin = cfr.dtFlight, DateMax = cfr.dtFlight
                };
            }

            // Longest flight
            if (cfr.Total > LongestFlightLength)
            {
                LongestFlightLength               = cfr.Total;
                miLongestFlight.Progress          = 1;
                miLongestFlight.MatchingEventID   = cfr.flightID;
                miLongestFlight.MatchingEventText = String.Format(CultureInfo.CurrentCulture, Resources.Achievements.RecentAchievementsLongestFlight, cfr.Total, dtFlight);
            }

            // Distinct aircraft/models
            DistinctAircraft.Add(cfr.idAircraft);
            DistinctModels.Add(cfr.idModel);
            DistinctICAO.Add(cfr.szFamily);

            // Furthest Flight & airport computations.
            AirportList al = AirportListOfRoutes.CloneSubset(cfr.Route, true);

            double distance = al.DistanceForRoute();

            if (distance > FurthestFlightDistance)
            {
                FurthestFlightDistance             = distance;
                miFurthestFlight.Progress          = 1;
                miFurthestFlight.MatchingEventID   = cfr.flightID;
                miFurthestFlight.MatchingEventText = String.Format(CultureInfo.CurrentCulture, Resources.Achievements.RecentAchievementsFurthestFlight, distance, dtFlight);
            }

            int cUniqueAirports           = 0;
            HashSet <string> hsThisFlight = new HashSet <string>();

            foreach (airport ap in al.UniqueAirports)
            {
                // Dedupe as we go based on latitude/longitude, ignoring non-ports.
                // We don't actually need the facility name here - so we can just round off the latitude/longitude and distinguish by type code.
                // Note: this can differ slightly from Visited Airports counts because for achievements, we're ignoring flights in training devices; visited airports doesn't ignore them.
                if (ap.IsPort)
                {
                    string szHash = ap.GeoHashKey;
                    if (!Airports.Contains(szHash))
                    {
                        Airports.Add(ap.GeoHashKey);
                        cUniqueAirports++;
                    }
                    hsThisFlight.Add(szHash);
                }
            }

            int cAirportsThisFlight = hsThisFlight.Count;

            if (cAirportsThisFlight > MostAirportsFlightCount)
            {
                MostAirportsFlightCount = cAirportsThisFlight;
                miMostAirportsFlight.MatchingEventID   = cfr.flightID;
                miMostAirportsFlight.Progress          = 1;
                miMostAirportsFlight.MatchingEventText = String.Format(CultureInfo.CurrentCulture, Resources.Achievements.RecentAchievementsAirportsOnFlight, cAirportsThisFlight, dtFlight.ToShortDateString());
                miMostAirportsFlight.Query             = new FlightQuery(Username)
                {
                    DateRange = FlightQuery.DateRanges.Custom, DateMax = dtFlight, DateMin = dtFlight
                };
            }
        }
        public override void ExamineFlight(ExaminerFlightRow cfr)
        {
            if (cfr == null)
            {
                throw new ArgumentNullException("cfr");
            }
            DateTime dtFlight = cfr.dtFlight.Date;

            // ignore anything not in a real aircraft or outside of our date range
            if (!cfr.fIsRealAircraft || dtFlight.CompareTo(StartDate) < 0 || dtFlight.CompareTo(EndDate) > 0)
            {
                return;
            }

            string szDateKey = dtFlight.YMDString();

            // Initialize the current streak, if needed
            if (FirstDayOfCurrentStreak == null || LastDayOfCurrentStreak == null)
            {
                FirstDayOfCurrentStreak = LastDayOfCurrentStreak = dtFlight;
            }

            // Extend the current streak if this flight is either on the first date or on a day before the first date; if it isn't one of those, then end the current streak
            if (dtFlight.CompareTo(FirstDayOfCurrentStreak.Value.Date) == 0 || dtFlight.CompareTo(FirstDayOfCurrentStreak.Value.AddDays(-1).Date) == 0)
            {
                FirstDayOfCurrentStreak = dtFlight;
            }
            else
            {
                FirstDayOfCurrentStreak = LastDayOfCurrentStreak = dtFlight;
            }

            int cDaysCurrentStreak = CurrentFlyingDayStreak;

            if (cDaysCurrentStreak > 1 && cDaysCurrentStreak > FlyingDayStreak)
            {
                FirstFlyingDayOfStreak = FirstDayOfCurrentStreak;
                LastFlyingDayOfStreak  = LastDayOfCurrentStreak;
            }

            // Distinct flights on dates
            if (FlightDates.ContainsKey(szDateKey))
            {
                FlightDates[szDateKey] = FlightDates[szDateKey] + 1;
            }
            else
            {
                FlightDates[szDateKey] = 1;
            }

            if (FlightDates[szDateKey] > MaxFlightsPerDay)
            {
                int cFlights = FlightDates[szDateKey];
                MaxFlightsPerDay                     = cFlights;
                miMostFlightsInDay.Progress          = cFlights;
                miMostFlightsInDay.MatchingEventText = String.Format(CultureInfo.InvariantCulture, Resources.Achievements.RecentAchievementMostFlightsInDay, cFlights, cfr.dtFlight);
                miMostFlightsInDay.Query             = new FlightQuery(Username)
                {
                    DateRange = FlightQuery.DateRanges.Custom, DateMin = cfr.dtFlight, DateMax = cfr.dtFlight
                };
            }

            // Longest flight
            if (cfr.Total > LongestFlightLength)
            {
                LongestFlightLength               = cfr.Total;
                miLongestFlight.Progress          = 1;
                miLongestFlight.MatchingEventID   = cfr.flightID;
                miLongestFlight.MatchingEventText = String.Format(CultureInfo.CurrentCulture, Resources.Achievements.RecentAchievementsLongestFlight, cfr.Total, dtFlight);
            }

            // Distinct aircraft/models
            DistinctAircraft.Add(cfr.idAircraft);
            DistinctModels.Add(cfr.idModel);
            DistinctICAO.Add(cfr.szFamily);

            // Furthest Flight & airport computations.
            AirportList al = AirportListOfRoutes.CloneSubset(cfr.Route);

            double distance = al.DistanceForRoute();

            if (distance > FurthestFlightDistance)
            {
                FurthestFlightDistance             = distance;
                miFurthestFlight.Progress          = 1;
                miFurthestFlight.MatchingEventID   = cfr.flightID;
                miFurthestFlight.MatchingEventText = String.Format(CultureInfo.CurrentCulture, Resources.Achievements.RecentAchievementsFurthestFlight, distance, dtFlight);
            }

            int cUniqueAirports = al.UniqueAirports.Count();

            foreach (airport ap in al.UniqueAirports)
            {
                if (ap.IsPort)
                {
                    // Dedupe as we go - do the K-hack check; if the K version is in the AirportListOfRoutes, use that.  I.e., just pre-pend a "K" to ANY three-letter airport code.
                    if (ap.Code.Length == 3)
                    {
                        Airports.Add("K" + ap.Code);
                    }
                    else
                    {
                        Airports.Add(ap.Code);
                    }
                }
            }

            if (cUniqueAirports > MostAirportsFlightCount)
            {
                MostAirportsFlightCount                = cUniqueAirports;
                miMostAirportsFlight.Progress          = 1;
                miMostAirportsFlight.MatchingEventText = String.Format(CultureInfo.CurrentCulture, Resources.Achievements.RecentAchievementsAirportsOnFlight, cUniqueAirports, dtFlight.ToShortDateString());
                miMostAirportsFlight.Query             = new FlightQuery(Username)
                {
                    DateRange = FlightQuery.DateRanges.Custom, DateMax = dtFlight, DateMin = dtFlight
                };
            }
        }