Ejemplo n.º 1
0
 /// <summary>
 /// Clears all tracked events and periods and sets a new start event.
 /// <param name="startEvent">The new start event.</param>
 /// </summary>
 public void ClearTrackedState(TrackableEvent startEvent)
 {
     _events.Clear();
       _events.Add(startEvent);
       _completedPeriods.Clear();
       _currentTimePeriod = null;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a trackable event to the time tracker.
        /// </summary>
        /// <param name="trackableEvent">Trackable event.</param>
        public void AddEvent(TrackableEvent trackableEvent)
        {
            TrackableEvent previousEvent = LastEvent;
              _events.Add(trackableEvent);

              TimePeriod newPeriod = new TimePeriod(GetPeriodTypeFromEvent(previousEvent.Activity),
                                            GetPeriodDuration(previousEvent.Time,
                                                              trackableEvent.Time));
              if (_currentTimePeriod != null)
              {
            newPeriod.IsWorkTime = _currentTimePeriod.IsWorkTime;
            _currentTimePeriod = null;
              }
              _completedPeriods.Add(newPeriod);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets the time period from its starting event activity type.
 /// </summary>
 /// <param name="activity">Starting event activity type.</param>
 /// <returns>Time period type.</returns>
 public static TimePeriod.PeriodType GetPeriodTypeFromEvent(TrackableEvent.EventActivity activity)
 {
     return (activity == TrackableEvent.EventActivity.Active) ?
      TimePeriod.PeriodType.Active : TimePeriod.PeriodType.Inactive;
 }
        /// <summary>
        /// Adds an event to the time tracker and resets the tracker state if appropriate.
        /// </summary>
        /// <param name="trackableEvent">Event to add.</param>
        public void AddEvent(TrackableEvent trackableEvent)
        {
            if ((trackableEvent.Time.DayOfYear != _timeTracker.FirstEvent.Time.DayOfYear) &&
              (trackableEvent.Type == TrackableEvent.EventType.Unlock))
              {
            // The new event starts a new work day
            _timeTracker.ClearTrackedState(new TrackableEvent(TrackableEvent.EventType.Start,
                                                          trackableEvent.Time));
              }
              else
              {
            // Add event normally
            _timeTracker.AddEvent(trackableEvent);
              }

              SaveSettings();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Adds an event and checks that the last time period has expected values.
 /// </summary>
 /// <param name="tracker">Time tracker to test.</param>
 /// <param name="type">Type of event to add.</param>
 private void CheckLastPeriod(TimeTracker tracker,
                          TrackableEvent.EventType type)
 {
     TrackableEvent previousEvent = tracker.LastEvent;
       AddEvent(tracker, type, new TimeSpan(0, 1, 0));
       TimePeriod period = tracker.LastCompletedTimePeriod;
       TimePeriod.PeriodType expectedType = TimeTracker.GetPeriodTypeFromEvent(previousEvent.Activity);
       Assert.That(period.Type, Is.EqualTo(expectedType));
       Assert.That(period.Duration,
           Is.EqualTo(tracker.LastEvent.Time.Subtract(previousEvent.Time)));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds a trackable event to the tracker and verifies that it matches the
        /// last event in the tracker.
        /// </summary>
        /// <param name="tracker">Time tracker to test.</param>
        /// <param name="type">Type of event to add.</param>
        /// <param name="delay">Delay of the new event since the previous event.</param>
        private void AddEvent(TimeTracker tracker,
                          TrackableEvent.EventType type, TimeSpan delay)
        {
            Console.WriteLine(String.Format("Adding {0} after {1}", type, delay));

              // Add delay to last event time
              int eventCount = tracker.GetEvents().Count;
              DateTime time = tracker.GetEvents()[eventCount - 1].Time.Add(delay);

              // Add and verify the event
              tracker.AddEvent(new TrackableEvent(type, time));
              Assert.That(tracker.GetEvents().Count, Is.EqualTo(++eventCount));
              TrackableEvent lastEvent = tracker.LastEvent;
              Assert.That(lastEvent.Type, Is.EqualTo(type));
              Assert.That(lastEvent.Time, Is.EqualTo(time));
        }