Ejemplo n.º 1
0
        internal static LCRanking Parse(IDictionary <string, object> data)
        {
            LCRanking ranking = new LCRanking();

            if (data.TryGetValue("rank", out object rank))
            {
                ranking.Rank = Convert.ToInt32(rank);
            }
            if (data.TryGetValue("user", out object user))
            {
                LCObjectData objectData = LCObjectData.Decode(user as System.Collections.IDictionary);
                ranking.User = LCUser.GenerateUser(objectData);
            }
            if (data.TryGetValue("statisticName", out object statisticName))
            {
                ranking.StatisticName = statisticName as string;
            }
            if (data.TryGetValue("statisticValue", out object value))
            {
                ranking.Value = Convert.ToDouble(value);
            }
            if (data.TryGetValue("statistics", out object statistics) &&
                statistics is List <object> list)
            {
                List <LCStatistic> statisticList = new List <LCStatistic>();
                foreach (object item in list)
                {
                    LCStatistic statistic = LCStatistic.Parse(item as IDictionary <string, object>);
                    statisticList.Add(statistic);
                }
                ranking.IncludedStatistics = statisticList.AsReadOnly();
            }
            return(ranking);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the rankings of the user.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="version"></param>
        /// <param name="skip"></param>
        /// <param name="limit"></param>
        /// <param name="selectUserKeys"></param>
        /// <param name="includeStatistics"></param>
        /// <returns></returns>
        private async Task <ReadOnlyCollection <LCRanking> > GetResults(LCUser user,
                                                                        int version,
                                                                        int skip,
                                                                        int limit,
                                                                        IEnumerable <string> selectUserKeys,
                                                                        IEnumerable <string> includeStatistics)
        {
            string path = $"leaderboard/leaderboards/{StatisticName}/ranks";

            if (user != null)
            {
                path = $"{path}/{user.ObjectId}";
            }
            path = $"{path}?skip={skip}&limit={limit}";
            if (version != -1)
            {
                path = $"{path}&version={version}";
            }
            if (selectUserKeys != null)
            {
                string keys = string.Join(",", selectUserKeys);
                path = $"{path}&includeUser={keys}";
            }
            if (includeStatistics != null)
            {
                string statistics = string.Join(",", includeStatistics);
                path = $"{path}&includeStatistics={statistics}";
            }
            Dictionary <string, object> result = await LCCore.HttpClient.Get <Dictionary <string, object> >(path);

            if (result.TryGetValue("results", out object results) &&
                results is List <object> list)
            {
                List <LCRanking> rankings = new List <LCRanking>();
                foreach (object item in list)
                {
                    LCRanking ranking = LCRanking.Parse(item as IDictionary <string, object>);
                    rankings.Add(ranking);
                }
                return(rankings.AsReadOnly());
            }
            return(null);
        }