Пример #1
0
        /// <summary>
        /// Requests information about a user's collection in an asynchronous manner
        /// </summary>
        /// <param name="collectionRequest">Details of the request</param>
        /// <returns>A task which returns details of the user's collection</returns>
        public async Task <BGGResponse <BGGCollection> > GetCollectionAsync(BGGCollectionRequest collectionRequest)
        {
            if (string.IsNullOrEmpty(collectionRequest.Username))
            {
                throw new ArgumentException("Null or empty username in collectionRequest");
            }

            return(await CallBGGAsync <Collection, BGGCollection>("collection", collectionRequest, BGGFactory.CreateCollection));
        }
Пример #2
0
        private async static Task FetchUser(BGGClient client, string username, bool retry)
        {
            var request = new BGGCollectionRequest { Username = username };

            var task = client.GetCollectionAsync(request);
            var response = await task;

            if (response.StatusCode == HttpStatusCode.Accepted)
            {
                if (retry)
                {
                    Console.WriteLine("Waiting to get collection for {0}", username);
                    Thread.Sleep(TimeSpan.FromSeconds(30));
                    await FetchUser(client, username, false);
                    return;
                }
                else
                {
                    Console.WriteLine("Failed to fetch collection at second attempt for {0}", username);
                }
            }

            var collection = response.Data;

            lock (LockObject)
            {
                foreach (var game in collection.Items)
                {
                    var id = game.Id;

                    GameNames[id] = game.Name;

                    if (game.Owned)
                    {
                        var owners = Owners.GetOrCreate(id, () => new List<string>());
                        owners.Add(username);
                    }

                    if (game.WantToPlay)
                    {
                        var players = WantToPlay.GetOrCreate(id, () => new List<string>());
                        players.Add(username);
                    }
                }
            }
        }