public void Visit(ForegroundApp result, string type, bool isActive = false) { var e = new AppEvent(); var session = FindSession(); e.Session = session; e.SequenceId = ++_sessions[session]; e.Type = e.GetType().Name; e.TriggeredAt = result.TriggeredAt; e.TimeStamp = (long)e.TriggeredAt.Value.Subtract(new DateTime(2010, 01, 01)).TotalMilliseconds; e.TriggeredBy = isActive ? type : "-"; e.Duration = 1000.ToString(); e.ActiveDocumentName = ""; e.ActiveDocumentType = ""; e.ActiveWindowCaption = result.WindowTitle; e.ActiveWindowType = ""; e.Details = result.Details; e.AppType = type; e.ProcessHandle = result.ProcessHandle; e.ProcessName = result.ProcessName; e.ProcessPath = result.ProcessPath; e.WindowTitle = result.WindowTitle; e.IsActive = isActive; session.Events.Add(e); _baseContext.Events.Add(e); SaveChanges(); }
private void ForegroundAppUpdate() { var allwindows = SystemWindow.AllToplevelWindows.Select(ExtractAppData).ToArray(); ForegroundAppsDiscovered?.Invoke(allwindows); ForegroundApp a = ExtractAppData(SystemWindow.ForegroundWindow); if (!_current.Equals(a)) { _current.Status = AppStatus.Deactivated; ForegroundAppChanged?.Invoke(_current, a); _current = a; } }
public void ForegroundChanged(ForegroundApp old, ForegroundApp current) { Logger.Instance.Log(old.Details); Logger.Instance.Log(current.Details); foreach (var hook in appHooks) { // Notify Deactivation if (old.WindowTitle != null && Regex.IsMatch(old.WindowTitle, hook.WindowTitleRegx) && Regex.IsMatch(old.ProcessName, hook.ProcessNameRegx)) { hook.WindowDeactivated(old.WindowTitle, old.ProcessName); } // Notify Activation if (Regex.IsMatch(current.WindowTitle, hook.WindowTitleRegx) && Regex.IsMatch(current.ProcessName, hook.ProcessNameRegx)) { var type = hook.WindowActivated(current.WindowTitle, current.ProcessName); DBInsertAgent.Instance.Visit(current, type.ToString(), true); } } }