Example #1
0
        public static void buildList(BrowserController controller)
        {
            List <Friend> list     = new List <Friend>();
            string        queryUrl = String.Format("http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key={0}&steamid={1}&relationship=friend", Properties.Settings.Default.SteamWebAPIKey, controller.user.steam.steamid);

            using (WebClient c = new WebClient())
            {
                c.DownloadStringAsync(new Uri(queryUrl));
                c.DownloadStringCompleted += (s, e) =>
                {
                    try
                    {
                        dynamic result = JObject.Parse(e.Result);
                        List <MongoDB.Driver.IMongoQuery> queries = new List <MongoDB.Driver.IMongoQuery>();
                        foreach (var friend in result.friendslist.friends)
                        {
                            queries.Add(Query.EQ("steam.steamid", (string)friend.steamid));
                        }
                        if (queries.Count > 0)
                        {
                            var users = Mongo.Users.FindAs <User>(Query.Or(queries)).ToList();
                            list.AddRange(users.Select(usr => new Friend()
                            {
                                id = usr.steam.steamid, name = usr == null ? null : usr.profile.name, status = usr == null ? FriendStatus.NotRegistered : getFriendStatus(usr.steam.steamid), avatar = usr == null ? null : usr.steam.avatar
                            }));
                            controller.friendlist = list;
                            controller.Send(BrowserController.FriendsSnapshot(list));
                        }
                    }
                    catch (Exception ex)
                    {
                        //log.Error("Could get build list.", ex);
                    }
                };
            }
        }