Ejemplo n.º 1
0
        public static MigrationMySql2MongoDb getInstance()
        {
            if (MigrationObj == null)
            {
                MigrationObj = new MigrationMySql2MongoDb();
            }

            return(MigrationObj);
        }
Ejemplo n.º 2
0
        // ==============================================================
        public void Parse(string[] args)
        // ==============================================================
        {
            bool cmdLineHalt = false;

            if (args.Length == 0)
            {
                // Just run the program
                HammerMain.ReadSurveyResults = true;   // Default
            }
            else if (args.Length > 2)
            {
                throw (new CmdLineProcessorException(CmdLineProcessorException.ExceptionID.TooManyArgs, "Error: Only one command line argument allowed."));
            }
            else
            {
                foreach (string arg in args)
                {
                    if (arg == "--Help" || arg == "--help")
                    {
                        Console.WriteLine();
                        Help();
                        cmdLineHalt = true;
                    }
                    else if (arg == "--MongoDb")
                    {
                        HammerMainDb.Server = DbConnection.Server.MongoDb;
                    }
                    else if (arg == "--MySql")
                    {
                        // Already initialized as default
                        HammerMainDb.Server = DbConnection.Server.MySql;
                    }
                    else if (arg == "--AddNewPlayer")
                    {
                        Console.WriteLine();
                        if (AddNewPlayer() == false)
                        {
                            throw (new CmdLineProcessorException(CmdLineProcessorException.ExceptionID.AddNewPlayer, "Error: Couldn't add the new player."));
                        }
                        cmdLineHalt = true;
                    }
                    else if (arg == "--UpdatePlayer")
                    {
                        Console.WriteLine();
                        if (UpdatePlayer() == false)
                        {
                            throw (new CmdLineProcessorException(CmdLineProcessorException.ExceptionID.UpdatePlayer, "Error: Couldn't find the new player nor update the attributes."));
                        }
                        cmdLineHalt = true;
                    }
                    else if (arg == "--DeletePlayer")
                    {
                        Console.WriteLine();
                        if (DeletePlayer() == false)
                        {
                            throw (new CmdLineProcessorException(CmdLineProcessorException.ExceptionID.DeletePlayer, "Error: Couldn't delete the player."));
                        }
                        cmdLineHalt = true;
                    }
                    else if (arg == "--PlayerAttrs")
                    {
                        Console.WriteLine();
                        if (PlayerAttrs() == false)
                        {
                            throw (new CmdLineProcessorException(CmdLineProcessorException.ExceptionID.PlayerAttrs, "Error: Couldn't retrieve the player's attributes."));
                        }
                        cmdLineHalt = true;
                    }
                    else if (arg == "--SaveTeams")
                    {
                        Console.WriteLine();
                        HammerMain.ReadSurveyResults = false;
                        HammerMain.SaveTeams         = true;
                    }
                    else if (arg == "--Backup")
                    {
                        Console.WriteLine();
                        if (BackupDb() == false)
                        {
                            throw (new CmdLineProcessorException(CmdLineProcessorException.ExceptionID.BackupDb, "Error: Couldn't backup the database."));
                        }
                        cmdLineHalt = true;
                    }
                    else if (arg == "--Restore")
                    {
                        Console.WriteLine();
                        if (RestoreDb() == false)
                        {
                            throw (new CmdLineProcessorException(CmdLineProcessorException.ExceptionID.RestoreDb, "Error: Couldn't restore the database."));
                        }
                        cmdLineHalt = true;
                    }
                    else if (arg == "--Count")
                    {
                        int count = Count();

                        Console.WriteLine();
                        if (count == 0)
                        {
                            Console.WriteLine("There aren't any player records in the database.");
                        }
                        else if (count == 1)
                        {
                            Console.WriteLine("There is one player record in the database.");
                        }
                        else
                        {
                            Console.WriteLine($"There are {count} player records in the database.");
                        }

                        cmdLineHalt = true;
                    }
                    else if (arg == "--MigrateMySql2Mongo")
                    {
                        Console.WriteLine();
                        MigrationMySql2MongoDb migrationObj = MigrationMySql2MongoDb.getInstance();
                        try
                        {
                            migrationObj.PerformMigration();
                        }
                        catch (MigrationMySql2MongoDbException ex)
                        {
                            Console.WriteLine();
                            Console.WriteLine($"Error: {ex.Message}");
                        }
                        cmdLineHalt = true;
                    }
                    else
                    {
                        string   pattern    = "=";
                        string[] substrings = Regex.Split(arg, pattern);

                        if (substrings[0] == "--ReadSurveyResults" && (substrings[1] == "true" || substrings[1] == "false"))
                        {
                            if (substrings[1] == "true")
                            {
                                HammerMain.ReadSurveyResults = true;
                            }
                            else
                            {
                                HammerMain.ReadSurveyResults = false;
                            }
                        }
                        else
                        {
                            throw (new CmdLineProcessorException(CmdLineProcessorException.ExceptionID.UnrecognizedArgs, "Error: Unsupported command line argument."));
                        }
                    }
                }
            }

            if (cmdLineHalt == true)
            {
                throw (new CmdLineProcessorException(CmdLineProcessorException.ExceptionID.Benign, ""));
            }
        }