Exemplo n.º 1
0
        /// <summary>
        /// Gets all pit stops set by a driver in a race.
        /// </summary>
        /// <param name="year">Year of the race.</param>
        /// <param name="round">Round of the season.</param>
        /// <param name="driver">Driver ID.</param>
        /// <returns>All pit stops info.</returns>
        public async Task <Race> PitStopsByRaceAndDriverAsync(int year, int round, string driver)
        {
            try
            {
                HttpResponseMessage response = await _client.GetAsync(_api.PitStopsByRaceAndDriver(year, round, driver));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <DataErgastRaces>(DataErgast.RemoveMRData(content))?.RaceTable?.Races[0]);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets all drivers who has won at least once in this circuit.
        /// </summary>
        /// <param name="circuit">Circuit ID.</param>
        /// <returns>Drivers info.</returns>
        public async Task <DriverTable> GetDriversWinnerCircuitAsync(string circuit)
        {
            try
            {
                HttpResponseMessage response = await _client.GetAsync(_api.DriversWinnersInCircuit(circuit));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <DataErgastDrivers>(DataErgast.RemoveMRData(content))?.DriverTable);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets driver standings for all seasons.
        /// </summary>
        /// <returns>Driver Standings info.</returns>
        public async Task <StandingsTable> DriverStandingsBySeason()
        {
            try
            {
                HttpResponseMessage response = await _client.GetAsync(_api.ChampionsByYear());

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <DataErgastStandings>(DataErgast.RemoveMRData(content))?.StandingsTable);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets all races a constructors has set a fastest lap.
        /// </summary>
        /// <param name="constructor">Constructor ID.</param>
        /// <returns>Races info.</returns>
        public async Task <RaceTable> FastestLapsByConstructorAsync(string constructor)
        {
            try
            {
                HttpResponseMessage response = await _client.GetAsync(_api.FastestLapsByConstructor(constructor));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <DataErgastRaces>(DataErgast.RemoveMRData(content))?.RaceTable);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets all the seasons a specific driver has won the Driver WC.
        /// </summary>
        /// <param name="driver">Driver ID.</param>
        /// <returns>Seasons data.</returns>
        public async Task <SeasonTable> GetSeasonsDriverWorldChampionAsync(string driver)
        {
            try
            {
                HttpResponseMessage response = await _client.GetAsync(_api.SeasonWorldChampionByDriver(driver));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <DataErgastSeasons>(DataErgast.RemoveMRData(content))?.SeasonTable);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets all circuits info. It can be filtered by year.
        /// </summary>
        /// <param name="year">Year to be filtered.</param>
        /// <returns>All circuits info.</returns>
        public async Task <CircuitTable> GetCircuitsAsync(int?year = null)
        {
            try
            {
                HttpResponseMessage response = await _client.GetAsync(_api.Circuits(year));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <DataErgastCircuits>(DataErgast.RemoveMRData(content))?.CircuitTable);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }

            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets all races starting by the offset.
        /// </summary>
        /// <param name="offset">Offset to begin counting.</param>
        /// <returns>All races starting in the offset.</returns>
        private async Task <RaceTable> GetRacesByURIAsync(int offset)
        {
            try
            {
                HttpResponseMessage response = await _client.GetAsync(_api.Races(offset));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <DataErgastRaces>(DataErgast.RemoveMRData(content))?.RaceTable);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }

            return(null);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets all laps set in the whole race, starting in the offset.
        /// </summary>
        /// <param name="year">Year of the race.</param>
        /// <param name="round">Round of the season.</param>
        /// <param name="offset">Offset to start in.</param>
        /// <returns>Laps info.</returns>
        private async Task <Race> GetLapsByRace(int year, int round, int offset)
        {
            string uri = _api.LapsByRace(year, round, offset);

            try
            {
                HttpResponseMessage response = await _client.GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <DataErgastRaces>(DataErgast.RemoveMRData(content))?.RaceTable.Races[0]);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(null);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets constructor info.
        /// </summary>
        /// <param name="constructor">Constructor ID.</param>
        /// <returns>Constructor info.</returns>
        public async Task <Constructor> GetConstructorAsync(string constructor)
        {
            string uri = _api.Constructor(constructor);

            try
            {
                HttpResponseMessage response = await _client.GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <DataErgastConstructors>(DataErgast.RemoveMRData(content))?.ConstructorTable.Constructors[0]);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets all races that a Driver has been into.
        /// </summary>
        /// <param name="driver">Driver ID.</param>
        /// <returns>Race list info.</returns>
        public async Task <RaceTable> RacesByDriverAsync(string driver)
        {
            try
            {
                HttpResponseMessage response = await _client.GetAsync(_api.RacesByDriver(driver));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    var aux = JsonConvert.DeserializeObject <DataErgastRaces>(DataErgast.RemoveMRData(content));
                    if (aux != null)
                    {
                        return(aux.RaceTable);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(null);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets constructor standings at the end of a race.
        /// </summary>
        /// <param name="year">Year of the race.</param>
        /// <param name="round">Round of the season.</param>
        /// <returns>Constructor standings info.</returns>
        public async Task <StandingsTable> ConstructorStandingsByRace(int year, int round)
        {
            try
            {
                HttpResponseMessage response = await _client.GetAsync(_api.ConstructorStandingsByRace(year, round));

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    var aux = JsonConvert.DeserializeObject <DataErgastStandings>(DataErgast.RemoveMRData(content));
                    if (aux != null)
                    {
                        return(aux.StandingsTable);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(null);
        }