Beispiel #1
0
        /// <summary>
        /// Saves the timestamp, start and end, process name and window title into the database.
        ///
        /// In case the user doesn't want the window title to be stored (For privacy reasons),
        /// it is obfuscated.
        /// </summary>
        /// <param name="window"></param>
        /// <param name="process"></param>
        internal static void InsertSnapshot(WindowsActivityEntry entry)
        {
            try
            {
                if (Shared.Settings.AnonymizeSensitiveData)
                {
                    var activityCategory = ProcessToActivityMapper.Map(entry.Process, entry.WindowTitle);
                    entry.WindowTitle = string.Format("{0} (category: {1})", Dict.Anonymized, activityCategory);  // obfuscate window title
                }

                // if end time is missing, don't store anything
                if (entry.TsEnd == DateTime.MinValue)
                {
                    Database.GetInstance().LogWarning("TsEnd of WindowsActivitySwitch was empty.");
                    return;
                }

                var query = string.Format(QUERY_INSERT,
                                          "strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime')",
                                          Database.GetInstance().QTime2(entry.TsStart),
                                          Database.GetInstance().QTime2(entry.TsEnd),
                                          Database.GetInstance().Q(entry.WindowTitle),
                                          Database.GetInstance().Q(entry.Process));

                Database.GetInstance().ExecuteDefaultQuery(query);
            }
            catch (Exception e)
            {
                Logger.WriteToLogFile(e);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Saves the previous WindowsActivityEvent into the database
        ///
        /// (tsEnd not know yet for current entry)
        /// (includes a process handle for later)
        /// (also re-sets the previous item values)
        /// </summary>
        /// <param name="windowTitle"></param>
        /// <param name="process"></param>
        private void SetCurrentAndStorePrevious_WindowsActivityEvent(DateTime tsStart, string windowTitle, string process, IntPtr handle)
        {
            var tmpPreviousEntry = _previousEntry; // perf, because storing takes a moment

            // set current entry
            _previousEntry = new WindowsActivityEntry(tsStart, windowTitle, process, handle); // tsEnd is not known yet

            // update tsEnd & store previous entry
            if (tmpPreviousEntry != null)
            {
                tmpPreviousEntry.TsEnd = DateTime.Now;
                Queries.InsertSnapshot(tmpPreviousEntry);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Saves the previous and current WindowsActivityEvent into the database
        /// (also re-sets the previous item values)
        ///
        /// !! Only used when tsEnd will not be available later, as the tool/computer is being shut down
        /// </summary>
        /// <param name="tsStart"></param>
        /// <param name="tsEnd"></param>
        /// <param name="windowTitle"></param>
        /// <param name="process"></param>
        private void SetCurrentAndStoreThisAndPrevious_WindowsActivityEvent(string windowTitle, string process)
        {
            // store previous entry
            //var tmpPreviousEntry = _previousEntry; // perf, because storing takes a moment

            if (_previousEntry != null)
            {
                SetCurrentAndStorePrevious_WindowsActivityEvent(_previousEntry.TsStart, _previousEntry.WindowTitle, _previousEntry.Process, _previousEntry.Handle);
            }

            // set current entry
            _previousEntry = new WindowsActivityEntry(DateTime.Now, DateTime.Now, windowTitle, process, IntPtr.Zero); // tsEnd is right now

            // set store current entry
            Queries.InsertSnapshot(_previousEntry);
        }
Beispiel #4
0
        internal static void AddMissedSleepIdleEntry(List <Tuple <long, DateTime, DateTime> > toFix)
        {
            foreach (var item in toFix)
            {
                var idleTimeFix = item.Item2.AddMilliseconds(Settings.NotCountingAsIdleInterval_ms);
                var tsEnd       = item.Item3;

                // add missed sleep idle entry
                var tempItem = new WindowsActivityEntry(idleTimeFix, tsEnd, Settings.ManualSleepIdle, Dict.Idle, IntPtr.Zero);
                InsertSnapshot(tempItem);

                // update tsEnd of previous (wrong entry)
                var query = "UPDATE " + Settings.DbTable + " SET tsEnd = " + Database.GetInstance().QTime2(idleTimeFix) + " WHERE id = " + item.Item1;
                Database.GetInstance().ExecuteDefaultQuery(query);
            }

            if (toFix.Count > 0)
            {
                Database.GetInstance().LogInfo("Fixed " + toFix.Count + " missed IDLE sleep entries.");
            }
        }
Beispiel #5
0
        /// <summary>
        /// Saves the timestamp, start and end, process name and window title into the database.
        ///
        /// In case the user doesn't want the window title to be stored (For privacy reasons),
        /// it is obfuscated.
        /// </summary>
        /// <param name="window"></param>
        /// <param name="process"></param>
        internal static void InsertSnapshot(WindowsActivityEntry entry)
        {
            try
            {
                // if user is browsing in InPrivate-mode, obfuscate window title (doesn't work in Google Chrome!)
                if (ProcessToActivityMapper.IsBrowser(entry.Process) && Settings.InkognitoBrowsingTerms.Any(entry.WindowTitle.ToLower().Contains))
                {
                    entry.WindowTitle = Dict.Anonymized;  // obfuscate window title
                }

                // if user enabled private tracking, obfuscate window title
                if (Shared.Settings.AnonymizeSensitiveData)
                {
                    var activityCategory = ProcessToActivityMapper.Map(entry.Process, entry.WindowTitle);
                    entry.WindowTitle = string.Format("{0} (category: {1})", Dict.Anonymized, activityCategory);  // obfuscate window title
                }

                // if end time is missing, don't store anything
                if (entry.TsEnd == DateTime.MinValue)
                {
                    Database.GetInstance().LogWarning("TsEnd of WindowsActivitySwitch was empty.");
                    return;
                }

                var query = string.Format(QUERY_INSERT,
                                          "strftime('%Y-%m-%d %H:%M:%f', 'now', 'localtime')",
                                          Database.GetInstance().QTime2(entry.TsStart),
                                          Database.GetInstance().QTime2(entry.TsEnd),
                                          Database.GetInstance().Q(entry.WindowTitle),
                                          Database.GetInstance().Q(entry.Process));

                Database.GetInstance().ExecuteDefaultQuery(query);
            }
            catch (Exception e)
            {
                Logger.WriteToLogFile(e);
            }
        }