/// <summary> /// Gets a folder containing all data of a Coach, and returns a corresponding Coach instance /// </summary> /// <param name="directory">Directory where all the Coach's data is stored</param> /// <returns>Whether the method worked or not</returns> private static bool Read(DirectoryInfo directory) { // Creating a new default Coach (for security purposes) Coach newCoach = new Coach(); Credentials newCredentials = new Credentials(); try { // We get the COACH file string coachPath = String.Format("{0}\\coach_{1}.json", directory.FullName, directory.Name); // We read the json string json = System.IO.File.ReadAllText(coachPath); // We fill our instances according to the JSON file newCoach = Coach.Deserialize(json); newCredentials = Credentials.Deserialize(json); // For all the Team files in the Directory foreach (FileInfo file in directory.GetFiles("team_*.json")) { // We read the Team Team newTeam = TEAM.Read(file); // We add it if correct if (newTeam.IsComplete) { // We set the Coach and Team values respectively in both instances newCoach.teams.Add(newTeam); newTeam.coach = newCoach; // We add the team to the List teams.Add(newTeam); } } // If the instances are complete (all fields are OK) if (newCoach.IsComplete && newCredentials.IsComplete) { // We sort the teams in chronological order (older first, then younger) teams.Sort((x, y) => x.dateCreation.CompareTo(y.dateCreation)); // We add them to their respective lists coaches.Add(newCoach); credentials.Add(newCredentials); // It worked ! return(true); } } catch (Exception) { } // It didn't work. return(false); }