public void Deserialize_V15(Stream stream, DataVersion version) { Deserialize_V14(stream, version); // Check if we found the workout link. If we did deserialize the steps // list in a disposable one. If we can't find the workout, then we must // not deserialize the list so it can simply add the steps the the workout if (m_LinkedWorkout != null) { WorkoutStepsList tempStepsList = new WorkoutStepsList(ParentConcreteWorkout); tempStepsList.Deserialize(stream, version); } }
public List<IStep> DeserializeSteps(Stream stream) { List<IStep> deserializedSteps = new List<IStep>(); byte[] intBuffer = new byte[sizeof(Int32)]; Byte stepCount = (Byte)stream.ReadByte(); for (int i = 0; i < stepCount; i++) { IStep.StepType type; stream.Read(intBuffer, 0, sizeof(Int32)); type = (IStep.StepType)BitConverter.ToInt32(intBuffer, 0); if (type == IStep.StepType.Regular) { deserializedSteps.Add(new RegularStep(stream, Constants.CurrentVersion, ConcreteWorkout)); } else if (type == IStep.StepType.Repeat) { deserializedSteps.Add(new RepeatStep(stream, Constants.CurrentVersion, ConcreteWorkout)); } else { WorkoutLinkStep tempLink = new WorkoutLinkStep(stream, Constants.CurrentVersion, ConcreteWorkout); if (tempLink.LinkedWorkout != null) { deserializedSteps.Add(tempLink); } else { WorkoutStepsList linkSteps = new WorkoutStepsList(ConcreteWorkout); linkSteps.Deserialize(stream, Constants.CurrentVersion); deserializedSteps.AddRange(linkSteps); } } } // Now that we deserialized, paste in the current workout if (Steps.AddStepsToRoot(deserializedSteps)) { return deserializedSteps; } return null; }
public void Deserialize_V20(Stream stream, DataVersion version) { // Call base deserialization Deserialize(typeof(IStep), stream, version); byte[] intBuffer = new byte[sizeof(Int32)]; Int32 stepCount; stream.Read(intBuffer, 0, sizeof(Int32)); stepCount = BitConverter.ToInt32(intBuffer, 0); // In case the repeat was already registered on the workout ParentConcreteWorkout.Steps.RemoveSteps(StepsToRepeat, false); m_StepsToRepeat.Clear(); for (int i = 0; i < stepCount; ++i) { IStep.StepType type; stream.Read(intBuffer, 0, sizeof(Int32)); type = (IStep.StepType)BitConverter.ToInt32(intBuffer, 0); if (type == IStep.StepType.Regular) { m_StepsToRepeat.Add(new RegularStep(stream, version, ParentConcreteWorkout)); } else if (type == IStep.StepType.Link) { WorkoutLinkStep tempLink = new WorkoutLinkStep(stream, version, ParentConcreteWorkout); if (tempLink.LinkedWorkout != null) { m_StepsToRepeat.Add(tempLink); } else { WorkoutStepsList linkSteps = new WorkoutStepsList(ParentConcreteWorkout); linkSteps.Deserialize(stream, Constants.CurrentVersion); m_StepsToRepeat.AddRange(linkSteps); } } else { m_StepsToRepeat.Add(new RepeatStep(stream, version, ParentConcreteWorkout)); } } stream.Read(intBuffer, 0, sizeof(Int32)); IRepeatDuration.RepeatDurationType durationType = (IRepeatDuration.RepeatDurationType)(BitConverter.ToInt32(intBuffer, 0)); Duration = DurationFactory.Create(durationType, stream, version, this); }