public static void Write(MatchScheduleInfo[] items, string targetFileName)
        {
            var lines = new List<string>();
            foreach (var matchScheduleInfo in items)
            {
                var winner = matchScheduleInfo.Winner.HasValue
                                 ? (matchScheduleInfo.Winner == (int)MatchWinner.Player1
                                        ? matchScheduleInfo.Player1
                                        : matchScheduleInfo.Player2).ToString()
                                 : string.Empty;
                
                var detailedResult = matchScheduleInfo.SetScores == null ? string.Empty: string.Join(" ", matchScheduleInfo.SetScores.Select(s=> s.Player1Points + ":" + s.Player2Points));
                var data = new[]
                               {
                                   matchScheduleInfo.Id.ToString(), 
                                   matchScheduleInfo.Player1.ToString(),
                                   matchScheduleInfo.Player2.ToString(), 
                                   winner,
                                   matchScheduleInfo.Player1Points + ":" + matchScheduleInfo.Player2Points, detailedResult,
                                   string.Empty, string.Empty
                               };
                var line = string.Join(";", data);
                
                lines.Add(line);

            }
            File.WriteAllLines(targetFileName, lines);
        }
        private void SaveSchedule(MatchHeaderInfo[] matches, CompetitionPlayer[] players, string schedulePath)
        {
            var playersMap = new Dictionary<int, int>();
            var index = 1;
            foreach (var player in players)
            {
                playersMap[player.Id] = index++;
            }

            var items = new List<MatchScheduleInfo>();
            index = 1;
            foreach (var match in matches)
            {
                var matchSchedule = new MatchScheduleInfo();
                matchSchedule.Id = "M" + index++;
                if (match.Player1 != null)
                {
                    matchSchedule.Player1 = playersMap[match.Player1.Id];
                }
                else if (match.Player1 == null || match.Player1Code == "BYE")
                {
                    matchSchedule.Player1 = players.Length+1;
                }
                if (match.Player2 != null)
                {
                    matchSchedule.Player2 = playersMap[match.Player2.Id];
                }
                else if (match.Player2 == null || match.Player2Code == "BYE")
                {
                    matchSchedule.Player2 = players.Length+1;
                }

                if (match.Winner != MatchWinner.None)
                {
                    matchSchedule.Winner = (int) match.Winner;
                }

                matchSchedule.Player1Points = 0;
                matchSchedule.Player2Points = 0;
                matchSchedule.SetScores = match.SetScores;
                //matchSchedule.SetScores = new[]
                //                              {
                //                                  new SetScore()
                //                                      {
                //                                          Player1Points = 7,
                //                                          Player2Points = 5,
                //                                      }, 
                //                                  new SetScore()
                //                                      {
                //                                          Player1Points = 2,
                //                                          Player2Points = 6,
                //                                      }, 
                //                                  new SetScore()
                //                                      {
                //                                          Player1Points = 0,
                //                                          Player2Points = 6,
                //                                      }, 
                //                              };
                items.Add(matchSchedule);
            }

            MatchScheduleInfo.Write(items.ToArray(), schedulePath);
        }
        private void SaveSchedule(MatchHeaderInfo[] matches, CompetitionPlayer[] players, string schedulePath)
        {
            var playersMap = new Dictionary <int, int>();
            var index      = 1;

            foreach (var player in players)
            {
                playersMap[player.Id] = index++;
            }

            var items = new List <MatchScheduleInfo>();

            index = 1;
            foreach (var match in matches)
            {
                var matchSchedule = new MatchScheduleInfo();
                matchSchedule.Id = "M" + index++;
                if (match.Player1 != null)
                {
                    matchSchedule.Player1 = playersMap[match.Player1.Id];
                }
                else if (match.Player1 == null || match.Player1Code == "BYE")
                {
                    matchSchedule.Player1 = players.Length + 1;
                }
                if (match.Player2 != null)
                {
                    matchSchedule.Player2 = playersMap[match.Player2.Id];
                }
                else if (match.Player2 == null || match.Player2Code == "BYE")
                {
                    matchSchedule.Player2 = players.Length + 1;
                }

                if (match.Winner != MatchWinner.None)
                {
                    matchSchedule.Winner = (int)match.Winner;
                }

                matchSchedule.Player1Points = 0;
                matchSchedule.Player2Points = 0;
                matchSchedule.SetScores     = match.SetScores;
                //matchSchedule.SetScores = new[]
                //                              {
                //                                  new SetScore()
                //                                      {
                //                                          Player1Points = 7,
                //                                          Player2Points = 5,
                //                                      },
                //                                  new SetScore()
                //                                      {
                //                                          Player1Points = 2,
                //                                          Player2Points = 6,
                //                                      },
                //                                  new SetScore()
                //                                      {
                //                                          Player1Points = 0,
                //                                          Player2Points = 6,
                //                                      },
                //                              };
                items.Add(matchSchedule);
            }

            MatchScheduleInfo.Write(items.ToArray(), schedulePath);
        }