PM.BLL/PMService.cs
/// <summary>
/// Builds only the commands in a variable interval workout
/// </summary>
/// <param name="intervals">The intervals</param>
/// <returns>Enumerable of the commands</returns>
Builds only the commands in a variable interval workout
Builds only the commands in a variable interval workout
private IEnumerable<ICommand>? BuildVariableWorkout(IEnumerable<Interval> intervals)
        {
            IList<Interval> intervalList = new List<Interval>(intervals);
            if (intervalList.Any(i => i.IntervalType == null))
            {
                _logger.LogError("All intervals must have a defined interval type. No workout has been set.");
                return null;
            }
            if (!intervalList.Any())
            {
                _logger.LogError("At least one interval must be defined. No workout has been set.");
                return null;
            }
            bool atLeastOneIntervalWithUndefinedRest = false;
            List<ICommand> commands = new();
            for (int intervalNumber = 0; intervalNumber < intervalList.Count; intervalNumber++)
            {
                Interval currentInterval = intervalList[intervalNumber];
                if (currentInterval.IntervalType == null)
                {
                    _logger.LogCritical("The interval type was unexpectedly null. No workout has been set.");
                    return null;
                }
                commands.Add(new SetWorkoutIntervalCountCommand(intervalNumber));
                if (intervalNumber == 0)
                {
                    commands.Add(new SetWorkoutTypeCommand(WorkoutType.VariableInterval));
                }
                commands.Add(new SetIntervalTypeCommand(currentInterval.IntervalType.Value));
                WorkoutDetails? workoutDetails = GetWorkoutDetails(currentInterval);
                if (workoutDetails == null)
                {
                    _logger.LogError("An error occurred while extracting workout details. No workout has been set.");
                    return null;
                }
                atLeastOneIntervalWithUndefinedRest = atLeastOneIntervalWithUndefinedRest || !workoutDetails.Value.RequireRest;
                IEnumerable<ICommand>? intervalCommands = BuildInterval(currentInterval, workoutDetails.Value);
                if (intervalCommands == null)
                {
                    _logger.LogError("An error occurred while building the interval commands. No workout has been set.");
                    return null;
                }
                commands.AddRange(intervalCommands);
                commands.Add(new SetConfigureWorkoutCommand(WorkoutProgrammingMode.Enable));
            }
            if (atLeastOneIntervalWithUndefinedRest)
            {
                commands.AddRange(new ICommand[]
                {
                    new SetWorkoutTypeCommand(WorkoutType.VariableIntervalUndefinedRest),
                    new SetSplitDurationCommand(WorkoutDuration.Distance, 0)
                });
            }
            commands.Add(new SetScreenStateCommand(ScreenType.Workout, ScreenValueWorkout.PrepareToRowWorkout));
            return commands;
        }
private IEnumerable < ICommand > ? BuildVariableWorkout ( IEnumerable < Interval > intervals ) { IList < Interval > intervalList = new List < Interval > ( intervals ) ; if ( intervalList . Any ( i => i . IntervalType == null ) ) { _logger . LogError ( " " ) ; return null ; } if ( ! intervalList . Any ( ) ) { _logger . LogError ( " " ) ; return null ; } bool atLeastOneIntervalWithUndefinedRest = false ; List < ICommand > commands = new ( ) ; for ( int intervalNumber = 0 ; intervalNumber < intervalList . Count ; intervalNumber ++ ) { Interval currentInterval = intervalList [ intervalNumber ] ; if ( currentInterval . IntervalType == null ) { _logger . LogCritical ( " " ) ; return null ; } commands . Add ( new SetWorkoutIntervalCountCommand ( intervalNumber ) ) ; if ( intervalNumber == 0 ) { commands . Add ( new SetWorkoutTypeCommand ( WorkoutType . VariableInterval ) ) ; } commands . Add ( new SetIntervalTypeCommand ( currentInterval . IntervalType . Value ) ) ; WorkoutDetails ? workoutDetails = GetWorkoutDetails ( currentInterval ) ; if ( workoutDetails == null ) { _logger . LogError ( " " ) ; return null ; } atLeastOneIntervalWithUndefinedRest = atLeastOneIntervalWithUndefinedRest || ! workoutDetails . Value . RequireRest ; IEnumerable < ICommand > ? intervalCommands = BuildInterval ( currentInterval , workoutDetails . Value ) ; if ( intervalCommands == null ) { _logger . LogError ( " " ) ; return null ; } commands . AddRange ( intervalCommands ) ; commands . Add ( new SetConfigureWorkoutCommand ( WorkoutProgrammingMode . Enable ) ) ; } if ( atLeastOneIntervalWithUndefinedRest ) { commands . AddRange ( new ICommand [ ] { new SetWorkoutTypeCommand ( WorkoutType . VariableIntervalUndefinedRest ) , new SetSplitDurationCommand ( WorkoutDuration . Distance , 0 ) } ) ; } commands . Add ( new SetScreenStateCommand ( ScreenType . Workout , ScreenValueWorkout . PrepareToRowWorkout ) ) ; return commands ; }
Builds only the commands in a variable interval workout
Builds only the commands in a variable interval workout
// Setting the SplitDurationDistance to 0 is necessary when at least one undefined rest interval is configured
Enumerable of the commands
Enumerable of the commands
intervals
IEnumerable<Interval>
None