public void loadPersonas(object state) { WebClient wc = new WebClient(); foreach (string shard in shards) { foreach (string pers in mypers[shard].Split(',')) { Driver d = drivers.Where(x => x.DriverProfile.name.Equals(pers)).FirstOrDefault(); if (d == null) { d = new Driver() { DriverProfile = new worldDriverProfile() { name = pers } }; drivers.Add(d); } string uri = "/ws/game/nfsw/driver/" + pers + "/profile?shard=" + shard; try { string json = wc.DownloadString(uribase + uri + (uri.IndexOf("?") == -1 ? "?" : "&") + "output=json"); dynamic obj = JObject.Parse(json); var ev = obj.worldDriverProfile; d.DriverProfile.image= ev.image; d.DriverProfile.level=ev.level; d.DriverProfile.personaId=ev.personaId; } catch (Exception ex) { string s = ex.Message; } uri = "/ws/game/nfsw/driver/"+ pers +"/cars?shard="+shard; try { string json = wc.DownloadString(uribase + uri + (uri.IndexOf("?") == -1 ? "?" : "&") + "output=json"); dynamic obj = JObject.Parse(json); d.Cars = new List<worldCars>(); foreach (var ev in obj.worldCars) { var c = new worldCars() { carName = ev.carName, make = ev.make, physicsProfile = new physicsProfile() { acceleration = ev.physicsProfile.acceleration, carClass = ev.physicsProfile.carClass, handling = ev.physicsProfile.handling, rating = ev.physicsProfile.rating, topSpeed = ev.physicsProfile.topSpeed } }; d.Cars.Add(c); } } catch (Exception ex) { string s = ex.Message; } uri = "/ws/game/nfsw/driver/" + pers + "/stats?shard=" + shard; try { string json = wc.DownloadString(uribase + uri + (uri.IndexOf("?") == -1 ? "?" : "&") + "output=json"); if(d.Stats==null) { d.Stats=new worldStats(){eventStats=new List<eventStats>(),skillStats=new List<skillStats>(),streaksStats=new List<streaksStats>()}; } dynamic obj = JObject.Parse(json); d.Stats.eventStats.Clear(); d.Stats.skillStats.Clear(); d.Stats.streaksStats.Clear(); foreach (var ev in obj.worldStats.eventStats) { d.Stats.eventStats.Add(new eventStats() { averageFinishingPlace=ev.averageFinishingPlace, multiPlayerAverageFinishingPlace=ev.multiPlayerAverageFinishingPlace, multiPlayerDnfCount=ev.multiPlayerDnfCount, multiPlayerRacesLost=ev.multiPlayerRacesLost, multiPlayerRacesWon=ev.multiPlayerRacesWon, multiPlayerTotalPlacing=ev.multiPlayerTotalPlacing, singlePlayerAverageFinishingPlace=ev.singlePlayerAverageFinishingPlace, singlePlayerDnfCount=ev.singlePlayerDnfCount, singlePlayerRacesLost=ev.singlePlayerRacesLost, singlePlayerRacesWon=ev.singlePlayerRacesWon, singlePlayerTotalPlacing=ev.singlePlayerTotalPlacing, totalRacesLost=ev.totalRacesLost, totalRacesWon=ev.totalRacesWon }); } /*foreach (var ev in obj.worldStats.skillStats) { }*/ foreach (var ev in obj.worldStats.streaksStats) { d.Stats.streaksStats.Add(new streaksStats(){ bestMultiPlayerWinStreak=ev.bestMultiPlayerWinStreak, bestSinglePlayerWinStreak=ev.bestSinglePlayerWinStreak, currentMultiPlayerWinStreak=ev.currentMultiPlayerWinStreak, currentSinglePlayerWinStreak=ev.currentSinglePlayerWinStreak }); } } catch (Exception ex) { string s = ex.Message; } uri = "/ws/game/nfsw/driver/" + pers + "/lastLogin?shard=" + shard; try { string json = wc.DownloadString(uribase + uri + (uri.IndexOf("?") == -1 ? "?" : "&") + "output=json"); dynamic obj = JObject.Parse(json); d.LastLogin = new worldLastLogin() { date = obj.worldLastLogin.date, day = obj.worldLastLogin.day, hours = obj.worldLastLogin.hours, minutes = obj.worldLastLogin.minutes, month = obj.worldLastLogin.month, seconds = obj.worldLastLogin.seconds, time = obj.worldLastLogin.time, timezoneOffset = obj.worldLastLogin.timezoneOffset, year = obj.worldLastLogin.year }; } catch (Exception ex) { string s = ex.Message; } } } this.Invoke((MethodInvoker)delegate { cntdone++; }); }
public void loadPersonas(object state) { WebClient wc = new WebClient(); foreach (string shard in shards) { foreach (string pers in mypers[shard].Split(',')) { Driver d = drivers.Where(x => x.DriverProfile.name.Equals(pers)).FirstOrDefault(); if (d == null) { d = new Driver() { DriverProfile = new worldDriverProfile() { name = pers } }; drivers.Add(d); } string uri = "/ws/game/nfsw/driver/" + pers + "/profile?shard=" + shard; try { string json = wc.DownloadString(uribase + uri + (uri.IndexOf("?") == -1 ? "?" : "&") + "output=json"); dynamic obj = JObject.Parse(json); var ev = obj.worldDriverProfile; d.DriverProfile.image = ev.image; d.DriverProfile.level = ev.level; d.DriverProfile.personaId = ev.personaId; } catch (Exception ex) { string s = ex.Message; } uri = "/ws/game/nfsw/driver/" + pers + "/cars?shard=" + shard; try { string json = wc.DownloadString(uribase + uri + (uri.IndexOf("?") == -1 ? "?" : "&") + "output=json"); dynamic obj = JObject.Parse(json); d.Cars = new List <worldCars>(); foreach (var ev in obj.worldCars) { var c = new worldCars() { carName = ev.carName, make = ev.make, physicsProfile = new physicsProfile() { acceleration = ev.physicsProfile.acceleration, carClass = ev.physicsProfile.carClass, handling = ev.physicsProfile.handling, rating = ev.physicsProfile.rating, topSpeed = ev.physicsProfile.topSpeed } }; d.Cars.Add(c); } } catch (Exception ex) { string s = ex.Message; } uri = "/ws/game/nfsw/driver/" + pers + "/stats?shard=" + shard; try { string json = wc.DownloadString(uribase + uri + (uri.IndexOf("?") == -1 ? "?" : "&") + "output=json"); if (d.Stats == null) { d.Stats = new worldStats() { eventStats = new List <eventStats>(), skillStats = new List <skillStats>(), streaksStats = new List <streaksStats>() }; } dynamic obj = JObject.Parse(json); d.Stats.eventStats.Clear(); d.Stats.skillStats.Clear(); d.Stats.streaksStats.Clear(); foreach (var ev in obj.worldStats.eventStats) { d.Stats.eventStats.Add(new eventStats() { averageFinishingPlace = ev.averageFinishingPlace, multiPlayerAverageFinishingPlace = ev.multiPlayerAverageFinishingPlace, multiPlayerDnfCount = ev.multiPlayerDnfCount, multiPlayerRacesLost = ev.multiPlayerRacesLost, multiPlayerRacesWon = ev.multiPlayerRacesWon, multiPlayerTotalPlacing = ev.multiPlayerTotalPlacing, singlePlayerAverageFinishingPlace = ev.singlePlayerAverageFinishingPlace, singlePlayerDnfCount = ev.singlePlayerDnfCount, singlePlayerRacesLost = ev.singlePlayerRacesLost, singlePlayerRacesWon = ev.singlePlayerRacesWon, singlePlayerTotalPlacing = ev.singlePlayerTotalPlacing, totalRacesLost = ev.totalRacesLost, totalRacesWon = ev.totalRacesWon }); } /*foreach (var ev in obj.worldStats.skillStats) * { * * }*/ foreach (var ev in obj.worldStats.streaksStats) { d.Stats.streaksStats.Add(new streaksStats() { bestMultiPlayerWinStreak = ev.bestMultiPlayerWinStreak, bestSinglePlayerWinStreak = ev.bestSinglePlayerWinStreak, currentMultiPlayerWinStreak = ev.currentMultiPlayerWinStreak, currentSinglePlayerWinStreak = ev.currentSinglePlayerWinStreak }); } } catch (Exception ex) { string s = ex.Message; } uri = "/ws/game/nfsw/driver/" + pers + "/lastLogin?shard=" + shard; try { string json = wc.DownloadString(uribase + uri + (uri.IndexOf("?") == -1 ? "?" : "&") + "output=json"); dynamic obj = JObject.Parse(json); d.LastLogin = new worldLastLogin() { date = obj.worldLastLogin.date, day = obj.worldLastLogin.day, hours = obj.worldLastLogin.hours, minutes = obj.worldLastLogin.minutes, month = obj.worldLastLogin.month, seconds = obj.worldLastLogin.seconds, time = obj.worldLastLogin.time, timezoneOffset = obj.worldLastLogin.timezoneOffset, year = obj.worldLastLogin.year }; } catch (Exception ex) { string s = ex.Message; } } } this.Invoke((MethodInvoker) delegate { cntdone++; }); }