Example #1
0
        public bool SaveChallengeGamesToDataStore(clsChallengeGameList gameList)
        {
            string currentYearGameBackupDirectory = GetCurrentYearGameBackupDirectory();
            string currentYearGameDirectory       = GetCurrentYearGameDirectory();
            string currentYearGameFile            = GetCurrentYearGameFileName();
            string currentYearBackupGameFile      = GetCurrentYearGameBackupFileName();

            try
            {
                if (System.IO.Directory.Exists(currentYearGameBackupDirectory) == true)
                {
                    if (System.IO.File.Exists(currentYearBackupGameFile))
                    {
                        System.IO.File.Delete(currentYearBackupGameFile);
                    }
                }
                else
                {
                    System.IO.Directory.CreateDirectory(currentYearGameBackupDirectory);
                }
                //                if (System.IO.Directory.Exists(GetCurrentYearBackupDirectory()) == false)
                if (System.IO.Directory.Exists(currentYearGameDirectory) == true)
                {
                    if (System.IO.File.Exists(currentYearGameFile) == true)
                    {
                        System.IO.Directory.Move(currentYearGameFile, currentYearBackupGameFile);
                    }
                }
                else
                {
                    System.IO.Directory.CreateDirectory(currentYearGameDirectory);
                }
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error creating challenge game directory: " + ex.Message);
                messageForm.ShowDialog();
                return(false);
            }

            try
            {
                using (System.IO.FileStream fs = new System.IO.FileStream(currentYearGameFile, System.IO.FileMode.Create))
                {
                    XmlSerializer s = new XmlSerializer(gameList.GetType());
                    s.Serialize(fs, gameList);
                    fs.Close();
                }
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error saving challenge games: " + ex.Message);
                messageForm.ShowDialog();
                return(false);
            }

            return(true);
        }
Example #2
0
        public clsChallengeGameList LoadOutsideGamesFromDataStore()
        {
            try
            {
                string currentYearGameFile = GetCurrentYearGameFileName();

                if (System.IO.File.Exists(currentYearGameFile) == false)
                {
                    return(new clsChallengeGameList());
                }

                System.IO.FileStream fs         = new System.IO.FileStream(currentYearGameFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                XmlSerializer        serializer = new XmlSerializer(typeof(clsChallengeGameList));
                clsChallengeGameList gameList   = (clsChallengeGameList)serializer.Deserialize(fs);
                fs.Close();
                if (gameList == null)
                {
                    return(new clsChallengeGameList());
                }
                else
                {
                    return(gameList);
                }
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error loading challenge games: " + ex.Message);
                messageForm.ShowDialog();
                return(new clsChallengeGameList());
            }
        }
Example #3
0
        public clsChallengeGameList LoadAllGamesFromDataStore()
        {
            clsChallengeGameList allGames = new clsChallengeGameList();

            try
            {
                allGames.AddRange(LoadOutsideGamesFromDataStore());

                if (System.IO.Directory.Exists(GetCurrentYearMeetingDirectory()) == true)
                {
                    string[] fileList = System.IO.Directory.GetFiles(GetCurrentYearMeetingDirectory());
                    foreach (string filePath in fileList)
                    {
                        string fileName = System.IO.Path.GetFileNameWithoutExtension(filePath);
                        if (fileName.Contains(GamesFile))
                        {
                            clsChessClubMeeting retrievedMeeting = LoadMeeting_XML(filePath);
                            allGames.AddRange(retrievedMeeting.listChallengeGames);
                        }
                    }
                }
                return(allGames);
            }
            catch (Exception ex)
            {
                frmMessage messageForm = new frmMessage();
                messageForm.SetMessageText("Error loading all challenge games: " + ex.Message);
                messageForm.ShowDialog();
                return(new clsChallengeGameList());
            }
        }
Example #4
0
        public void PairAttendees()
        {
            allGames = dataStore.LoadAllGamesFromDataStore();
            allGames.Sort(gameComparer);
            List <clsMeetingAttendee> listRemainingAttendees = new List <clsMeetingAttendee>();

            foreach (clsMeetingAttendee attendee in listChallengeGameAttendees)
            {
                if (attendee.ChallengeGameAssigned == false)
                {
                    attendee.LastGame = allGames.GetPreviousGameForPlayer(attendee.Player);
                    listRemainingAttendees.Add(attendee);
                }
            }
            clsCompareAttendeesByRank rankComparer = new clsCompareAttendeesByRank();

            listRemainingAttendees.Sort(rankComparer);
            gameBoard = listRemainingAttendees.Count / 2;

            while (listRemainingAttendees.Count > 1)
            {
                clsChallengeGame nextGame = GetNextMatch(listRemainingAttendees);
                listChallengeGames.Add(nextGame);
                gameBoard--;
            }
        }