예제 #1
0
        // Calculations:

        public TimeSpan CalculateTotalBalance(DateTime?calculateEndDate = null)
        {
            TimeSpan totalBalance = new TimeSpan(0);
            var      StampRange   = calculateEndDate.HasValue ? StampList.Where(s => s.Day.Date <= calculateEndDate) : StampList;

            foreach (var stamp in StampRange)
            {
                if (stamp.Day == Time.Today)
                {
                    continue;
                }
                totalBalance = totalBalance.Add(DayBalance(stamp));
            }
            return(totalBalance);
        }
예제 #2
0
        public void ResumeStamping()
        {
            // assuming here that activity is null!
            //if (TodayCurrentActivity != null)
            //throw new NotSupportedException($"TodayCurrentActivity is not null after resume: {TodayCurrentActivity.Activity}, started: {TodayCurrentActivity.Begin}");

            // this can happen when:
            // starting the app (e.g. new day autostart, same day computer restart)
            // resuming from sleep (e.g. new day resume, same day resume)
            // resuming from lunch break (insert pause parameter)..

            // find existing stamp for today:

            IsStamping = true;

            var existing = StampList.SingleOrDefault(t => t.Day == Time.Today);

            if (existing != null)
            {
                Today     = CurrentShown = existing;
                Today.End = TimeSpan.Zero;

                // TODO: (optionally) ask in a notification, whether have been working or not since last known stamp (default yes, if choosing no will automatically insert a pause)...

                bool hasSetPause = RestoreLastActivity(Today);

                // update event (for ui):
                CurrentActivityUpdated();

                // show notification:
                if (hasSetPause)
                {
                    //new Task(() =>
                    //{
                    //    System.Threading.Thread.Sleep(10000);
                    //}).Start();
                    PopupDialog.ShowAfterPause(Today.Pause, TodayCurrentActivity.Activity);
                }
                else
                {
                    PopupDialog.ShowCurrentlyTrackingActivity(TodayCurrentActivity.Activity);
                }

                return;
            }

            // new day, new stamp:

            TodayCurrentActivity = null;
            Today = CurrentShown = new Stamp(Time.Today, GetNowTime(), Settings.DefaultWorkingHours);
            StampList.Add(Today);

            // not specified ? -> keep tracking for latest activity...
            if (String.IsNullOrEmpty(Settings.AlwaysStartNewDayWithActivity))
            {
                foreach (var day in StampList.OrderByDescending(s => s.Day))
                {
                    if (!day.ActivityRecords.Any())
                    {
                        continue;
                    }
                    StartNewActivity(day.GetLastActivity().Activity, null);
                    break;
                }
            }

            // if not yet set -> start tracking either default activity or just the first activity...
            if (TodayCurrentActivity == null)
            {
                StartNewActivity(Settings.AlwaysStartNewDayWithActivity ?? Settings.TrackedActivities.ElementAt(0), null);
            }

            var previous = StampList.Where(s => s.Day < Today.Day).OrderByDescending(s => s.Day).FirstOrDefault();

            PopupDialog.ShowCurrentlyTrackingActivityOnNewDay(TodayCurrentActivity.Activity, previous);
        }