Esempio n. 1
0
        public void Update()
        {
            bool done           = false;
            var  previousDateId = string.Empty;

            while (!done)
            {
                try
                {
                    Console.Out.WriteLine($"Updating league {_settings.LeagueId}");
                    var league       = _statsProvider.GetLeagueStats(_settings.LeagueId).Result;
                    var playerScores = _statsProvider.GeneratePlayerScores(league, false).Result;
                    var teamScores   = _statsProvider.GenerateTeamScores(league, playerScores).Result;

                    var leagueScore = new Data.LeagueScore
                    {
                        Id = _settings.LeagueId,
                        PlayerCalculatedScores = playerScores,
                        FantasyTeams           = teamScores
                    };

                    Console.Out.WriteLine("Updating calcuations");
                    var result = _client.UpdateAsync("updateLeagueScores", leagueScore, "league").Result;
                    if (result == null)
                    {
                        Console.Error.WriteLine("Null result");
                    }
                    else if (!result.Success)
                    {
                        Console.Error.WriteLine($"Failed to update. Message {result.Message}");
                    }
                    Console.Out.WriteLine("Finished updating league");
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine($"Update failed. {e.Message}. {e.StackTrace}");
                }
                if (!_settings.Continuous)
                {
                    done = true;
                }
                else
                {
                    Task.Delay(_settings.Delay).Wait();
                }
            }
        }
Esempio n. 2
0
        public static async Task UpdateLeague(LeagueRequest request)
        {
            var builder = new ConfigurationBuilder()
                          .AddEnvironmentVariables();
            var configuration = builder.Build();

            var serviceProvider = new ServiceCollection()
                                  .AddOptions()
                                  .AddSingleton <StatsProvider>()
                                  .AddAuth0Client(configuration)
                                  .AddStaplePuckClient(configuration)
                                  .BuildServiceProvider();

            var provider = serviceProvider.GetService <StatsProvider>();

            var league = await provider.GetLeagueStats(request.LeagueId);

            var playerScores = await provider.GeneratePlayerScores(league, request.Initialize);

            var teamScores = await provider.GenerateTeamScores(league, playerScores);

            var leagueScore = new Data.LeagueScore
            {
                Id = request.LeagueId,
                PlayerCalculatedScores = playerScores,
                FantasyTeams           = teamScores
            };
            var client = serviceProvider.GetService <IStaplePuckClient>();
            var result = await client.UpdateAsync("updateLeagueScores", leagueScore, "league");

            if (result == null)
            {
                Console.Error.WriteLine("Null result");
            }
            else if (!result.Success)
            {
                Console.Error.WriteLine($"Failed to update. Message {result.Message}");
            }
        }