public static async Task SaveCompetition(Competition competition) { var filename = string.Format("{0}2014.json", competition.Name.Replace(" ", string.Empty)); var data = JsonConvert.SerializeObject(competition, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects }); var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, data); }
public static async Task<Competition> LoadCompetition(Competition competition) { var filename = string.Format("{0}2014.json", competition.Name.Replace(" ", string.Empty)); try { var file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename); var data = await FileIO.ReadTextAsync(file); return JsonConvert.DeserializeObject<Competition>(data, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects }); } catch (Exception) { return competition; } }
public static void ImportSchedule(Competition competition, ImportModel matchData) { foreach (var matchSchedule in matchData.Matches) { if (competition.Matches.Any(m => m.MatchNumber == matchSchedule.Key)) { continue; } var match = new Match(); match.MatchNumber = matchSchedule.Key; match.Blue1 = GetTeam(competition, matchSchedule.Value.Blue1); match.Blue2 = GetTeam(competition, matchSchedule.Value.Blue2); match.Blue3 = GetTeam(competition, matchSchedule.Value.Blue3); match.Red1 = GetTeam(competition, matchSchedule.Value.Red1); match.Red2 = GetTeam(competition, matchSchedule.Value.Red2); match.Red3 = GetTeam(competition, matchSchedule.Value.Red3); competition.Matches.Add(match); } }
public static async Task<ImportModel> ImportRemoteData(Competition competition, string serverAddress) { var importModel = new ImportModel(); //var folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets"); //var file = await folder.GetFileAsync("matches.json"); var client = new HttpClient(); var uri = new Uri(serverAddress, UriKind.Absolute); using (var downloadStream = await client.GetStreamAsync(uri)) //using (var fileData = await file.OpenReadAsync()) { using (var stringreader = new StreamReader(downloadStream)) { using (var jsonReader = new JsonTextReader(stringreader)) { var jsonSerializer = new JsonSerializer(); importModel = jsonSerializer.Deserialize<ImportModel>(jsonReader); } } } return importModel; }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { competition = e.NavigationParameter as Competition; }
/// <summary> /// Populates the page with content passed during navigation. Any saved state is also /// provided when recreating a page from a prior session. /// </summary> /// <param name="sender"> /// The source of the event; typically <see cref="NavigationHelper"/> /// </param> /// <param name="e">Event data that provides both the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and /// a dictionary of state preserved by this page during an earlier /// session. The state will be null the first time a page is visited.</param> private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { var crossroads = new Competition { Name = "Crossroads Regional", Location = "Terre Haute, IN", ImagePath = "Assets/Competitions/crossroads.jpg" }; var wisconsin = new Competition { Name = "Wisconsin Regional", Location = "Milwaukee, WI", ImagePath = "Assets/Competitions/wisconsin.jpg" }; //competition.Matches.Add(new Match { MatchNumber = 1, MatchType = MatchType.Practive }); //competition.Teams.Add(new Team { Number = 48, Name = "Delphi Corporation/Nordson XALOY & Warren G. Harding High School", ImagePath = null }); //competition.Teams.Add(new Team { Number = 71, Name = "School City of Hammond/Caterpillar/City of Hammond & School City of Hammond", ImagePath = null }); //competition.Teams.Add(new Team { Number = 128, Name = "American Electric Power/Grandview Heights Marble Cliff Education Foundation & Grandview Heights High School", ImagePath = null }); //competition.Teams.Add(new Team { Number = 537, Name = "Charger Robotics", ImagePath = null }); this.defaultViewModel.Competitions.Add(wisconsin); this.defaultViewModel.Competitions.Add(crossroads); }
public static void ImportMatchData(Competition competition, ImportModel matchData) { foreach (var rawTeam in matchData.Teams) { var team = GetTeam(competition, rawTeam.Key); if (rawTeam.Value.Matches == null) { continue; } foreach (var rawMatch in rawTeam.Value.Matches) { var match = team.MatchData2014.FirstOrDefault(m => m.MatchNumber == rawMatch.Key); if (match == null) { match = new MatchScoutingData2014(); match.MatchNumber = rawMatch.Key; team.MatchData2014.Add(match); } // autonomous match.AutonomousHigh = rawMatch.Value.AutonomousHigh; match.AutonomousHighHot = rawMatch.Value.AutonomousHighHot; match.AutonomousLow = rawMatch.Value.AutonomousLow; match.AutonomousLowHot = rawMatch.Value.AutonomousLowHot; match.Mobility = rawMatch.Value.Mobility == "yes"; // overall switch (rawMatch.Value.StartingPosition) { case "side": match.StartingPosition = StartingPosition.Side; break; case "middle": match.StartingPosition = StartingPosition.Middle; break; case "goalie": match.StartingPosition = StartingPosition.Goalie; break; } match.Fouls = rawMatch.Value.Fouls.GetValueOrDefault() + rawMatch.Value.Technicals.GetValueOrDefault(); // possession match.TeleOperatedPossessionFront = rawMatch.Value.TeleOperatedPossessionFront; match.TeleOperatedPossessionMiddle = rawMatch.Value.TeleOperatedPossessionMiddle; match.TeleOperatedPossessionBack = rawMatch.Value.TeleOperatedPossessionBack; // offense match.TeleOperatedTruss = rawMatch.Value.TeleOperatedTruss; match.TeleOperatedCatch = rawMatch.Value.TeleOperatedCatch; match.TeleOperatedCatchFail = rawMatch.Value.TeleOperatedCatchFail; match.TeleOperatedHighGoal = rawMatch.Value.TeleOperatedHighGoal; match.TeleOperatedHighGoalMiss = rawMatch.Value.TeleOperatedHighGoalMiss; match.TeleOperatedLowGoal = rawMatch.Value.TeleOperatedLowGoal; // ball control match.TeleOperatedBallsLost = rawMatch.Value.TeleOperatedBallsLost; // defense match.ShotsDefended = rawMatch.Value.ShotsDefended; match.DefensiveContacts = rawMatch.Value.DefensiveContacts; match.PinnedOpponents = rawMatch.Value.PinnedOpponents; // comments match.ManuverabilityComments = rawMatch.Value.ManuverabilityComments; match.CollectorComments = rawMatch.Value.CollectorComments; match.ShooterComments = rawMatch.Value.ShooterComments; match.OverallComments = rawMatch.Value.OverallComments; } } }
private static Team GetTeam(Competition competition, int number) { var team = competition.Teams.SingleOrDefault(t => t.Number == number); if (team == null) { team = new Team { Number = number }; competition.Teams.Add(team); } return team; }