Example #1
0
        public bool tryLoad(out Record[] recs, out TimeSpan previousSpan)
        {
            var list = new List<Record>();
            previousSpan = TimeSpan.Zero;
            try
            {
                var lines = File.ReadAllLines(pather.getPath());

                if (lines.Length > 0)
                    previousSpan = TimeSpan.FromTicks(Int64.Parse(lines[0]));

                for (int i = 1; i < lines.Length; i++)
                {
                    var split = lines[i].Split(',');

                    if (split.Length == 4)
                    {
                        list.Add(new Record
                        {
                            process = split[1],
                            runningTime = TimeSpan.FromTicks(Int64.Parse(split[2])),
                            timesFocused = Int32.Parse(split[3])
                        });
                    }

                }
                recs = list.ToArray();
                return true;
            }
            catch (FileNotFoundException e)
            {
                recs = list.ToArray();
                return true;
            }
        }
Example #2
0
 public void addRecord(Record rec)
 {
     var index = records.FindIndex(x => x.process == rec.process);
     if (index >= 0)
     {
         var temp = records[index];
         temp.runningTime += rec.runningTime;
         temp.timesFocused += rec.timesFocused;
         records[index] = temp;
         if (records[index].timesFocused != temp.timesFocused)
             throw new Exception("value wasn't updated");
     }
     else
     {
         records.Add(rec);
     }
 }
Example #3
0
        public void endRecording()
        {
            if (isRecording)
            {
                string process = lastProcess;
                var timesFocused = 0;
                TimeSpan runningTime;

                isRecording = false;
                var span = DateTime.Now - lastStart;
                var index = records.FindIndex(x => x.process == lastProcess);
                if (index >= 0)
                {
                    var rec = records[index];
                    rec.runningTime += span;
                    rec.timesFocused++;
                    records[index] = rec;
                    if (records[index].timesFocused != rec.timesFocused)
                        throw new Exception("value wasn't updated");

                    runningTime = rec.runningTime;
                    timesFocused = rec.timesFocused;
                }
                else
                {
                    runningTime = span;
                    timesFocused = 1;

                    var rec = new Record
                    {
                        process = lastProcess,
                        runningTime = span,
                        timesFocused = 1
                    };

                    records.Add(rec);
                }
                Console.WriteLine("UnFocused Process: {0}\n\tRunning Time: {1:N2}min\n\tTimes Focused: {2}", process, runningTime.TotalMinutes, timesFocused);
            }
        }