Пример #1
0
        public FormStat(UsageStat p_usageStat)
        {
            InitializeComponent();
            usageStat = p_usageStat;

            updateForm();
        }
Пример #2
0
        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();
                }
            }
        }
Пример #3
0
        public static void saveUsageTime(UsageStat usageStat)
        {
            SQLiteParameter p1 = new SQLiteParameter("currDate", DateTime.Today.Date);
            SQLiteParameter p2 = new SQLiteParameter("totalTime", Math.Ceiling(usageStat.SystemRunningTime.TotalSeconds));
            SQLiteParameter p3 = new SQLiteParameter("sessTime", usageStat.SessionTime);

            using (SQLiteCommand cmd = conn.CreateCommand())
            {
                bool hasRows = false;
                cmd.CommandText = @"SELECT CURR_DATE, TOTAL_TIME, SESS_TIME FROM RT_STATS WHERE CURR_DATE=@currDate";
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add(p1);
                SQLiteDataReader r = cmd.ExecuteReader();
                hasRows = r.HasRows;
                r.Close();
                if (hasRows)
                {
                    using (SQLiteCommand updateCmd = conn.CreateCommand())
                    {
                        updateCmd.CommandText = @"UPDATE RT_STATS SET TOTAL_TIME=@totalTime, SESS_TIME=@sessTime WHERE CURR_DATE=@currDate";
                        updateCmd.CommandType = CommandType.Text;
                        updateCmd.Parameters.Add(p1);
                        updateCmd.Parameters.Add(p2);
                        updateCmd.Parameters.Add(p3);
                        updateCmd.ExecuteNonQuery();
                    }
                }
                else
                {
                    // today record not created
                    using (SQLiteCommand insertCmd = conn.CreateCommand())
                    {
                        insertCmd.CommandText = @"INSERT INTO RT_STATS(CURR_DATE, TOTAL_TIME, SESS_TIME) VALUES(@currDate, @totalTime, @sessTime)";
                        insertCmd.CommandType = CommandType.Text;
                        insertCmd.Parameters.Add(p1);
                        insertCmd.Parameters.Add(p2);
                        insertCmd.Parameters.Add(p3);
                        insertCmd.ExecuteNonQuery();
                    }
                }
            }
        }
Пример #4
0
 public static void saveProgramTime(UsageStat usageStat)
 {
     using (var tra = conn.BeginTransaction())
     {
         try
         {
             foreach (KeyValuePair <string, int> entry in usageStat.programTime)
             {
                 string program   = entry.Key;
                 int    spendTime = entry.Value;
                 string process   = program.Substring(0, program.IndexOf(":"));
                 string title     = program.Substring(program.IndexOf(":") + 1);
                 saveProgramTime(process, title, spendTime);
             }
             tra.Commit();
         }
         catch (Exception ex)
         {
             tra.Rollback();
             logger.Error("Failed to save to db", ex);
         }
     }
 }
Пример #5
0
        public static void restoreStat(UsageStat usageStat)
        {
            using (SQLiteCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = @"SELECT CURR_DATE, TOTAL_TIME, SESS_TIME FROM RT_STATS WHERE CURR_DATE=@currDate";
                cmd.CommandType = CommandType.Text;
                SQLiteParameter p1 = new SQLiteParameter("currDate", DateTime.Today.Date);
                cmd.Parameters.Add(p1);
                SQLiteDataReader r = cmd.ExecuteReader();
                if (r.HasRows)
                {
                    r.Read();
                    int systemRunningTime = (int)r["TOTAL_TIME"];
                    int SessionTime       = (int)r["SESS_TIME"];
                    usageStat.StartUpTime = DateTime.Now.AddSeconds(-systemRunningTime);
                    usageStat.SessionTime = SessionTime;
                }
                r.Close();
            }

            using (SQLiteCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText = @"SELECT LOG_DATE, PROCESS_NAME, WIN_TITLE, SPEND_TIME FROM HIST_STATS WHERE LOG_DATE=@currDate";
                cmd.CommandType = CommandType.Text;
                SQLiteParameter p1 = new SQLiteParameter("currDate", DateTime.Today.Date);
                cmd.Parameters.Add(p1);
                SQLiteDataReader r = cmd.ExecuteReader();
                if (r.HasRows)
                {
                    while (r.Read())
                    {
                        usageStat.addProgramTime((string)r["PROCESS_NAME"], (string)r["WIN_TITLE"], (int)r["SPEND_TIME"]);
                    }
                }
                r.Close();
            }
        }
Пример #6
0
 public AppBlocker(UsageStat usageStat)
 {
     _usageStat        = usageStat;
     _totalAllowedTime = KidsGuardConfig.GetConfig().TotalAllowedTime;
     initAppTimeDict();
 }