public void SetCurrentActivity(ActivityId activity, DateTime now)
        {
            lock (this)
            {
                this.EndTime = now;

                if (this.CurrentActivityRegion == null || this.CurrentActivityRegion.ActivityId != activity)
                {
                    if (this.CurrentActivityRegion != null)
                    {
                        // Wrap up the previous activity
                        this.ActivitySummaries[this.CurrentActivityRegion.ActivityId] += now - this.lastUpdateTime;
                        this.CurrentActivityRegion.EndTime = now;
                    }
                    else if (this.ActivityRegions.Count > 0)
                    {
                        // We probably loaded from disk, fill the gap with a nodata region
                        var lastRegion = this.ActivityRegions[this.ActivityRegions.Count - 1];
                        var newRegion  = new ActivityRegion(lastRegion.EndTime, now, ActivityId.NoData);
                        this.ActivitySummaries[newRegion.ActivityId] += newRegion.Duration;
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            this.ActivityRegions.Add(newRegion);
                        });
                    }

                    // Start new activity
                    this.CurrentActivityRegion = new ActivityRegion(now, now, activity);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.ActivityRegions.Add(this.CurrentActivityRegion);
                    });
                }

                this.lastUpdateTime = now;
            }

            OnPropertyChanged("EndTime");
            OnPropertyChanged("ActivitySummaries");
            OnPropertyChanged("CurrentActivityRegion");
            OnPropertyChanged("ActivityRegions");
        }
Beispiel #2
0
 public static Color GetColorFromActivity(ActivityId activityId)
 {
     return(activityIdToActivityConfig[activityId].Color);
 }
Beispiel #3
0
 public static string GetNameFromActivity(ActivityId activityId)
 {
     return(activityIdToActivityConfig[activityId].Name);
 }
Beispiel #4
0
 public ActivityRegion(DateTime startTime, DateTime endTime, ActivityId activity)
 {
     this.StartTime  = startTime;
     this.EndTime    = endTime;
     this.ActivityId = activity;
 }