Esempio n. 1
0
        /// <summary>
        /// Main program initialization
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            //Setup console
            Setup();

            //Display logo
            Core.GetLogoType();

            Core.WriteLine("Checking Internet Connection...");

            //Check if Internet connection is available
            if (!Core.InternetAvailable())
            {
                Core.WriteLine(Core.softwareName + " " + Core.GetVersion() + " requires an active internet connection. Detection failed. Exiting...");
                Thread.Sleep(15000);
                Environment.Exit(0);
            }
            else
            {
                //Load local and remote bots and save the most recent one.
                Core.WriteLine("Loading session. Please wait...");
                bots = Core.LoadPreviousSession();

                //Clear Console.
                Console.Clear();

                //Display logo
                Core.GetLogoType();

                //Set thread information and start it.
                botScraperThread = new Thread(() => Do_Work());
                botScraperThread.Start();

                //Loop main menu.
                MainMenu();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loop and show the main menu
        /// </summary>
        private static void MainMenu()
        {
            Thread.Sleep(100);
            Console.WriteLine("? or help will show commands");
            Console.WriteLine("Enter a command:");
            while (runMainMenu)                       // Lock the user in the menu loop
            {
                switch (Console.ReadLine().ToLower()) // Get user input as lower case
                {
                    //Nice case devided switch case

                    #region Case help

                case "?":
                case "help":
                    Core.WriteLine("Commands:" +
                                   "\n\rclear, cls   -- This will clear the console." +
                                   "\n\rdebug, dev   -- This will activate debug console output." +
                                   "\n\rstart        -- This will start the worker." +
                                   "\n\rstop         -- This will stop the worker after work has finished." +
                                   "\n\rupload       -- This will upload current bot data to the remote server." +
                                   "\n\rdownload     -- This will download new data to the software." +
                                   "\n\rreset, r     -- WARNING! Instantly resets bots data and overwrite data on next pass." +
                                   "\n\rstatus, info -- Shows software information and session data." +
                                   "\n\rlist, bots   -- Lists all bots and their data in the console." +
                                   "\n\rexit, quit   -- Instantly closes the software.", Core.LogType.Requested);
                    break;

                    #endregion Case help

                    #region Case clear

                case "clear":
                case "cls":
                    Console.Clear();
                    break;

                    #endregion Case clear

                    #region Case debug

                case "dev":
                case "debug":
                    debug      = !debug;
                    Core.debug = !Core.debug;
                    Core.WriteLine("Debug mode is now set " + debug.ToString(), Core.LogType.Requested);
                    break;

                    #endregion Case debug

                    #region Worker Controller

                    #region Case start

                case "start":
                    if (botScraperThread.IsAlive)
                    {
                        Core.WriteLine("Worker is already ONLINE.", Core.LogType.Requested);
                        break;
                    }
                    runWorker = true;
                    try
                    {
                        botScraperThread = new Thread(() => Do_Work());
                        botScraperThread.Start();
                        Core.WriteLine("Worker is starting...", Core.LogType.Requested);
                    }
                    catch (ThreadStateException x) { Core.WriteLine(x.Message, Core.LogType.Console); }
                    catch (OutOfMemoryException x) { Core.WriteLine(x.Message, Core.LogType.Console); }

                    break;

                    #endregion Case start

                    #region Case stop

                case "stop":
                    if (!botScraperThread.IsAlive)
                    {
                        Core.WriteLine("Worker is already OFFLINE...", Core.LogType.Requested);
                        break;
                    }
                    runWorker = false;
                    Core.WriteLine("Worker is scheduled to stop. Please allow up to " + Core.updateTimerSeconds.ToString() + " second(s) to finish current work.", Core.LogType.Requested);
                    break;

                    #endregion Case stop

                    #region Case upload

                case "upload":
                    string json = SaveDataToLocalJsonFile(); // Save file (to get string)
                    UploadJsonToDatabase(json);              // Upload file
                    Core.WriteLine("Upload complete.", Core.LogType.Requested);
                    break;

                    #endregion Case upload

                    #region Case download

                case "download":
                    //Download new bot-data
                    downloadedData = Core.Download <DownloadedData>(Core.scrapeURL);    // Download new data

                    //Create update bots data
                    UpdateBotsData(downloadedData);     // Perform work on the new data
                    Core.WriteLine("Download Complete.", Core.LogType.Requested);
                    break;

                    #endregion Case download

                    #endregion Worker Controller

                    #region Bot Controller

                    #region Case Reset

                case "r":
                case "reset":
                    bots = new BotsData();
                    Core.WriteLine("Bots have been reset. Save and upload will begin in next cycle.", Core.LogType.Requested);
                    break;

                    #endregion Case Reset

                    #region Case status/info

                case "status":
                case "info":
                    SendStatusInformation();
                    Core.WriteLine("This software was created by " + Core.authorName + "/" + Core.authorRealName + " @ 2020", Core.LogType.Requested);
                    break;

                    #endregion Case status/info

                    #region Case list bots

                case "list":
                case "bots":
                    try
                    {
                        if (bots.bot.Count > 0)
                        {
                            // List bots if there are any in the list
                            foreach (Bot bot in bots.bot)
                            {
                                Core.WriteLine(bot.name + " has been sighted " + bot.timesSeen.ToString() + " times and was last seen: " + Core.TranslateLongToDateTime(bot.lastSeen).ToString(), Core.LogType.Requested);
                            }
                        }
                        else
                        {
                            Core.WriteLine("There are no bots in the list.", Core.LogType.Requested);
                        }
                    }
                    catch (InvalidOperationException x) { Core.WriteLine(x.Message); }
                    break;

                    #endregion Case list bots

                    #endregion Bot Controller

                    #region Case exit

                case "exit":
                case "quit":
                    Environment.Exit(0);
                    break;

                    #endregion Case exit

                default:
                    Core.WriteLine("That is not an accepted command. Please try again.\n\rFor help & commands, write \"help\" or \"?\".\n\r");
                    break;
                }
            }
        }