public static RunStatus Parse(SpeedrunComClient client, dynamic statusElement) { var status = new RunStatus(); var properties = statusElement.Properties as IDictionary<string, dynamic>; status.Type = ParseType(statusElement.status as string); if (status.Type == RunStatusType.Rejected || status.Type == RunStatusType.Verified) { status.ExaminerUserID = statusElement.examiner as string; status.examiner = new Lazy<User>(() => client.Users.GetUser(status.ExaminerUserID)); if (status.Type == RunStatusType.Verified) { var date = properties["verify-date"] as string; if (!string.IsNullOrEmpty(date)) status.VerifyDate = DateTime.Parse(date, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } } else { status.examiner = new Lazy<User>(() => null); } if (status.Type == RunStatusType.Rejected) { status.Reason = statusElement.reason as string; } return status; }
public static UserNameStyle Parse(SpeedrunComClient client, dynamic styleElement) { var style = new UserNameStyle(); style.IsGradient = styleElement.style == "gradient"; if (style.IsGradient) { var properties = styleElement.Properties as IDictionary<string, dynamic>; var colorFrom = properties["color-from"]; var colorTo = properties["color-to"]; style.LightGradientStartColorCode = colorFrom.light as string; style.LightGradientEndColorCode = colorTo.light as string; style.DarkGradientStartColorCode = colorFrom.dark as string; style.DarkGradientEndColorCode = colorTo.dark as string; } else { style.LightSolidColorCode = styleElement.color.light as string; style.DarkSolidColorCode = styleElement.color.dark as string; } return style; }
public static new Record Parse(SpeedrunComClient client, dynamic recordElement) { var record = new Record(); record.Rank = recordElement.place; //Parse potential embeds var properties = recordElement.Properties as IDictionary<string, dynamic>; if (properties.ContainsKey("game")) recordElement.run.game = recordElement.game; if (properties.ContainsKey("category")) recordElement.run.category = recordElement.category; if (properties.ContainsKey("level")) recordElement.run.level = recordElement.level; if (properties.ContainsKey("players")) recordElement.run.players = recordElement.players; if (properties.ContainsKey("region")) recordElement.run.region = recordElement.region; if (properties.ContainsKey("platform")) recordElement.run.platform = recordElement.platform; Run.Parse(record, client, recordElement.run); return record; }
public static RunSystem Parse(SpeedrunComClient client, dynamic systemElement) { var system = new RunSystem(); system.IsEmulated = (bool)systemElement.emulated; if (!string.IsNullOrEmpty(systemElement.platform as string)) { system.PlatformID = systemElement.platform as string; system.platform = new Lazy<Platform>(() => client.Platforms.GetPlatform(system.PlatformID)); } else { system.platform = new Lazy<Platform>(() => null); } if (!string.IsNullOrEmpty(systemElement.region as string)) { system.RegionID = systemElement.region as string; system.region = new Lazy<Region>(() => client.Regions.GetRegion(system.RegionID)); } else { system.region = new Lazy<Region>(() => null); } return system; }
public static Guest Parse(SpeedrunComClient client, dynamic guestElement) { var guest = new Guest(); guest.Name = guestElement.name; guest.Runs = client.Runs.GetRuns(guestName: guest.Name); return guest; }
public static Players Parse(SpeedrunComClient client, dynamic playersElement) { var players = new Players(); players.Value = (int)playersElement.value; players.Type = playersElement.type == "exactly" ? PlayersType.Exactly : PlayersType.UpTo; return players; }
public static Notification Parse(SpeedrunComClient client, dynamic notificationElement) { var notification = new Notification(); //Parse Attributes notification.ID = notificationElement.id as string; notification.TimeCreated = DateTime.Parse(notificationElement.created as string, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); notification.Status = NotificationStatusHelpers.Parse(notificationElement.status as string); notification.Text = notificationElement.text as string; notification.Type = NotificationTypeHelpers.Parse(notificationElement.item.rel as string); notification.WebLink = new Uri(notificationElement.item.uri as string); //Parse Links var links = notificationElement.links as IList<dynamic>; if (links != null) { var run = links.FirstOrDefault(x => x.rel == "run"); if (run != null) { var runUri = run.uri as string; notification.RunID = runUri.Substring(runUri.LastIndexOf("/") + 1); } var game = links.FirstOrDefault(x => x.rel == "game"); if (game != null) { var gameUri = game.uri as string; notification.GameID = gameUri.Substring(gameUri.LastIndexOf("/") + 1); } } if (!string.IsNullOrEmpty(notification.RunID)) { notification.run = new Lazy<Run>(() => client.Runs.GetRun(notification.RunID)); } else { notification.run = new Lazy<Run>(() => null); } if (!string.IsNullOrEmpty(notification.GameID)) { notification.game = new Lazy<Game>(() => client.Games.GetGame(notification.GameID)); } else { notification.game = new Lazy<Game>(() => null); } return notification; }
public static Country Parse(SpeedrunComClient client, dynamic countryElement) { var country = new Country(); country.Code = countryElement.code as string; country.Name = countryElement.names.international as string; country.JapaneseName = countryElement.names.japanese as string; return country; }
public static CountryRegion Parse(SpeedrunComClient client, dynamic regionElement) { var region = new CountryRegion(); region.Code = regionElement.code as string; region.Name = regionElement.names.international as string; region.JapaneseName = regionElement.names.japanese as string; return region; }
public static GameHeader Parse(SpeedrunComClient client, dynamic gameHeaderElement) { var gameHeader = new GameHeader(); gameHeader.ID = gameHeaderElement.id as string; gameHeader.Name = gameHeaderElement.names.international as string; gameHeader.JapaneseName = gameHeaderElement.names.japanese as string; gameHeader.WebLink = new Uri(gameHeaderElement.weblink as string); gameHeader.Abbreviation = gameHeaderElement.abbreviation as string; return gameHeader; }
public static Moderator Parse(SpeedrunComClient client, KeyValuePair<string, dynamic> moderatorElement) { var moderator = new Moderator(); moderator.UserID = moderatorElement.Key; moderator.Type = moderatorElement.Value as string == "moderator" ? ModeratorType.Moderator : ModeratorType.SuperModerator; moderator.user = new Lazy<User>(() => client.Users.GetUser(moderator.UserID)); return moderator; }
public static RunVideos Parse(SpeedrunComClient client, dynamic videosElement) { if (videosElement == null) return null; var videos = new RunVideos(); videos.Text = videosElement.text as string; videos.Links = client.ParseCollection(videosElement.links, new Func<dynamic, Uri>(parseVideoLink)); return videos; }
public static Location Parse(SpeedrunComClient client, dynamic locationElement) { var location = new Location(); if (locationElement != null) { location.Country = Country.Parse(client, locationElement.country) as Country; if (locationElement.region != null) location.Region = CountryRegion.Parse(client, locationElement.region) as CountryRegion; } return location; }
public static ImageAsset Parse(SpeedrunComClient client, dynamic imageElement) { if (imageElement == null) return null; var image = new ImageAsset(); var uri = imageElement.uri as string; image.Uri = new Uri(uri); image.Width = (int)imageElement.width; image.Height = (int)imageElement.height; return image; }
public static VariableValue ParseValueDescriptor(SpeedrunComClient client, KeyValuePair<string, dynamic> valueElement) { var value = new VariableValue(); value.VariableID = valueElement.Key; value.ID = valueElement.Value as string; //Parse Links value.variable = new Lazy<Variable>(() => client.Variables.GetVariable(value.VariableID)); value.value = new Lazy<string>(() => value.Variable.Choices.FirstOrDefault(x => x.ID == value.ID).Value); return value; }
public static Level Parse(SpeedrunComClient client, dynamic levelElement) { if (levelElement is ArrayList) return null; var level = new Level(); //Parse Attributes level.ID = levelElement.id as string; level.Name = levelElement.name as string; level.WebLink = new Uri(levelElement.weblink as string); level.Rules = levelElement.rules; //Parse Links var properties = levelElement.Properties as IDictionary<string, dynamic>; var links = properties["links"] as IEnumerable<dynamic>; var gameUri = links.First(x => x.rel == "game").uri as string; level.GameID = gameUri.Substring(gameUri.LastIndexOf('/') + 1); level.game = new Lazy<Game>(() => client.Games.GetGame(level.GameID)); if (properties.ContainsKey("categories")) { Func<dynamic, Category> categoryParser = x => Category.Parse(client, x) as Category; ReadOnlyCollection<Category> categories = client.ParseCollection(levelElement.categories.data, categoryParser); level.categories = new Lazy<ReadOnlyCollection<Category>>(() => categories); } else { level.categories = new Lazy<ReadOnlyCollection<Category>>(() => client.Levels.GetCategories(level.ID)); } if (properties.ContainsKey("variables")) { Func<dynamic, Variable> variableParser = x => Variable.Parse(client, x) as Variable; ReadOnlyCollection<Variable> variables = client.ParseCollection(levelElement.variables.data, variableParser); level.variables = new Lazy<ReadOnlyCollection<Variable>>(() => variables); } else { level.variables = new Lazy<ReadOnlyCollection<Variable>>(() => client.Levels.GetVariables(level.ID)); } level.Runs = client.Runs.GetRuns(levelId: level.ID); return level; }
public static VariableValue ParseIDPair(SpeedrunComClient client, Variable variable, KeyValuePair<string, dynamic> valueElement) { var value = new VariableValue(); value.VariableID = variable.ID; value.ID = valueElement.Key as string; //Parse Links value.variable = new Lazy<Variable>(() => variable); var valueName = valueElement.Value as string; value.value = new Lazy<string>(() => valueName); return value; }
public WorldRecordComponent(LiveSplitState state) { State = state; Client = new SpeedrunComClient(userAgent: Updates.UpdateHelper.UserAgent, maxCacheElements: 0); RefreshInterval = TimeSpan.FromMinutes(5); Cache = new GraphicsCache(); TimeFormatter = new AutomaticPrecisionTimeFormatter(); LocalTimeFormatter = new RegularTimeFormatter(); InternalComponent = new InfoTextComponent("World Record", "-"); Settings = new WorldRecordSettings() { CurrentState = state }; }
public static Ruleset Parse(SpeedrunComClient client, dynamic rulesetElement) { var ruleset = new Ruleset(); var properties = rulesetElement.Properties as IDictionary<string, dynamic>; ruleset.ShowMilliseconds = properties["show-milliseconds"]; ruleset.RequiresVerification = properties["require-verification"]; ruleset.RequiresVideo = properties["require-video"]; Func<dynamic, TimingMethod> timingMethodParser = x => TimingMethodHelpers.FromString(x as string); ruleset.TimingMethods = client.ParseCollection(properties["run-times"], timingMethodParser); ruleset.DefaultTimingMethod = TimingMethodHelpers.FromString(properties["default-time"]); ruleset.EmulatorsAllowed = properties["emulators-allowed"]; return ruleset; }
public static RunTimes Parse(SpeedrunComClient client, dynamic timesElement) { var times = new RunTimes(); if (timesElement.primary != null) times.Primary = TimeSpan.FromSeconds((double)timesElement.primary_t); if (timesElement.realtime != null) times.RealTime = TimeSpan.FromSeconds((double)timesElement.realtime_t); if (timesElement.realtime_noloads != null) times.RealTimeWithoutLoads = TimeSpan.FromSeconds((double)timesElement.realtime_noloads_t); if (timesElement.ingame != null) times.GameTime = TimeSpan.FromSeconds((double)timesElement.ingame_t); return times; }
public static VariableScope Parse(SpeedrunComClient client, dynamic scopeElement) { var scope = new VariableScope(); scope.Type = parseType(scopeElement.type as string); if (scope.Type == VariableScopeType.SingleLevel) { scope.LevelID = scopeElement.level as string; scope.level = new Lazy<Level>(() => client.Levels.GetLevel(scope.LevelID)); } else { scope.level = new Lazy<Level>(() => null); } return scope; }
public static Region Parse(SpeedrunComClient client, dynamic regionElement) { if (regionElement is ArrayList) return null; var region = new Region(); //Parse Attributes region.ID = regionElement.id as string; region.Name = regionElement.name as string; //Parse Links region.Games = client.Games.GetGames(regionId: region.ID); region.Runs = client.Runs.GetRuns(regionId: region.ID); return region; }
public static Platform Parse(SpeedrunComClient client, dynamic platformElement) { if (platformElement is ArrayList) return null; var platform = new Platform(); //Parse Attributes platform.ID = platformElement.id as string; platform.Name = platformElement.name as string; platform.YearOfRelease = (int)platformElement.released; //Parse Links platform.Games = client.Games.GetGames(platformId: platform.ID); platform.Runs = client.Runs.GetRuns(platformId: platform.ID); return platform; }
public static Player Parse(SpeedrunComClient client, dynamic playerElement) { var player = new Player(); var properties = playerElement.Properties as IDictionary<string, dynamic>; if (properties.ContainsKey("uri")) { if (playerElement.rel as string == "user") { player.UserID = playerElement.id as string; player.user = new Lazy<User>(() => client.Users.GetUser(player.UserID)); player.guest = new Lazy<Guest>(() => null); } else { player.GuestName = playerElement.name as string; player.guest = new Lazy<Guest>(() => client.Guests.GetGuest(player.GuestName)); player.user = new Lazy<User>(() => null); } } else { if (playerElement.rel as string == "user") { var user = User.Parse(client, playerElement) as User; player.user = new Lazy<User>(() => user); player.UserID = user.ID; player.guest = new Lazy<Guest>(() => null); } else { var guest = Guest.Parse(client, playerElement) as Guest; player.guest = new Lazy<Guest>(() => guest); player.GuestName = guest.Name; player.user = new Lazy<User>(() => null); } } return player; }
public static Assets Parse(SpeedrunComClient client, dynamic assetsElement) { var assets = new Assets(); var properties = assetsElement.Properties as IDictionary<string, dynamic>; assets.Logo = ImageAsset.Parse(client, assetsElement.logo) as ImageAsset; assets.CoverTiny = ImageAsset.Parse(client, properties["cover-tiny"]) as ImageAsset; assets.CoverSmall = ImageAsset.Parse(client, properties["cover-small"]) as ImageAsset; assets.CoverMedium = ImageAsset.Parse(client, properties["cover-medium"]) as ImageAsset; assets.CoverLarge = ImageAsset.Parse(client, properties["cover-large"]) as ImageAsset; assets.Icon = ImageAsset.Parse(client, assetsElement.icon) as ImageAsset; assets.TrophyFirstPlace = ImageAsset.Parse(client, properties["trophy-1st"]) as ImageAsset; assets.TrophySecondPlace = ImageAsset.Parse(client, properties["trophy-2nd"]) as ImageAsset; assets.TrophyThirdPlace = ImageAsset.Parse(client, properties["trophy-3rd"]) as ImageAsset; assets.TrophyFourthPlace = ImageAsset.Parse(client, properties["trophy-4th"]) as ImageAsset; assets.BackgroundImage = ImageAsset.Parse(client, assetsElement.background) as ImageAsset; assets.ForegroundImage = ImageAsset.Parse(client, assetsElement.foreground) as ImageAsset; return assets; }
static SpeedrunCom() { ShareSettings.Default.Reload(); Client = new SpeedrunComClient("LiveSplit/" + Updates.UpdateHelper.Version, ShareSettings.Default.SpeedrunComAccessToken); }
public RunsClient(SpeedrunComClient baseClient) { this.baseClient = baseClient; }
private string GetWR(string game, bool isCurrent, string category, string level, Dictionary <string, string> subcategories, Dictionary <string, string> variables) { try { SetParameters(ref isCurrent, ref category, ref level, ref subcategories, ref variables); if (game == "") { return("No game provided"); } var srSearch = new SpeedrunComClient(); var srGame = srSearch.Games.SearchGame(game); if (srGame == null) { return("No game was found"); } else { //Levels generally have different category, so they need a seperate look up if (level != "") { Category srCategory; if (category == "") { srCategory = srGame.LevelCategories.ElementAt(0); } else { srCategory = srGame.LevelCategories.FirstOrDefault(cat => cat.Name.ToLower().StartsWith(category.ToLower())); } if (srCategory == null) { return("No category was found"); } var srLevel = srGame.Levels.FirstOrDefault(lvl => lvl.Name.ToLower().StartsWith(level.ToLower())); if (srLevel == null) { return("No level was found"); } //Haven't tested this for levels List <VariableValue> lookVariable = GetVariablesForLevel(ref subcategories, ref variables, ref srCategory, ref srLevel); var leaderboard = srSearch.Leaderboards.GetLeaderboardForLevel(srGame.ID, srLevel.ID, srCategory.ID, variableFilters: lookVariable); if (leaderboard.Records.Count > 0) { var record = leaderboard.Records[0]; string runners = ""; if (record.Players.Count > 1) { for (int i = 0; i < record.Players.Count - 1; i++) { runners += record.Players[i].Name + ", "; } runners += record.Players[record.Players.Count - 1].Name; } else { runners = record.Player.Name; } return(string.Format("{0} - Level: {1} WR ({2}) is {3} by {4} - {5}", srGame.Name, srLevel.Name, srCategory.Name, record.Times.Primary.ToString(), runners, record.WebLink.ToString() )); } else { return(string.Format("No records were found! - {0}", leaderboard.WebLink)); } } //Full-game run else { Category srCategory; if (category == "") { srCategory = srGame.FullGameCategories.ElementAt(0); } else { srCategory = srGame.FullGameCategories.FirstOrDefault(cat => cat.Name.ToLower().StartsWith(category.ToLower())); } if (srCategory == null) { return("No category was found"); } List <VariableValue> lookVariable = GetVariablesForFullGameCategory(ref subcategories, ref variables, ref srCategory); var leaderboard = srSearch.Leaderboards.GetLeaderboardForFullGameCategory(srGame.ID, srCategory.ID, variableFilters: lookVariable); if (leaderboard.Records.Count > 0) { var record = leaderboard.Records[0]; string runners = ""; if (record.Players.Count > 1) { for (int i = 0; i < record.Players.Count - 1; i++) { runners += record.Players[i].Name + ", "; } runners += record.Players[record.Players.Count - 1].Name; } else { runners = record.Player.Name; } return(string.Format("{0} ({1}) record is {2} by {3} - {4}", srGame.Name, srCategory.Name, record.Times.Primary.ToString(), runners, record.WebLink )); } else { return("Leaderboard doesn't have any records! " + leaderboard.WebLink); }; } } } catch (Exception e) { ErrorLogging.WriteLine(e.ToString()); return("Error looking for a game on speedrun.com."); } }
private string GetPB(string game, bool isCurrentGame, string category, string level, Dictionary <string, string> subcategories, Dictionary <string, string> variables) { try { SetParameters(ref isCurrentGame, ref category, ref level, ref subcategories, ref variables); var srSearch = new SpeedrunComClient(); var srGame = srSearch.Games.SearchGame(game); if (srGame == null) { return("No game was found"); } else { //Levels generally have different category, so they need a seperate look up if (level != "") { Category srCategory; if (category == "") { srCategory = srGame.LevelCategories.ElementAt(0); } else { srCategory = srGame.LevelCategories.FirstOrDefault(cat => cat.Name.ToLower().StartsWith(category.ToLower())); } if (srCategory == null) { return("No category was found"); } var srLevel = srGame.Levels.FirstOrDefault(lvl => lvl.Name.ToLower().StartsWith(level.ToLower())); if (srLevel == null) { return("No level was found"); } var pbs = srSearch.Users.GetPersonalBests(Speedrunusername, gameId: srGame.ID); var levelPBs = pbs.Where(x => x.LevelID == srLevel.ID); if (levelPBs.Count() > 0) { var SRVariables = GetVariablesForLevel(ref subcategories, ref variables, ref srCategory, ref srLevel); var bestPBsInCategory = levelPBs.Where(x => x.Category.ID == srCategory.ID); if (SRVariables != null) { for (int i = 0; i < SRVariables.Count; i++) { bestPBsInCategory = bestPBsInCategory.Where(x => x.VariableValues.Contains(SRVariables[i])); } } var bestPBInCategory = bestPBsInCategory.FirstOrDefault(); if (bestPBInCategory != null) { return(string.Format("Streamer\'s PB for {0} ({1}) in level \"{2}\" is {3} - {4}", srGame.Name, srCategory.Name, srLevel.Name, bestPBInCategory.Times.Primary.ToString(), bestPBInCategory.WebLink)); } else { return(string.Format("No PB in category {0} for level {1} was found.", srCategory.Name, srLevel.Name)); } } else { return("No PBs found for this level"); } } else //Full-game run { Category srCategory; if (category == "") { srCategory = srGame.FullGameCategories.ElementAt(0); } else { srCategory = srGame.FullGameCategories.FirstOrDefault(cat => cat.Name.ToLower().StartsWith(category.ToLower())); } if (srCategory == null) { return("No category was found"); } var pbs = srSearch.Users.GetPersonalBests(Speedrunusername, gameId: srGame.ID); if (pbs.Count > 0) { var SRVariables = GetVariablesForFullGameCategory(ref subcategories, ref variables, ref srCategory); var bestPBsInCategory = pbs.Where(x => x.Category.ID == srCategory.ID); if (SRVariables != null) { for (int i = 0; i < SRVariables.Count; i++) { bestPBsInCategory = bestPBsInCategory.Where(x => x.VariableValues.Contains(SRVariables[i])); } } if (bestPBsInCategory.Count() > 0) { return(string.Format("Streamer\'s PB for {0} ({1}) is {2} - {3}", srGame.Name, srCategory.Name, bestPBsInCategory.ElementAt(0).Times.Primary.ToString(), bestPBsInCategory.ElementAt(0).WebLink)); } else { return("Stremer doesn\'t seem to have any PBs in category " + srCategory.Name); } } else { return("Streamer doesn\'t have any PBs in this game."); } } } } catch (Exception e) { ErrorLogging.WriteLine(e.ToString()); return("Error looking for a game on speedrun.com"); } }
public CategoriesClient(SpeedrunComClient baseClient) { this.baseClient = baseClient; }
static SpeedrunCom() { ShareSettings.Default.Reload(); Client = new SpeedrunComClient("LiveSplit/" + Updates.UpdateHelper.Version, ShareSettings.Default.SpeedrunComAccessToken); }
public LevelsClient(SpeedrunComClient baseClient) { this.baseClient = baseClient; }
public SeriesClient(SpeedrunComClient baseClient) { this.baseClient = baseClient; }
static SpeedrunCom() { Client = new SpeedrunComClient(Updates.UpdateHelper.UserAgent, WebCredentials.SpeedrunComAccessToken); }
static SpeedrunCom() { ShareSettings.Default.Reload(); Client = new SpeedrunComClient(Updates.UpdateHelper.UserAgent, ShareSettings.Default.SpeedrunComAccessToken); }
public static Game Parse(SpeedrunComClient client, dynamic gameElement) { var game = new Game(); //Parse Attributes game.Header = GameHeader.Parse(client, gameElement); game.YearOfRelease = gameElement.released; game.Ruleset = Ruleset.Parse(client, gameElement.ruleset); game.IsRomHack = gameElement.romhack; var created = gameElement.created as string; if (!string.IsNullOrEmpty(created)) game.CreationDate = DateTime.Parse(created, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); game.Assets = Assets.Parse(client, gameElement.assets); //Parse Embeds var properties = gameElement.Properties as IDictionary<string, dynamic>; if (gameElement.moderators is DynamicJsonObject && gameElement.moderators.Properties.ContainsKey("data")) { Func<dynamic, User> userParser = x => User.Parse(client, x) as User; ReadOnlyCollection<User> users = client.ParseCollection(gameElement.moderators.data, userParser); game.moderatorUsers = new Lazy<ReadOnlyCollection<User>>(() => users); } else if (gameElement.moderators is DynamicJsonObject) { var moderatorsProperties = gameElement.moderators.Properties as IDictionary<string, dynamic>; game.Moderators = moderatorsProperties.Select(x => Moderator.Parse(client, x)).ToList().AsReadOnly(); game.moderatorUsers = new Lazy<ReadOnlyCollection<User>>( () => { ReadOnlyCollection<User> users; if (game.Moderators.Count(x => !x.user.IsValueCreated) > 1) { users = client.Games.GetGame(game.ID, embeds: new GameEmbeds(embedModerators: true)).ModeratorUsers; foreach (var user in users) { var moderator = game.Moderators.FirstOrDefault(x => x.UserID == user.ID); if (moderator != null) { moderator.user = new Lazy<User>(() => user); } } } else { users = game.Moderators.Select(x => x.User).ToList().AsReadOnly(); } return users; }); } else { game.Moderators = new ReadOnlyCollection<Moderator>(new Moderator[0]); game.moderatorUsers = new Lazy<ReadOnlyCollection<User>>(() => new List<User>().AsReadOnly()); } if (properties["platforms"] is IList) { game.PlatformIDs = client.ParseCollection<string>(gameElement.platforms); if (game.PlatformIDs.Count > 1) { game.platforms = new Lazy<ReadOnlyCollection<Platform>>( () => client.Games.GetGame(game.ID, embeds: new GameEmbeds(embedPlatforms: true)).Platforms); } else { game.platforms = new Lazy<ReadOnlyCollection<Platform>>( () => game.PlatformIDs.Select(x => client.Platforms.GetPlatform(x)).ToList().AsReadOnly()); } } else { Func<dynamic, Platform> platformParser = x => Platform.Parse(client, x) as Platform; ReadOnlyCollection<Platform> platforms = client.ParseCollection(gameElement.platforms.data, platformParser); game.platforms = new Lazy<ReadOnlyCollection<Platform>>(() => platforms); game.PlatformIDs = platforms.Select(x => x.ID).ToList().AsReadOnly(); } if (properties["regions"] is IList) { game.RegionIDs = client.ParseCollection<string>(gameElement.regions); if (game.RegionIDs.Count > 1) { game.regions = new Lazy<ReadOnlyCollection<Region>>( () => client.Games.GetGame(game.ID, embeds: new GameEmbeds(embedRegions: true)).Regions); } else { game.regions = new Lazy<ReadOnlyCollection<Region>>( () => game.RegionIDs.Select(x => client.Regions.GetRegion(x)).ToList().AsReadOnly()); } } else { Func<dynamic, Region> regionParser = x => Region.Parse(client, x) as Region; ReadOnlyCollection<Region> regions = client.ParseCollection(gameElement.regions.data, regionParser); game.regions = new Lazy<ReadOnlyCollection<Region>>(() => regions); game.RegionIDs = regions.Select(x => x.ID).ToList().AsReadOnly(); } //Parse Links game.Runs = client.Runs.GetRuns(gameId: game.ID); if (properties.ContainsKey("levels")) { Func<dynamic, Level> levelParser = x => Level.Parse(client, x) as Level; ReadOnlyCollection<Level> levels = client.ParseCollection(gameElement.levels.data, levelParser); game.levels = new Lazy<ReadOnlyCollection<Level>>(() => levels); } else { game.levels = new Lazy<ReadOnlyCollection<Level>>(() => client.Games.GetLevels(game.ID)); } if (properties.ContainsKey("categories")) { Func<dynamic, Category> categoryParser = x => Category.Parse(client, x) as Category; ReadOnlyCollection<Category> categories = client.ParseCollection(gameElement.categories.data, categoryParser); foreach (var category in categories) { category.game = new Lazy<Game>(() => game); } game.categories = new Lazy<ReadOnlyCollection<Category>>(() => categories); } else { game.categories = new Lazy<ReadOnlyCollection<Category>>(() => { var categories = client.Games.GetCategories(game.ID); foreach (var category in categories) { category.game = new Lazy<Game>(() => game); } return categories; }); } if (properties.ContainsKey("variables")) { Func<dynamic, Variable> variableParser = x => Variable.Parse(client, x) as Variable; ReadOnlyCollection<Variable> variables = client.ParseCollection(gameElement.variables.data, variableParser); game.variables = new Lazy<ReadOnlyCollection<Variable>>(() => variables); } else { game.variables = new Lazy<ReadOnlyCollection<Variable>>(() => client.Games.GetVariables(game.ID)); } var links = properties["links"] as IEnumerable<dynamic>; var seriesLink = links.FirstOrDefault(x => x.rel == "series"); if (seriesLink != null) { var parentUri = seriesLink.uri as string; game.SeriesID = parentUri.Substring(parentUri.LastIndexOf('/') + 1); game.series = new Lazy<Series>(() => client.Series.GetSingleSeries(game.SeriesID)); } else { game.series = new Lazy<Series>(() => null); } var originalGameLink = links.FirstOrDefault(x => x.rel == "game"); if (originalGameLink != null) { var originalGameUri = originalGameLink.uri as string; game.OriginalGameID = originalGameUri.Substring(originalGameUri.LastIndexOf('/') + 1); game.originalGame = new Lazy<Game>(() => client.Games.GetGame(game.OriginalGameID)); } else { game.originalGame = new Lazy<Game>(() => null); } game.romHacks = new Lazy<ReadOnlyCollection<Game>>(() => { var romHacks = client.Games.GetRomHacks(game.ID); if (romHacks != null) { foreach (var romHack in romHacks) { romHack.originalGame = new Lazy<Game>(() => game); } } return romHacks; }); return game; }