コード例 #1
0
        public static void SaveEntryToFile(this MatchEntryModel entry, string matchupEntryFile)
        {
            List <MatchEntryModel> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().ConvertToMatchupEntryModels();

            int currentId = 1;

            if (entries.Count > 0)
            {
                currentId = entries.OrderByDescending(x => x.Id).First().Id + 1;
            }
            entry.Id = currentId;
            entries.Add(entry);

            List <string> lines = new List <string>();

            foreach (MatchEntryModel e in entries)
            {
                // id = 0, TeamCompeting =1, Score =2, ParentMatchup = 3
                string parent = "";
                if (e.ParentMatchup != null)
                {
                    parent = e.ParentMatchup.Id.ToString();
                }
                string teamCompeting = "";
                if (e.TeamCompeting != null)
                {
                    teamCompeting = e.TeamCompeting.Id.ToString();
                }
                lines.Add($"{ e.Id },{ teamCompeting },{ e.Score },{ parent }");
            }
            File.WriteAllLines(GlobalConfig.MatchupEntryFile.FullFilePath(), lines);
        }
コード例 #2
0
        public static List <MatchEntryModel> ConvertToMatchupEntryModels(this List <string> lines)
        {
            // id = 0, TeamCompeting =1, Score =2, ParentMatchup = 3
            List <MatchEntryModel> output = new List <MatchEntryModel>();

            foreach (string line in lines)
            {
                string[] cols = line.Split(',');

                MatchEntryModel me = new MatchEntryModel();
                me.Id = int.Parse(cols[0]);
                if (cols[1].Length == 0)
                {
                    me.TeamCompeting = null;
                }
                else
                {
                    me.TeamCompeting = LookUpTeamById(int.Parse(cols[1]));
                }

                me.Score = double.Parse(cols[2]);

                int parentId = 0;
                if (int.TryParse(cols[3], out parentId))
                {
                    me.ParentMatchup = LookUpTeamMatchById(parentId);
                }
                else
                {
                    me.ParentMatchup = null;
                }

                output.Add(me);
            }

            return(output);
        }