示例#1
0
 private void Reset()
 {
     Processes.Clear();
     Breaks.Clear();
     currentBreak   = null;
     currentProcess = null;
     ElapsedTime    = 0d;
 }
示例#2
0
        private void PoolData(object state)
        {
            if (SessionState == SessionStates.Active)
            {
                IntPtr hwnd = GetForegroundWindow();
                uint   pid;
                GetWindowThreadProcessId(hwnd, out pid);
                string  processName;
                Process proc = Process.GetProcessById((int)pid);
                try
                {
                    processName = Path.GetFileName(proc.MainModule.FileName);
                }
                catch (System.ComponentModel.Win32Exception)
                {
                    processName = Properties.Resources.unknown;
                }

                if (currentProcess == null)
                {
                    currentProcess = new ProcessData(processName);
                    Processes.Add(currentProcess);
                }
                else if (currentProcess.ProcessName != processName)
                {
                    var foundIndex = Processes.FindIndex(p => p.ProcessName == processName);
                    if (foundIndex > -1)
                    {
                        currentProcess = Processes[foundIndex];
                    }
                    else
                    {
                        currentProcess = new ProcessData(processName);
                        Processes.Add(currentProcess);
                    }
                }
                string windowtitle;
                if (IsBrowser(processName))
                {
                    //windowtitle = GetWindowTitle(hwnd);
                    var url = GetChromeUrl();
                    if (String.IsNullOrWhiteSpace(url))
                    {
                        windowtitle = Properties.Resources.unknown;
                        //windowtitle = GetWindowTitle(hwnd);
                    }
                    else
                    {
                        if (!url.StartsWith("http"))
                        {
                            windowtitle = Properties.Resources.unknown;
                            //url = url.Insert(0, "http://");
                        }
                        else
                        {
                            Uri uri = new Uri(url, UriKind.Absolute);
                            windowtitle = uri.Host;
                        }
                    }
                }
                else
                {
                    windowtitle = GetWindowTitle(hwnd);
                }
                if (lastPooledTime != null)
                {
                    var    now = DateTime.Now;
                    double secondsPassedBetweenPools = (now - lastPooledTime).TotalSeconds;
                    //Debug.WriteLine(secondsPassedBetweenPools + " ================ " + windowtitle);
                    if (secondsPassedBetweenPools > 100)
                    {
                        secondsPassedBetweenPools = 1;
                    }
                    currentProcess.IncrementFocusedSeconds(secondsPassedBetweenPools, windowtitle);
                    ElapsedTime   += secondsPassedBetweenPools;
                    lastPooledTime = now;
                }
            }
        }