Beispiel #1
0
 public static void SetEnd(Stamp stamp, TimeSpan value)
 {
     if (stamp.End != default(TimeSpan) && value > stamp.End)
     {
         // also move latest activity to the correct later end time
         var activity = stamp.GetLastActivity();
         if (activity != null)
         {
             activity.End = value;
         }
     }
     else if (stamp.End == default(TimeSpan) || value < stamp.End)
     {
         // cutt off later activities and/or set the latest activity to the correct earlier end time
         var activities = stamp.ActivityRecords.OrderByDescending(r => r.Begin.Value).ToArray();
         foreach (var act in activities)
         {
             // starts after 'new check-out': remove activity completely:
             if (act.Begin.Value >= value)
             {
                 stamp.ActivityRecords.Remove(act);
             }
             // starts before: set new end time for activity and stop iteration:
             else
             {
                 act.End = value;
                 break;
             }
         }
     }
     stamp.End = value;
 }
Beispiel #2
0
 public void DeleteActivity(Stamp stamp, ActivityRecord activity)
 {
     if (activity == TodayCurrentActivity)
     {
         // todays end auf neuen letzten zeitpunkt setzen, current activity clearen:
         stamp.ActivityRecords.Remove(activity);
         TodayCurrentActivity = null;
         var newLastActivity = stamp.GetLastActivity();
         stamp.End = newLastActivity.End.Value;
         // TODO: need to recalculate pause?
         TimeManager.CalculatePauseFromActivities(stamp);
     }
     else if (activity == stamp.GetFirstActivity())
     {
         // update todays start time:
         stamp.ActivityRecords.Remove(activity);
         var newFirstActivity = stamp.GetFirstActivity();
         stamp.Begin = newFirstActivity.Begin.Value;
         // TODO: need to recalculate pause?
         TimeManager.CalculatePauseFromActivities(stamp);
     }
     else if (activity == stamp.GetLastActivity())
     {
         // update todays end time:
         stamp.ActivityRecords.Remove(activity);
         var newLastActivity = stamp.GetLastActivity();
         stamp.End = newLastActivity.End.Value;
         // TODO: need to recalculate pause?
         TimeManager.CalculatePauseFromActivities(stamp);
     }
     else
     {
         // in between activity; update todays pause time:
         stamp.ActivityRecords.Remove(activity);
         TimeManager.CalculatePauseFromActivities(stamp);
     }
 }
Beispiel #3
0
        private bool RestoreLastActivity(Stamp today)
        {
            // assuming the last activity is still valid, and the downtime is not considered a break:
            // if there is no running activity, try to restore the last activity
            if (TodayCurrentActivity == null)
            {
                var openEnd = today.ActivityRecords.FirstOrDefault(r => !r.End.HasValue);
                if (openEnd != null) // this case should actually never happen?
                {
                    Log.Add("Warning: RestoreLastActivity has found an open end activity. " + new StackTrace().ToString());
                    TodayCurrentActivity = openEnd;
                }
                else
                {
                    // this branch should be the default case for this method:

                    // get lastest logged activity:
                    var last = today.GetLastActivity();

                    // the downtime is considered a break:
                    if (IsQualifiedPauseBreak)
                    {
                        // determine pause time from last qualified event:

                        TimeSpan pauseStartTime;

                        // last lock off time is 'master':
                        if (Settings.IsLockingComputerWhenLeaving)
                        {
                            pauseStartTime       = last.End.Value;
                            TodayCurrentActivity = last;
                        }
                        // last mouse movement time is 'master':
                        else
                        {
                            pauseStartTime = GetTime(LastMouseMove.TimeOfDay); // should be on same day... ;-)
                            LastMouseMove  = default(DateTime);

                            last.End             = pauseStartTime;
                            TodayCurrentActivity = last;
                        }

                        // set pause:
                        Today.Pause = GetNowTime() - pauseStartTime;

                        // ... and resume with a new activity now:
                        TodayCurrentActivity = null;
                        StartNewActivity(last.Activity, last.Comment);
                        return(true);
                    }
                    // the downtime is not considered a break:
                    // otherwise, if log off time since then was more than 7 minutes, create and start new activity record (better documented, as the end time of the 'relative longer' absence is not lost):
                    else if (GetNowTime() - last.End.Value > TimeSpan.FromMinutes(7))
                    {
                        today.ActivityRecords.Add(new ActivityRecord()
                        {
                            Activity = last.Activity, Begin = last.End.Value, End = GetNowTime()
                        });
                        StartNewActivity(last.Activity, null);
                    }
                    // otherwise, assume this is a total unrelevant break, e.g. fetched a cup of coffee, went to toilet, so just resume that activity (end time is reset to null, ergo lost and not documented):
                    else
                    {
                        TodayCurrentActivity = last;
                        last.End             = null;
                    }
                }
            }
            return(false);
        }