PM.BLL/PMService.cs
/// <summary>
/// Gets workout details pertaining to certain requirements
/// </summary>
/// <param name="interval">The interval</param>
/// <returns>The workout details</returns>
Gets workout details pertaining to certain requirements
Gets workout details pertaining to certain requirements
private WorkoutDetails? GetWorkoutDetails(Interval interval)
        {
            bool requireSplits = false;
            bool requireRest = false;
            WorkoutDuration? workoutDuration = null;
            if (interval.IntervalType != null && interval.WorkoutType == null)
            {
                switch(interval.IntervalType)
                {
                    case IntervalType.Calorie:
                        workoutDuration = WorkoutDuration.Calories;
                        requireRest = true;
                        break;
                    case IntervalType.Distance:
                        workoutDuration = WorkoutDuration.Distance;
                        requireRest = true;
                        break;
                    case IntervalType.Time:
                        workoutDuration = WorkoutDuration.Time;
                        requireRest = true;
                        break;
                    case IntervalType.WattMinute:
                        workoutDuration = WorkoutDuration.WattMinutes;
                        requireRest = true;
                        break;
                    case IntervalType.CalorieUndefinedRest:
                        workoutDuration = WorkoutDuration.Calories;
                        interval.SecondsOfRest = 0;
                        break;
                    case IntervalType.DistanceUndefinedRest:
                        workoutDuration = WorkoutDuration.Distance;
                        interval.SecondsOfRest = 0;
                        break;
                    case IntervalType.TimeUndefinedRest:
                        workoutDuration = WorkoutDuration.Time;
                        interval.SecondsOfRest = 0;
                        break;
                    case IntervalType.WattMinuteUndefinedRest:
                        workoutDuration = WorkoutDuration.WattMinutes;
                        interval.SecondsOfRest = 0;
                        break;
                }
            }
            if (interval.WorkoutType != null && interval.IntervalType == null) { 
                switch (interval.WorkoutType)
                {
                    case WorkoutType.FixedDistanceNoSplits:
                        workoutDuration = WorkoutDuration.Distance;
                        break;
                    case WorkoutType.FixedTimeNoSplits:
                        workoutDuration = WorkoutDuration.Time;
                        break;
                    case WorkoutType.FixedCalorieWithSplits:
                        workoutDuration = WorkoutDuration.Calories;
                        requireSplits = true;
                        break;
                    case WorkoutType.FixedDistanceWithSplits:
                        workoutDuration = WorkoutDuration.Distance;
                        requireSplits = true;
                        break;
                    case WorkoutType.FixedTimeWithSplits:
                        workoutDuration = WorkoutDuration.Time;
                        requireSplits = true;
                        break;
                    case WorkoutType.FixedWattMinuteWithSplits:
                        workoutDuration = WorkoutDuration.WattMinutes;
                        requireSplits = true;
                        break;
                    case WorkoutType.FixedCalorieInterval:
                        workoutDuration = WorkoutDuration.Calories;
                        requireRest = true;
                        break;
                    case WorkoutType.FixedDistanceInterval:
                        workoutDuration = WorkoutDuration.Distance;
                        requireRest = true;
                        break;
                    case WorkoutType.FixedTimeInterval:
                        workoutDuration = WorkoutDuration.Time;
                        requireRest = true;
                        break;
                    default:
                        _logger.LogError("Invalid workout type encountered when setting fixed interval workout. No workout has been set.");
                        break;
                }
            }
            if (workoutDuration == null)
            {
                _logger.LogCritical("Workout duration was not set in one of the cases. No workout has been set.");
                return null;
            }
            if (requireSplits && requireRest)
            {
                _logger.LogCritical("A configuration error occurred in one of the cases as splits and rest should never both be required. No workout has been set.");
                return null;
            }
            if (requireSplits && interval.Splits == null)
            {
                _logger.LogError("A workout type requiring splits was provided, but no split was defined. No workout has been set.");
                return null;
            }
            if (requireRest && interval.SecondsOfRest == null)
            {
                _logger.LogError("A workout type requiring rest was provided, but no rest was defined. No workout has been set.");
                return null;
            }
            return new WorkoutDetails(workoutDuration.Value, requireRest, requireSplits);
        }
private WorkoutDetails ? GetWorkoutDetails ( Interval interval ) { bool requireSplits = false ; bool requireRest = false ; WorkoutDuration ? workoutDuration = null ; if ( interval . IntervalType != null && interval . WorkoutType == null ) { switch ( interval . IntervalType ) { case IntervalType . Calorie : workoutDuration = WorkoutDuration . Calories ; requireRest = true ; break ; case IntervalType . Distance : workoutDuration = WorkoutDuration . Distance ; requireRest = true ; break ; case IntervalType . Time : workoutDuration = WorkoutDuration . Time ; requireRest = true ; break ; case IntervalType . WattMinute : workoutDuration = WorkoutDuration . WattMinutes ; requireRest = true ; break ; case IntervalType . CalorieUndefinedRest : workoutDuration = WorkoutDuration . Calories ; interval . SecondsOfRest = 0 ; break ; case IntervalType . DistanceUndefinedRest : workoutDuration = WorkoutDuration . Distance ; interval . SecondsOfRest = 0 ; break ; case IntervalType . TimeUndefinedRest : workoutDuration = WorkoutDuration . Time ; interval . SecondsOfRest = 0 ; break ; case IntervalType . WattMinuteUndefinedRest : workoutDuration = WorkoutDuration . WattMinutes ; interval . SecondsOfRest = 0 ; break ; } } if ( interval . WorkoutType != null && interval . IntervalType == null ) { switch ( interval . WorkoutType ) { case WorkoutType . FixedDistanceNoSplits : workoutDuration = WorkoutDuration . Distance ; break ; case WorkoutType . FixedTimeNoSplits : workoutDuration = WorkoutDuration . Time ; break ; case WorkoutType . FixedCalorieWithSplits : workoutDuration = WorkoutDuration . Calories ; requireSplits = true ; break ; case WorkoutType . FixedDistanceWithSplits : workoutDuration = WorkoutDuration . Distance ; requireSplits = true ; break ; case WorkoutType . FixedTimeWithSplits : workoutDuration = WorkoutDuration . Time ; requireSplits = true ; break ; case WorkoutType . FixedWattMinuteWithSplits : workoutDuration = WorkoutDuration . WattMinutes ; requireSplits = true ; break ; case WorkoutType . FixedCalorieInterval : workoutDuration = WorkoutDuration . Calories ; requireRest = true ; break ; case WorkoutType . FixedDistanceInterval : workoutDuration = WorkoutDuration . Distance ; requireRest = true ; break ; case WorkoutType . FixedTimeInterval : workoutDuration = WorkoutDuration . Time ; requireRest = true ; break ; default : _logger . LogError ( " " ) ; break ; } } if ( workoutDuration == null ) { _logger . LogCritical ( " " ) ; return null ; } if ( requireSplits && requireRest ) { _logger . LogCritical ( " " ) ; return null ; } if ( requireSplits && interval . Splits == null ) { _logger . LogError ( " " ) ; return null ; } if ( requireRest && interval . SecondsOfRest == null ) { _logger . LogError ( " " ) ; return null ; } return new WorkoutDetails ( workoutDuration . Value , requireRest , requireSplits ) ; }
Gets workout details pertaining to certain requirements
Gets workout details pertaining to certain requirements
// Variable intervals with rest // Variable intervals without rest. Mandated 0:00 // Fixed, No Splits // Fixed, Splits // Fixed, Intervals // Error case
The workout details
The workout details
interval
Interval
None