Exemplo n.º 1
0
 public static Task Stop()
 {
     return(Task.Run(() =>
     {
         updateCheckerTimer.Stop();
         Saliens.Stop();
         Presence.Stop();
         Shell.StopRead();
     }));
 }
Exemplo n.º 2
0
        public static async Task Start()
        {
            if (File.Exists("settings.json"))
            {
                var settingsJson = File.ReadAllText("settings.json");
                Settings = JsonConvert.DeserializeObject <Settings>(settingsJson);

#if DEBUG
                Settings.EnableBot             = false;
                Settings.EnableDiscordPresence = false;
#endif

                if (Settings.GameTime < 1)
                {
                    Settings.GameTime = 110;
                }
                if (Settings.Strategy == 0)
                {
                    Settings.Strategy =
                        AutomationStrategy.MostDifficultPlanetsFirst |
                        AutomationStrategy.MostCompletedPlanetsFirst |
                        AutomationStrategy.MostDifficultZonesFirst |
                        AutomationStrategy.LeastCompletedZonesFirst |
                        AutomationStrategy.TopDown;
                }
                if (Settings.DiscordPresenceTimeType == 0)
                {
                    Settings.DiscordPresenceTimeType = PresenceTimeType.TimeZoneElapsed;
                }
                Shell.WriteLine("", false);
                Shell.WriteLine("{verb}Read settings from settings.json");

                updateCheckerTimer.Start();
                var tasks = new List <Task>()
                {
                    CheckForUpdates()
                };

                if (Settings.EnableDiscordPresence)
                {
                    Shell.WriteLine("{verb}Initializing Discord presence...");
                    tasks.Add(Presence.Start());
                    if (!Settings.EnableBot)
                    {
                        Presence.CheckPeriodically = true;
                    }
                }
                if (Settings.EnableBot)
                {
                    Shell.WriteLine("{verb}Initializing bot...");
                    tasks.Add(Saliens.Start());
                }
                tasks.Add(Shell.StartRead());

#if DEBUG
                Shell.WriteLine("{inf}Debug build: type {command}resume{inf} to start automation or {command}presence {param}enable{inf} to start Discord presence");
#endif

                await Task.WhenAll(tasks);
            }
            else
            {
                Shell.WriteLine("{inf}It seems like that this is your first time running this application! Type {command}getstarted{inf} to get started.", false);
                Shell.WriteLine("", false);

                await Shell.StartRead();
            }
        }