Esempio n. 1
0
        private Collections GetPlayerCollections(string username, string collectionNameSavePattern,
                                                 ScoreSaveConditions configuration)
        {
            _currentUserMissingMapCount = 0;
            var validScores = GetPlayerScores(username, configuration);
            Dictionary <string, Beatmaps> collectionsDict = new Dictionary <string, Beatmaps>();
            var collections = new Collections();

            foreach (var s in validScores)
            {
                if (configuration.IsEgibleForSaving(s))
                {
                    string collectionName = CreateCollectionName(s, username, collectionNameSavePattern);
                    if (collectionsDict.ContainsKey(collectionName))
                    {
                        collectionsDict[collectionName].Add(GetBeatmapFromId(s.BeatmapId));
                    }
                    else
                    {
                        collectionsDict.Add(collectionName, new Beatmaps()
                        {
                            GetBeatmapFromId(s.BeatmapId)
                        });
                    }
                }
            }
            foreach (var c in collectionsDict)
            {
                var collection = new Collection(_mapCacher)
                {
                    Name = c.Key
                };
                foreach (var beatmap in c.Value)
                {
                    collection.AddBeatmap(beatmap);
                }
                collections.Add(collection);
            }
            return(collections);
        }
Esempio n. 2
0
        private IList <ApiScore> GetPlayerScores(string username, PlayMode gamemode, ScoreSaveConditions configuration)
        {
            Log(username, string.Format(GettingScores, 1));
            var scoresFromCache =
                _scoreCache.FirstOrDefault(s => s.Key.Username == username & s.Key.PlayMode == gamemode).Value;

            if (scoresFromCache != null)
            {
                return(scoresFromCache);
            }

            List <ApiScore>  egibleScores = new List <ApiScore>();
            IList <ApiScore> scores;

            do
            {
                int i        = 1;
                int Cooldown = 20;
                do
                {
                    Log(username, string.Format(GettingScores, i));
                    scores = _osuApi.GetUserBest(username, (PlayMode)gamemode);
                } while (scores == null && i++ < 5);
                if (scores == null)
                {
                    Log(username, string.Format(GettingUserFailed, i, Cooldown));
                    Thread.Sleep(Cooldown * 1000);
                }
            } while (scores == null);

            _scoreCache.Add(new UserModePair(username, gamemode), scores);
            foreach (var s in scores)
            {
                if (configuration.IsEgibleForSaving(s))
                {
                    egibleScores.Add(s);
                }
            }
            return(egibleScores);
        }
Esempio n. 3
0
        private IList <ApiScore> GetPlayerScores(string username, ScoreSaveConditions configuration)
        {
            Log(username, string.Format(GettingScores, 1));
            if (_scoreCache.ContainsKey(username))
            {
                return(_scoreCache[username]);
            }

            List <ApiScore>  egibleScores = new List <ApiScore>();
            IList <ApiScore> scores;

            do
            {
                int i        = 1;
                int Cooldown = 20;
                do
                {
                    Log(username, string.Format(GettingScores, i));
                    scores = _osuApi.GetUserBest(username, PlayMode.Osu);
                } while (scores == null && i++ < 5);
                if (scores == null)
                {
                    Log(username, string.Format(GettingUserFailed, i, Cooldown));
                    Thread.Sleep(Cooldown * 1000);
                }
            } while (scores == null);

            _scoreCache.Add(username, scores);
            foreach (var s in scores)
            {
                if (configuration.IsEgibleForSaving(s))
                {
                    egibleScores.Add(s);
                }
            }
            return(egibleScores);
        }