Beispiel #1
0
        static void ArchiveGameData()
        {
            string archiveFileName = "stats_" + DateTime.Now.ToString("ddMMyy") + ".csv";
            var    backup          = new FileDataSource(DirectoryPath + archiveFileName);

            backup.SaveGamesToDataSource(games);
            Console.Clear();
            Console.WriteLine("Backup saved to: " + DirectoryPath + archiveFileName);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            if (args.Contains("-help"))
            {
                ApplicationHelp();
            }

            //Setup the file to read in
            IDataSource DataSource = null;
            string      FileName   = DirectoryPath;

            try
            {
                if (args.Length == 0)
                {
                    FileName  += "SeasonData.csv"; //Default Filename
                    DataSource = new FileDataSource(FileName);
                }
                else
                {
                    if (args.Contains("-db"))
                    {
                        DataSource = new MySQLDataSource();
                    }
                    else
                    {
                        FileName  += args[0];
                        DataSource = new FileDataSource(FileName);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message + " Unable To continue");
                Console.WriteLine("\nPress any key to close");
                Console.ReadKey();
                Environment.Exit(-1);
            }

            // Removed due to the map rotation changing mid season 21
            //Maps.LoadMaps((string)ConfigurationManager.AppSettings["Map"]);
            Maps.ExcludedMaps((string)ConfigurationManager.AppSettings["ExcludedMaps"]);
            games = new List <Game>();

            //Check that the data source is readable, and that it has some data in it
            if (DataSource.VerifySourceExists())
            {
                games = DataSource.ReadExistingGamesSource();
            }
            else
            {
                PopulateGameData();
            }

            ConsoleKey keyPressed;

            do
            {
                Console.WriteLine("Please choose from the following options:\n");
                Console.WriteLine("(A) to Add a new game\n(B) to Backup the game data\n(C) to Compress all backups\n(D) to Display the current stats\n" +
                                  "(O) to display an Overview\n(S) to Save the games details\n(X) to Exit without saving");
                keyPressed = Console.ReadKey().Key;

                if (keyPressed == ConsoleKey.X)
                {
                    Environment.Exit(0);
                }
                if (keyPressed == ConsoleKey.D)
                {
                    DisplayGameData();
                }
                if (keyPressed == ConsoleKey.O)
                {
                    GamesOverview();
                }
                if (keyPressed == ConsoleKey.A)
                {
                    AddNewGame();
                }
                if (keyPressed == ConsoleKey.B)
                {
                    ArchiveGameData();
                }
                if (keyPressed == ConsoleKey.C)
                {
                    ArchiveToZipFile();
                }
            } while (keyPressed != ConsoleKey.S);

            DataSource.SaveGamesToDataSource(games);

            Console.WriteLine("File Saved.\nPress Any key to exit");
            Console.ReadKey();
        }