public static User Parse(SpeedrunComClient client, dynamic userElement) { var user = new User(); var properties = userElement.Properties as IDictionary <string, dynamic>; //Parse Attributes user.ID = userElement.id as string; user.Name = userElement.names.international as string; user.JapaneseName = userElement.names.japanese as string; user.WebLink = new Uri(userElement.weblink as string); user.NameStyle = UserNameStyle.Parse(client, properties["name-style"]) as UserNameStyle; user.Role = parseUserRole(userElement.role as string); var signUpDate = userElement.signup as string; if (!string.IsNullOrEmpty(signUpDate)) { user.SignUpDate = DateTime.Parse(signUpDate, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } user.Location = Location.Parse(client, userElement.location) as Location; var twitchLink = userElement.twitch; if (twitchLink != null) { user.TwitchProfile = new Uri(twitchLink.uri as string); } var hitboxLink = userElement.hitbox; if (hitboxLink != null) { user.HitboxProfile = new Uri(hitboxLink.uri as string); } var youtubeLink = userElement.youtube; if (youtubeLink != null) { user.YoutubeProfile = new Uri(youtubeLink.uri as string); } var twitterLink = userElement.twitter; if (twitterLink != null) { user.TwitterProfile = new Uri(twitterLink.uri as string); } var speedRunsLiveLink = userElement.speedrunslive; if (speedRunsLiveLink != null) { user.SpeedRunsLiveProfile = new Uri(speedRunsLiveLink.uri as string); } //Parse Links user.Runs = client.Runs.GetRuns(userId: user.ID); user.ModeratedGames = client.Games.GetGames(moderatorId: user.ID); user.personalBests = new Lazy <ReadOnlyCollection <Record> >(() => { var records = client.Users.GetPersonalBests(userId: user.ID); var lazy = new Lazy <User>(() => user); foreach (var record in records) { var player = record.Players.FirstOrDefault(x => x.UserID == user.ID); if (player != null) { player.user = lazy; } } return(records); }); return(user); }
public static User Parse(SpeedrunComClient client, dynamic userElement) { var user = new User(); var properties = userElement as IDictionary <string, dynamic>; //Parse Attributes user.ID = properties["id"] as string; user.WebLink = new Uri(properties["weblink"] as string); user.NameStyle = UserNameStyle.Parse(client, properties["name-style"]) as UserNameStyle; user.Role = parseUserRole(properties["role"] as string); var nameProperties = properties["names"] as IDictionary <string, dynamic>; user.Name = nameProperties["international"] as string; user.JapaneseName = nameProperties["japanese"] as string; if (properties.ContainsKey("signup")) { user.SignUpDate = (DateTime)userElement.signup; } user.Location = Location.Parse(client, properties["location"]) as Location; var twitchLink = properties["twitch"]; if (twitchLink != null) { user.TwitchProfile = new Uri((string)twitchLink.uri); } var hitboxLink = properties["hitbox"]; if (hitboxLink != null) { user.HitboxProfile = new Uri((string)hitboxLink.uri); } var youtubeLink = properties["youtube"]; if (youtubeLink != null) { user.YoutubeProfile = new Uri((string)youtubeLink.uri); } var twitterLink = properties["twitter"]; if (twitterLink != null) { user.TwitterProfile = new Uri((string)twitterLink.uri); } var speedRunsLiveLink = properties["speedrunslive"]; if (speedRunsLiveLink != null) { user.SpeedRunsLiveProfile = new Uri((string)speedRunsLiveLink.uri); } //Parse Links user.Runs = client.Runs.GetRuns(userId: user.ID); user.ModeratedGames = client.Games.GetGames(moderatorId: user.ID); user.personalBests = new Lazy <ReadOnlyCollection <Record> >(() => { var records = client.Users.GetPersonalBests(userId: user.ID); var lazy = new Lazy <User>(() => user); foreach (var record in records) { var player = record.Players.FirstOrDefault(x => x.UserID == user.ID); if (player != null) { player.user = lazy; } } return(records); }); return(user); }