internal bool AddMatch(Match match) { if (Matches.Any(m => m.ID == match.ID)) { return false; } Matches.Add(match); using (StreamWriter matchFile = new StreamWriter(_matchPath, false)) { string matchFormat = "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}\t{16}"; StringBuilder thisString = new StringBuilder(); thisString.AppendFormat(matchFormat, "#ID", "PlayerID", "HeroClassID", "DeckID", "MatchTypeID", "OpponentClassID", "OpponentName", "OpponentRankID", "StartingRankID", "StartingRankStars", "EndingRankID", "EndingRankStars", "HaveCoin", "HaveWon", "Rounds", "DidConcede", "Notes"); matchFile.WriteLine(thisString.ToString()); foreach (Match thisMatch in Matches.OrderBy(m => m.ID)) { matchFile.WriteLine(thisMatch.ToString()); } matchFile.Flush(); } return true; }
private void LoadMatches() { if (!File.Exists(_matchPath)) { throw new ArgumentException("Cannot load Match File."); } using (StreamReader matchFile = new StreamReader(_matchPath)) { string matchLine; while ((matchLine = matchFile.ReadLine()) != null) { if (matchLine.StartsWith("#")) { continue; } string[] matchData = matchLine.Split('\t'); if (matchData.Length >= 16) { Match thisMatch = new Match(); thisMatch.ID = int.Parse(matchData[0]); thisMatch.Player = Players.First(p => p.ID == int.Parse(matchData[1])); thisMatch.HeroClass = HeroClasses.First(c => c.ID == int.Parse(matchData[2])); thisMatch.Deck = Decks.First(d => d.ID == int.Parse(matchData[3])); thisMatch.Type = (MatchType)int.Parse(matchData[4]); thisMatch.OpponentClass = HeroClasses.First(c => c.ID == int.Parse(matchData[5])); thisMatch.OpponentName = matchData[6]; thisMatch.OpponentRank = AllRanks.First(r => r.ID == int.Parse(matchData[7])); thisMatch.StartingRank = AllRanks.First(r => r.ID == int.Parse(matchData[8])); thisMatch.StartingRank.Stars = int.Parse(matchData[9]); thisMatch.EndingRank = AllRanks.First(r => r.ID == int.Parse(matchData[10])); thisMatch.EndingRank.Stars = int.Parse(matchData[11]); thisMatch.HaveCoin = ParseBool(matchData[12]); thisMatch.HaveWon = ParseBool(matchData[13]); thisMatch.Rounds = int.Parse(matchData[14]); thisMatch.DidConcede = ParseBool(matchData[15]); if (matchData.Length == 17 && !String.IsNullOrWhiteSpace(matchData[16])) { thisMatch.Notes = matchData[16]; } else { thisMatch.Notes = ""; } if (!Matches.Any(m => m.ID == thisMatch.ID)) { Matches.Add(thisMatch); } } } } }
internal bool UpdateMatch(Match match) { if (!RemoveMatch(match)) { return false; } return AddMatch(match); }
internal bool RemoveMatch(Match match) { if (Matches.Any(m => m.ID == match.ID)) { Matches.Remove(Matches.First(m => m.ID == match.ID)); return RemoveMatch(match); } return true; }
public bool UpdateMatch(Match match) { return _fileData.UpdateMatch(match); }
public bool DeleteMatch(Match match) { return _fileData.RemoveMatch(match); }
public bool AddMatch(Match match) { return _fileData.AddMatch(match); }