public static void Save(FileStore store, PlayerDetails player) { store.Save(player, player.Id); }
public static PlayerDetails Parse(string url) { Dictionary<string, string> tokens = Tokenize(url); if (tokens.Count > 0) { PlayerDetails player = new PlayerDetails(); foreach (string key in tokens.Keys) { string value = tokens[key]; switch (key) { case "Full name:": player.FullName = value; break; case "Known As": player.KnownAs = value; break; case "Born:": player.Born = value; break; case "Died:": player.Died = value; break; case "Batting:": player.Batting = value; break; case "Bowling:": player.Bowling = value; break; case "Occasional wicket-keeper": case "Wicket-keeper": player.WicketKeeper = true; break; case "Somerset cap:": player.SomersetCap = int.Parse(value); break; case "Somerset benefit season:": if (value.EndsWith(" (Testimonial)")) value = value.Substring(0, value.Length - 14).Trim(); player.Benefit = int.Parse(value); break; case "Relations:": case "Teams:": case "Biography:": case "Christened:": case "Buried:": case "Articles:": case "Pictures:": case "Education:": case "Other Sports:": case "External link:": case "Clubs:": case "Disability:": case "Other Relations:": case "Galleries:": case "Audio-Video:": break; default: if (Regex.IsMatch(value, @"^\d{4}(?:/\d{2})?$")) { PlayerAward award = new PlayerAward { Award = key, Season = value }; if (player.Awards == null) player.Awards = new List<PlayerAward>(); player.Awards.Add(award); } else if (value.Contains(',')) { // Could be a multi-year award string[] seasons = Regex.Split(value, @"\s*,\s*"); foreach (string season in seasons) { if (!Regex.IsMatch(value, @"\d{4}(?:/\d{2})?")) { Log.WarnFormat("Player {0} has previously unseen token '{1}'", player.FullName, key); break; } PlayerAward award = new PlayerAward { Award = key, Season = season }; if (player.Awards == null) player.Awards = new List<PlayerAward>(); player.Awards.Add(award); } } else { Log.WarnFormat("Player {0} has previously unseen token '{1}'", player.FullName, key); } break; } } return player; } return null; }