private static void handleRunning(TimeHandler timeHandler = null, ExeHandler exeHandler = null)
        {
            if (timeHandler == null)
            {
                timeHandler = new TimeHandler();
            }
            if (exeHandler == null)
            {
                exeHandler = new ExeHandler();
            }

            if (exeHandler.ExesRunning().Length > 0)
            {
                if (!timeHandler.CheckTime())
                {
                    NotificationHandler.NotifyWindows("You've played enough for today. Shutting down.", () => {
                        Thread.Sleep(5000);
                        exeHandler.CloseExes();
                        exeHandler.DisableAll();
                        timeHandler.StopTimer();
                        Environment.Exit(0);
                    });
                }
            }
            else
            {
                NotificationHandler.NotifyWindows("Stopping timer.", () => {
                    exeHandler.DisableAll();
                    timeHandler.StopTimer();
                    Environment.Exit(0);
                });
            }
        }
        private static void handleCheck()
        {
            ExeHandler exeHandler = new ExeHandler();

            if(exeHandler.IsThisAppRunning())
                return;

            exeHandler.AddExecutables();
            exeHandler.DisableAll();
            if(exeHandler.ExesRunning().Length > 0) {
                handleRunning(exeHandler:exeHandler);
            }
        }
        public TimeHandler()
        {
            exeHandler = new ExeHandler();
            DateTime now = DateTime.Now;
            DateTime tomorrow = DateTime.Now.AddDays(1f);
            dayStart = new DateTime(now.Year, now.Month, now.Day, 8, 0, 0);
            otherEnd = new DateTime(now.Year, now.Month, now.Day, 23, 00, 0);
            fridayEnd = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, 1, 0, 0);

            warningHour = false;
            warning30 = false;
            warning10 = false;
            warning5 = false;
            warning1 = false;
        }
        private static void handleCheck()
        {
            ExeHandler exeHandler = new ExeHandler();

            if (exeHandler.IsThisAppRunning())
            {
                return;
            }

            exeHandler.AddExecutables();
            exeHandler.DisableAll();
            if (exeHandler.ExesRunning().Length > 0)
            {
                handleRunning(exeHandler: exeHandler);
            }
        }
Beispiel #5
0
        public TimeHandler()
        {
            exeHandler = new ExeHandler();
            DateTime now      = DateTime.Now;
            DateTime tomorrow = DateTime.Now.AddDays(1f);

            dayStart  = new DateTime(now.Year, now.Month, now.Day, 8, 0, 0);
            otherEnd  = new DateTime(now.Year, now.Month, now.Day, 23, 00, 0);
            fridayEnd = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, 1, 0, 0);

            warningHour = false;
            warning30   = false;
            warning10   = false;
            warning5    = false;
            warning1    = false;
        }
        private static void handleRun(string exeName)
        {
            TimeHandler timeHandler = new TimeHandler();
            bool        time        = timeHandler.CheckTime();

            if (time)
            {
                ExeHandler exeHandler = new ExeHandler();
                exeHandler.AddExecutables();
                exeHandler.EnableAll();
                exeHandler.StartExe(exeName);
                exeHandler.DisableAll();
                timeHandler.StartTimer();
                NotificationHandler.NotifyWindows("Starting timer.");
                DateTime start = DateTime.Now;
                while (true)
                {
                    DateTime now = DateTime.Now;
                    handleRunning(timeHandler, exeHandler);
                    Thread.Sleep(60000);
                }
            }
        }
 private static void handleRun(string exeName)
 {
     TimeHandler timeHandler = new TimeHandler();
     bool time = timeHandler.CheckTime();
     if(time) {
         ExeHandler exeHandler = new ExeHandler();
         exeHandler.AddExecutables();
         exeHandler.EnableAll();
         exeHandler.StartExe(exeName);
         exeHandler.DisableAll();
         timeHandler.StartTimer();
         NotificationHandler.NotifyWindows("Starting timer.");
         DateTime start = DateTime.Now;
         while(true) {
             DateTime now = DateTime.Now;
             handleRunning(timeHandler, exeHandler);
             Thread.Sleep(60000);
         }
     }
 }
        private static void handleRunning(TimeHandler timeHandler=null, ExeHandler exeHandler=null)
        {
            if(timeHandler == null)
                timeHandler = new TimeHandler();
            if(exeHandler == null)
                exeHandler = new ExeHandler();

            if(exeHandler.ExesRunning().Length > 0) {
                if(!timeHandler.CheckTime()) {
                    NotificationHandler.NotifyWindows("You've played enough for today. Shutting down.", () => {
                        Thread.Sleep(5000);
                        exeHandler.CloseExes();
                        exeHandler.DisableAll();
                        timeHandler.StopTimer();
                        Environment.Exit(0);
                    });
                }
            } else {
                NotificationHandler.NotifyWindows("Stopping timer.", () => {
                    exeHandler.DisableAll();
                    timeHandler.StopTimer();
                    Environment.Exit(0);
                });
            }
        }