コード例 #1
0
        public void TestTCXSerialization()
        {
            XmlDocument testDocument = new XmlDocument();
            XmlNode database;
            XmlAttribute attribute;
            Workout placeholderWorkout = new Workout("Test", PluginMain.GetApplication().Logbook.ActivityCategories[0]);
            RepeatStep placeholderStep = new RepeatStep(placeholderWorkout);

            // Setup document
            testDocument.AppendChild(testDocument.CreateXmlDeclaration("1.0", "UTF-8", "no"));
            database = testDocument.CreateNode(XmlNodeType.Element, "TrainingCenterDatabase", null);
            testDocument.AppendChild(database);
            attribute = testDocument.CreateAttribute("xmlns", "xsi", GarminFitnessPlugin.Constants.xmlns);
            attribute.Value = "http://www.w3.org/2001/XMLSchema-instance";
            database.Attributes.Append(attribute);

            // Repeat count
            RepeatCountDuration countDuration = new RepeatCountDuration(placeholderStep);
            placeholderStep.Duration = countDuration;
            countDuration.RepetitionCount = 4;
            countDuration.Serialize(database, "RepeatCountDuration1", testDocument);
            int durationPosition1 = testDocument.InnerXml.IndexOf(repeatCountDurationResult1);
            Assert.GreaterOrEqual(durationPosition1, 0, "Invalid repeat count duration serialization");
            countDuration.RepetitionCount = 10;
            countDuration.Serialize(database, "RepeatCountDuration2", testDocument);
            int durationPosition2 = testDocument.InnerXml.IndexOf(repeatCountDurationResult2);
            Assert.GreaterOrEqual(durationPosition2, 0, "Invalid repeat count duration serialization");
            Assert.Greater(durationPosition2, durationPosition1, "Repeat count durations serialization don't differ");

            // All other repeat durtions should not serialize in TCX
            try
            {
                RepeatUntilCaloriesDuration caloriesDuration = new RepeatUntilCaloriesDuration(placeholderStep);
                caloriesDuration.Serialize(database, "RepeatUntilCaloriesDuration", testDocument);
                Assert.Fail("Repeat until calories should not serialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilDistanceDuration distanceDuration = new RepeatUntilDistanceDuration(placeholderStep);
                distanceDuration.Serialize(database, "RepeatUntilDistanceDuration", testDocument);
                Assert.Fail("Repeat until distance should not serialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilHeartRateAboveDuration hrAboveDuration = new RepeatUntilHeartRateAboveDuration(placeholderStep);
                hrAboveDuration.Serialize(database, "RepeatUntilHRAboveDuration", testDocument);
                Assert.Fail("Repeat until HRAbove should not serialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilHeartRateBelowDuration hrBelowDuration = new RepeatUntilHeartRateBelowDuration(placeholderStep);
                hrBelowDuration.Serialize(database, "RepeatUntilHRBelowDuration", testDocument);
                Assert.Fail("Repeat until HRBelow should not serialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilPowerAboveDuration powerAboveDuration = new RepeatUntilPowerAboveDuration(placeholderStep);
                powerAboveDuration.Serialize(database, "RepeatUntilPowerAboveDuration", testDocument);
                Assert.Fail("Repeat until PowerAbove should not serialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilPowerBelowDuration powerBelowDuration = new RepeatUntilPowerBelowDuration(placeholderStep);
                powerBelowDuration.Serialize(database, "RepeatUntilPowerBelowDuration", testDocument);
                Assert.Fail("Repeat until PowerBelow should not serialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilTimeDuration timeDuration = new RepeatUntilTimeDuration(placeholderStep);
                timeDuration.Serialize(database, "RepeatUntilTimeDuration", testDocument);
                Assert.Fail("Repeat until time should not serialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilCaloriesDuration caloriesDuration = new RepeatUntilCaloriesDuration(placeholderStep);
                caloriesDuration.Serialize(database, "RepeatUntilCaloriesDuration", testDocument);
                Assert.Fail("Repeat until calories should not serialize");
            }
            catch (NotSupportedException)
            {
            }
        }
コード例 #2
0
        public void TestFITSerialization()
        {
            Workout placeholderWorkout = new Workout("Test", PluginMain.GetApplication().Logbook.ActivityCategories[0]);
            RepeatStep placeholderStep = new RepeatStep(placeholderWorkout);
            FITMessage serializedMessage = new FITMessage(FITGlobalMessageIds.WorkoutStep);
            FITMessageField messageField;

            // Repeat count
            RepeatCountDuration repeatDuration = new RepeatCountDuration(placeholderStep);
            repeatDuration.RepetitionCount = 3;
            repeatDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat count duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatCount, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat count duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat count duration");
            Assert.AreEqual(3, messageField.GetUInt32(), "Invalid target value in field for repeat count duration");
            serializedMessage.Clear();

            repeatDuration.RepetitionCount = 7;
            repeatDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat count duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatCount, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat count duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat count duration");
            Assert.AreEqual(7, messageField.GetUInt32(), "Invalid target value in field for repeat count duration");
            serializedMessage.Clear();

            // Repeat until calories
            RepeatUntilCaloriesDuration caloriesDuration = new RepeatUntilCaloriesDuration(placeholderStep);
            caloriesDuration.CaloriesToSpend = 550;
            caloriesDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until calories duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilCalories, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until calories duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until calories duration");
            Assert.AreEqual(550, messageField.GetUInt32(), "Invalid target value in field for repeat until calories duration");
            serializedMessage.Clear();

            caloriesDuration.CaloriesToSpend = 750;
            caloriesDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until calories duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilCalories, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until calories duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until calories duration");
            Assert.AreEqual(750, messageField.GetUInt32(), "Invalid target value in field for repeat until calories duration");
            serializedMessage.Clear();

            // Repeat until distance
            RepeatUntilDistanceDuration distanceDuration = new RepeatUntilDistanceDuration(1, Length.Units.Kilometer, placeholderStep);
            distanceDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until distance duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilDistance, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until distance duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until distance duration");
            Assert.AreEqual(100000, messageField.GetUInt32(), "Invalid target value in field for repeat until distance duration");
            serializedMessage.Clear();

            distanceDuration = new RepeatUntilDistanceDuration(1, Length.Units.Mile, placeholderStep);
            distanceDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until distance duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilDistance, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until distance duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until distance duration");
            Assert.AreEqual(160934, messageField.GetUInt32(), "Invalid target value in field for repeat until distance duration");
            serializedMessage.Clear();

            // Repeat until HRAbove
            RepeatUntilHeartRateAboveDuration hrAboveDuration = new RepeatUntilHeartRateAboveDuration(placeholderStep);
            hrAboveDuration.IsPercentageMaxHeartRate = false;
            hrAboveDuration.MaxHeartRate = 160;
            hrAboveDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until HRAbove duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilHeartRateGreaterThan, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until HRAbove duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until HRAbove duration");
            Assert.AreEqual(260, messageField.GetUInt32(), "Invalid target value in field for repeat until HRAbove duration");
            serializedMessage.Clear();

            hrAboveDuration.IsPercentageMaxHeartRate = true;
            hrAboveDuration.MaxHeartRate = 80;
            hrAboveDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until HRAbove duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilHeartRateGreaterThan, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until HRAbove duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until HRAbove duration");
            Assert.AreEqual(80, messageField.GetUInt32(), "Invalid target value in field for repeat until HRAbove duration");
            serializedMessage.Clear();

            // Repeat until HRBelow
            RepeatUntilHeartRateBelowDuration hrBelowDuration = new RepeatUntilHeartRateBelowDuration(placeholderStep);
            hrBelowDuration.IsPercentageMaxHeartRate = false;
            hrBelowDuration.MinHeartRate = 150;
            hrBelowDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until HRBelow duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilHeartRateLessThan, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until HRBelow duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until HRBelow duration");
            Assert.AreEqual(250, messageField.GetUInt32(), "Invalid target value in field for repeat until HRBelow duration");
            serializedMessage.Clear();

            hrBelowDuration.IsPercentageMaxHeartRate = true;
            hrBelowDuration.MinHeartRate = 70;
            hrBelowDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until HRBelow duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilHeartRateLessThan, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until HRBelow duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until HRBelow duration");
            Assert.AreEqual(70, messageField.GetUInt32(), "Invalid target value in field for repeat until HRBelow duration");
            serializedMessage.Clear();

            // Repeat until PowerAbove
            RepeatUntilPowerAboveDuration powerAboveDuration = new RepeatUntilPowerAboveDuration(placeholderStep);
            powerAboveDuration.IsPercentFTP = false;
            powerAboveDuration.MaxPower = 250;
            powerAboveDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until PowerAbove duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilPowerGreaterThan, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until PowerAbove duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until PowerAbove duration");
            Assert.AreEqual(1250, messageField.GetUInt32(), "Invalid target value in field for repeat until PowerAbove duration");
            serializedMessage.Clear();

            powerAboveDuration.IsPercentFTP = true;
            powerAboveDuration.MaxPower = 100;
            powerAboveDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until PowerAbove duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilPowerGreaterThan, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until PowerAbove duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until PowerAbove duration");
            Assert.AreEqual(100, messageField.GetUInt32(), "Invalid target value in field for repeat until PowerAbove duration");
            serializedMessage.Clear();

            // Repeat until HRBelow
            RepeatUntilPowerBelowDuration powerBelowDuration = new RepeatUntilPowerBelowDuration(placeholderStep);
            powerBelowDuration.IsPercentFTP = false;
            powerBelowDuration.MinPower = 150;
            powerBelowDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until PowerBelow duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilPowerLessThan, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until PowerBelow duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until PowerBelow duration");
            Assert.AreEqual(1150, messageField.GetUInt32(), "Invalid target value in field for repeat until PowerBelow duration");
            serializedMessage.Clear();

            powerBelowDuration.IsPercentFTP = true;
            powerBelowDuration.MinPower = 270;
            powerBelowDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until PowerBelow duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilPowerLessThan, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until PowerBelow duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until PowerBelow duration");
            Assert.AreEqual(270, messageField.GetUInt32(), "Invalid target value in field for repeat until PowerBelow duration");
            serializedMessage.Clear();

            // Repeat until time
            RepeatUntilTimeDuration timeDuration = new RepeatUntilTimeDuration(placeholderStep);
            timeDuration.TimeInSeconds = 600;
            timeDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until time duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilTime, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until time duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until time duration");
            Assert.AreEqual(600000, messageField.GetUInt32(), "Invalid target value in field for repeat until time duration");
            serializedMessage.Clear();

            timeDuration.TimeInSeconds = 350;
            timeDuration.FillFITStepMessage(serializedMessage);
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.DurationType);
            Assert.IsNotNull(messageField, "Duration type field not serialized for repeat until time duration");
            Assert.AreEqual(FITWorkoutStepDurationTypes.RepeatUntilTime, (FITWorkoutStepDurationTypes)messageField.GetEnum(), "Invalid duration type in field for repeat until time duration");
            messageField = serializedMessage.GetField((Byte)FITWorkoutStepFieldIds.TargetValue);
            Assert.IsNotNull(messageField, "Target value field not serialized for repeat until time duration");
            Assert.AreEqual(350000, messageField.GetUInt32(), "Invalid target value in field for repeat until time duration");
            serializedMessage.Clear();
        }
コード例 #3
0
        public void TestTCXDeserialization()
        {
            XmlDocument testDocument = new XmlDocument();
            XmlNode readNode;
            XmlNode database;
            Workout placeholderWorkout = new Workout("Test", PluginMain.GetApplication().Logbook.ActivityCategories[0]);
            RepeatStep placeholderStep = new RepeatStep(placeholderWorkout);

            // Setup document
            testDocument.AppendChild(testDocument.CreateXmlDeclaration("1.0", "UTF-8", "no"));
            database = testDocument.CreateNode(XmlNodeType.Element, "TrainingCenterDatabase", null);
            testDocument.AppendChild(database);
            XmlAttribute attribute = testDocument.CreateAttribute("xmlns", "xsi", GarminFitnessPlugin.Constants.xmlns);
            attribute.Value = "http://www.w3.org/2001/XMLSchema-instance";
            database.Attributes.Append(attribute);
            readNode = testDocument.CreateElement("TestNode");
            database.AppendChild(readNode);

            // Repeat count
            readNode.InnerXml = repeatCountDurationResult1;
            RepeatCountDuration countDuration = new RepeatCountDuration(placeholderStep);
            countDuration.Deserialize(readNode.FirstChild);
            Assert.AreEqual(4, countDuration.RepetitionCount, "Invalid number of repetitions deserialized");

            readNode.InnerXml = repeatCountDurationResult2;
            countDuration = new RepeatCountDuration(placeholderStep);
            countDuration.Deserialize(readNode.FirstChild);
            Assert.AreEqual(10, countDuration.RepetitionCount, "Invalid number of repetitions deserialized");

            // All other repeat durtions should not deserialize from TCX
            try
            {
                RepeatUntilCaloriesDuration caloriesDuration = new RepeatUntilCaloriesDuration(placeholderStep);
                caloriesDuration.Deserialize(readNode.FirstChild);
                Assert.Fail("Repeat until calories should not deserialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilDistanceDuration distanceDuration = new RepeatUntilDistanceDuration(placeholderStep);
                distanceDuration.Deserialize(readNode.FirstChild);
                Assert.Fail("Repeat until distance should not deserialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilHeartRateAboveDuration hrAboveDuration = new RepeatUntilHeartRateAboveDuration(placeholderStep);
                hrAboveDuration.Deserialize(readNode.FirstChild);
                Assert.Fail("Repeat until HRAbove should not deserialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilHeartRateBelowDuration hrBelowDuration = new RepeatUntilHeartRateBelowDuration(placeholderStep);
                hrBelowDuration.Deserialize(readNode.FirstChild);
                Assert.Fail("Repeat until HRBelow should not deserialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilPowerAboveDuration powerAboveDuration = new RepeatUntilPowerAboveDuration(placeholderStep);
                powerAboveDuration.Deserialize(readNode.FirstChild);
                Assert.Fail("Repeat until PowerAbove should not deserialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilPowerBelowDuration powerBelowDuration = new RepeatUntilPowerBelowDuration(placeholderStep);
                powerBelowDuration.Deserialize(readNode.FirstChild);
                Assert.Fail("Repeat until PowerBelow should not deserialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilTimeDuration timeDuration = new RepeatUntilTimeDuration(placeholderStep);
                timeDuration.Deserialize(readNode.FirstChild);
                Assert.Fail("Repeat until time should not deserialize");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RepeatUntilCaloriesDuration caloriesDuration = new RepeatUntilCaloriesDuration(placeholderStep);
                caloriesDuration.Deserialize(readNode.FirstChild);
                Assert.Fail("Repeat until calories should not deserialize");
            }
            catch (NotSupportedException)
            {
            }
        }
コード例 #4
0
        public static IRepeatDuration Create(IRepeatDuration.RepeatDurationType type, RepeatStep parent)
        {
            IRepeatDuration newDuration;

            switch (type)
            {
                case IRepeatDuration.RepeatDurationType.RepeatCount:
                    {
                        newDuration = new RepeatCountDuration(parent);
                        break;
                    }
                case IRepeatDuration.RepeatDurationType.RepeatUntilTime:
                    {
                        newDuration = new RepeatUntilTimeDuration(parent);
                        break;
                    }
                case IRepeatDuration.RepeatDurationType.RepeatUntilDistance:
                    {
                        newDuration = new RepeatUntilDistanceDuration(parent);
                        break;
                    }
                case IRepeatDuration.RepeatDurationType.RepeatUntilHeartRateAbove:
                    {
                        newDuration = new RepeatUntilHeartRateAboveDuration(parent);
                        break;
                    }
                case IRepeatDuration.RepeatDurationType.RepeatUntilHeartRateBelow:
                    {
                        newDuration = new RepeatUntilHeartRateBelowDuration(parent);
                        break;
                    }
                case IRepeatDuration.RepeatDurationType.RepeatUntilCalories:
                    {
                        newDuration = new RepeatUntilCaloriesDuration(parent);
                        break;
                    }
                case IRepeatDuration.RepeatDurationType.RepeatUntilPowerAbove:
                    {
                        newDuration = new RepeatUntilPowerAboveDuration(parent);
                        break;
                    }
                case IRepeatDuration.RepeatDurationType.RepeatUntilPowerBelow:
                    {
                        newDuration = new RepeatUntilPowerBelowDuration(parent);
                        break;
                    }
                default:
                    {
                        Debug.Assert(false);
                        newDuration = null;
                        break;
                    }
            }

            parent.Duration = newDuration;

            return newDuration;
        }