private void initAppTimeDict() { foreach (KidsGuardConfig.MonitoredApp blockedApp in KidsGuardConfig.GetConfig().MonitoredApps) { // configured time int allowedTime = blockedApp.AllowedTime; string blockedAppTitle = blockedApp.Title.ToLower(); // for weekday DateTime dt = DateTime.Now; if (dt.DayOfWeek != DayOfWeek.Saturday && dt.DayOfWeek != DayOfWeek.Sunday) { if (allowedTime > 600) { allowedTime = 600; // 10 minutes } } // deduct today used time allowedTime = allowedTime - _usageStat.getAppTimeUsed(blockedAppTitle); logger.Info(blockedAppTitle + " initial allow time: " + allowedTime); _appTimeDict.Add(blockedAppTitle, allowedTime); } }
public void checkBreakTime(UsageStat usageStat) { if (usageStat.State == "RUN") { //if (AppConfig.userToMonitor.IndexOf(Environment.UserName) == -1) //{ // return; //} // first reminder (10 mins) if (usageStat.SessionTime == 10 * 60 && !usageStat.Reminder1) { usageStat.Reminder1 = true; new System.Threading.Thread(new System.Threading.ThreadStart(delegate { System.Windows.Forms.MessageBox.Show(null, "Beware the power of the dark side!", "KidsGuard", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); })).Start(); } // second reminder (5 mins) if (usageStat.SessionTime == 5 * 60 && !usageStat.Reminder2) { usageStat.Reminder2 = true; new System.Threading.Thread(new System.Threading.ThreadStart(delegate { System.Windows.Forms.MessageBox.Show(null, "The Emperor is most displeased with your lack of apparent progress!", "KidsGuard", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); })).Start(); } if (usageStat.SessionTime == 0) { logger.Info("Lock Station due to session timeout"); usageStat.UpdateToLock(); // lock computer Win32.LockWorkStation(); } // check total computer time if (usageStat.getTotalComputerTime() >= KidsGuardConfig.GetConfig().TotalComputerTime) { logger.Info("Lock Station due to total computer time is used up"); usageStat.UpdateToLock(); // lock computer Win32.LockWorkStation(); } } }
public AppBlocker(UsageStat usageStat) { _usageStat = usageStat; _totalAllowedTime = KidsGuardConfig.GetConfig().TotalAllowedTime; initAppTimeDict(); }