private void GetUserInfo(int userId) { if (_userMap.ContainsKey(userId)) { return; } Task.Run( () => { string url = string.Format("{0}{1}.campfirenow.com/users/{2}.json", Scheme, _config.AccountName, userId); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.Accept = "application/json"; request.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", EncodedAuthToken); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { JObject userDto = JObject.Parse(reader.ReadToEnd()); JObject body = (JObject)userDto["user"]; UserInfo user = new UserInfo { id = userId, name = body["name"].ToString() }; _userMap.Add(userId, user); } }); }
private void PreloadUsers() { string url = string.Format("{0}{1}.campfirenow.com/room/{2}.json", Scheme, _config.AccountName, _roomId); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; request.Accept = "application/json"; request.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", EncodedAuthToken); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { JObject userDto = JObject.Parse(reader.ReadToEnd()); JObject body = (JObject)userDto["room"]; JArray users = (JArray)body["users"]; foreach (JObject user in users) { UserInfo userInfo = new UserInfo { id = (int)user["id"], name = user["name"].ToString() }; _userMap.Add(userInfo.id, userInfo); } } }