Esempio n. 1
0
        private static async System.Threading.Tasks.Task <ArchivedGamesList> GetPlayerMonthlyArchive(string username)
        {
            using ChessDotComSharp.ChessDotComClient client = new ChessDotComSharp.ChessDotComClient();
            ArchivedGamesList myGames = await client.GetPlayerGameArchivesAsync(username).ConfigureAwait(true);

            return(myGames);
        }
Esempio n. 2
0
        private static async System.Threading.Tasks.Task <PlayerArchivedGames> GetAllPlayerMonthlyGames(DirectoryInfo cache, string username, int year, int month)
        {
            PlayerArchivedGames myGames;
            string cacheFileName = $"{Path.Combine(cache.FullName, $"{username}{year}{month.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0')}")}";

            if (File.Exists(cacheFileName))
            {
                using FileStream gameFileInStream = File.OpenRead(cacheFileName);
                myGames = await JsonSerializer.DeserializeAsync <PlayerArchivedGames>(gameFileInStream).ConfigureAwait(false);
            }
            else
            {
                //Prevent rate limit errors on the API
                await apiSemaphore.WaitAsync().ConfigureAwait(false);

                try
                {
                    using ChessDotComSharp.ChessDotComClient client = new ChessDotComSharp.ChessDotComClient();
                    myGames = await client.GetPlayerGameMonthlyArchiveAsync(username, year, month).ConfigureAwait(true);

                    // Never cache data for this month
                    if (!(DateTime.UtcNow.Year == year && DateTime.UtcNow.Month == month))
                    {
                        using FileStream gameFileOutStream = File.Create(cacheFileName);
                        await JsonSerializer.SerializeAsync(gameFileOutStream, myGames).ConfigureAwait(false);
                    }
                }
                finally
                {
                    apiSemaphore.Release();
                }
            }

            return(myGames);
        }
Esempio n. 3
0
        public static async Task <(PlayerProfile userRecord, PlayerStats userStats)> FetchUserData(string username)
        {
            using ChessDotComSharp.ChessDotComClient client = new ChessDotComSharp.ChessDotComClient();
            PlayerProfile userRecord = await client.GetPlayerProfileAsync(username).ConfigureAwait(false);

            PlayerStats userStats = await client.GetPlayerStatsAsync(username).ConfigureAwait(false);

            return(userRecord, userStats);
        }