Beispiel #1
0
        public static async Task Run([TimerTrigger("0 0 1 * * *")] TimerInfo myTimer, ILogger log) //0 0 1 * * *
        {
            log.LogInformation($"[BEGIN] CompetitionImporter: {DateTime.Now}");
            var serviceProvider = new ServiceCollection().AddHttpClient().BuildServiceProvider();

            var settings          = AppSettings.Configure();
            var httpClientFactory = serviceProvider.GetService <IHttpClientFactory>();

            using (var sqlConnection = new SqlConnection(settings.Database.ConnectionString))
            {
                sqlConnection.Open();
                var databaseConnection = new DatabaseConnection(sqlConnection);
                var regionDb           = new RegionDatabase(databaseConnection);
                var mapper             = new Mappers.ApiFootball.CompetitionMapper(regionDb);
                //var provider = new FootballDataCompetitionProvider(httpClientFactory, settings.Api.AuthToken, mapper);
                var provider = new ApiFootballCompetitionProvider(httpClientFactory, settings.Api.AuthToken, mapper);

                var competitionDb = new CompetitionDatabase(databaseConnection);
                var competitions  = await CompetitionCollection.RetrieveFrom(provider);

                log.LogInformation($"Retrieved {competitions.Count()} competitions");
                competitions.SaveTo(competitionDb);
            }
            log.LogInformation($"[COMPLETE] CompetitionImporter: {DateTime.Now}");
        }
Beispiel #2
0
        public async Task <List <Competition> > SoccerCompetitions()
        {
            string errorString;

            CompetitionCollection jsonCompetitionCollection = new CompetitionCollection();

            try
            {
                jsonCompetitionCollection = await _httpClient.GetFromJsonAsync <CompetitionCollection>("/v2/competitions/?plan=TIER_ONE");

                errorString = null;
            }
            catch (Exception ex)
            {
                errorString = $"There was an error getting Competitions: {ex.Message}";
            }

            List <Competition> competitions = new List <Competition>(jsonCompetitionCollection.Competitions);

            return(competitions);
        }