예제 #1
0
        public void SerializeData(Stream stream)
        {
            switch (m_Type)
            {
                case DataType.Enum:
                case DataType.UInt8:
                case DataType.UInt8z:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessByteRange data = new GarminFitnessByteRange(m_ByteValues[i]);

                            data.Serialize(stream);
                        }
                        break;
                    }
                case DataType.SInt8:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessSByteRange data = new GarminFitnessSByteRange(m_SByteValues[i]);

                            data.Serialize(stream);
                        }
                        break;
                    }
                case DataType.UInt16:
                case DataType.UInt16z:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessUInt16Range data = new GarminFitnessUInt16Range(m_UInt16Values[i]);

                            data.Serialize(stream);
                        }
                        break;
                    }
                case DataType.SInt16:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessInt16Range data = new GarminFitnessInt16Range(m_Int16Values[i]);

                            data.Serialize(stream);
                        }
                        break;
                    }
                case DataType.UInt32:
                case DataType.UInt32z:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessUInt32Range data = new GarminFitnessUInt32Range(m_UInt32Values[i]);

                            data.Serialize(stream);
                        }
                        break;
                    }
                case DataType.SInt32:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessInt32Range data = new GarminFitnessInt32Range(m_Int32Values[i]);

                            data.Serialize(stream);
                        }
                        break;
                    }
                case DataType.Float32:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessFloatRange data = new GarminFitnessFloatRange(m_SingleValues[i]);

                            data.Serialize(stream);
                        }
                        break;
                    }
                case DataType.Float64:
                    {
                        for (int i = 0; i < ArraySize; ++i)
                        {
                            GarminFitnessDoubleRange data = new GarminFitnessDoubleRange(m_DoubleValues[i]);

                            data.Serialize(stream);
                        }
                        break;
                    }
                case DataType.String:
                    {
                        Byte[] valueStored = new Byte[FieldSize];

                        for(int i = 0; i < valueStored.Length; ++i)
                        {
                            if (i < m_ByteValues.Length)
                            {
                                valueStored[i] = m_ByteValues[i];
                            }
                            else
                            {
                                valueStored[i] = 0;
                            }
                        }
                        stream.Write(valueStored, 0, valueStored.Length);
                        break;
                    }
                case DataType.Byte:
                    {
                        stream.Write(m_ByteValues, 0, m_ByteValues.Length);
                        break;
                    }
                default:
                    {
                        Debug.Assert(false);
                        break;
                    }
            }
        }
        private void WeightTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            double enteredValue = 0;

            e.Cancel = !double.TryParse(WeightTextBox.Text, out enteredValue);

            if (!e.Cancel)
            {
                GarminFitnessDoubleRange valueInKilos = new GarminFitnessDoubleRange(0, Constants.MinWeight, Constants.MaxWeightInKg);

                e.Cancel = !valueInKilos.IsInRange(Weight.Convert(enteredValue, PluginMain.GetApplication().SystemPreferences.WeightUnits, Weight.Units.Kilogram));
            }

            if (e.Cancel)
            {
                double minValue = Weight.Convert(Constants.MinWeight, Weight.Units.Kilogram, PluginMain.GetApplication().SystemPreferences.WeightUnits);
                double maxValue = Weight.Convert(Constants.MaxWeightInKg, Weight.Units.Kilogram, PluginMain.GetApplication().SystemPreferences.WeightUnits);

                MessageBox.Show(String.Format(TextResourceManager.DoubleRangeValidationText, minValue, maxValue),
                                TextResourceManager.ValueValidationTitleText, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                System.Media.SystemSounds.Asterisk.Play();

                // Reset old valid value
                WeightTextBox.Text = GarminProfileManager.Instance.UserProfile.GetWeightInUnits(PluginMain.GetApplication().SystemPreferences.WeightUnits).ToString("0.0");
            }
        }
        private void OdometerTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            double enteredValue;

            e.Cancel = !double.TryParse(OdometerTextBox.Text, out enteredValue);

            if(!e.Cancel)
            {
                GarminFitnessDoubleRange valueInMeters = new GarminFitnessDoubleRange(0, Constants.MinOdometer, Constants.MaxOdometer);

                e.Cancel = !valueInMeters.IsInRange(Length.Convert(enteredValue, m_CurrentProfile.BaseSpeedUnit, Length.Units.Kilometer));
            }

            if (e.Cancel)
            {
                double minValue = Length.Convert(Constants.MinOdometer, Length.Units.Kilometer, m_CurrentProfile.BaseSpeedUnit);
                double maxValue = Length.Convert(Constants.MaxOdometer, Length.Units.Kilometer, m_CurrentProfile.BaseSpeedUnit);

                MessageBox.Show(String.Format(TextResourceManager.DoubleRangeValidationText, minValue, maxValue),
                                TextResourceManager.ValueValidationTitleText,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                System.Media.SystemSounds.Asterisk.Play();

                // Reset old valid value
                OdometerTextBox.Text = Length.Convert(m_CurrentBikeProfile.OdometerInMeters, Length.Units.Meter, m_CurrentProfile.BaseSpeedUnit).ToString("0.0");
            }
        }
예제 #4
0
        public void Serialize(XmlNode parentNode, String nodeName, XmlDocument document)
        {
            XmlNode bikeNode, wheelInfoChild;

            bikeNode = document.CreateElement(nodeName);
            parentNode.AppendChild(bikeNode);

            m_HasCadenceSensor.SerializeAttribute(bikeNode, Constants.HasCadenceTCXString, document);

            m_HasPowerSensor.SerializeAttribute(bikeNode, Constants.HasPowerTCXString, document);

            m_Name.Serialize(bikeNode, "Name", document);

            m_OdometerInMeters.Serialize(bikeNode, Constants.OdometerTCXString, document);

            GarminFitnessDoubleRange weightInKg = new GarminFitnessDoubleRange(Weight.Convert(m_WeightInPounds, Weight.Units.Pound, Weight.Units.Kilogram));
            weightInKg.Serialize(bikeNode, Constants.WeightTCXString, document);

            // Wheel info node
            wheelInfoChild = document.CreateElement(Constants.WheelSizeTCXString);
            bikeNode.AppendChild(wheelInfoChild);

            m_AutoWheelSize.SerializeAttribute(wheelInfoChild, Constants.AutoWheelSizeTCXString, document);

            m_WheelSize.Serialize(wheelInfoChild, Constants.SizeMillimetersTCXString, document);
        }
        public void Deserialize_V8(Stream stream, DataVersion version)
        {
            m_MaxHeartRate.Deserialize(stream, version);

            GarminFitnessDoubleRange gearWeightinKg = new GarminFitnessDoubleRange(Weight.Convert(m_GearWeightInPounds, Weight.Units.Pound, Weight.Units.Kilogram));

            gearWeightinKg.Deserialize(stream, version);
            SetGearWeightInUnits(gearWeightinKg, Weight.Units.Kilogram);

            GarminFitnessBool HRIsInPercentMax = new GarminFitnessBool(true);
            HRIsInPercentMax.Deserialize(stream, version);
            HRZonesReferential = HRIsInPercentMax ? HRReferential.HRReferential_PercentMax : HRReferential.HRReferential_BPM;

            for (int i = 0; i < m_HeartRateZones.Count; ++i)
            {
                m_HeartRateZones[i].Lower.Deserialize(stream, version);

                m_HeartRateZones[i].Upper.Deserialize(stream, version);
            }

            m_SpeedIsInPace.Deserialize(stream, version);

            GarminFitnessDoubleRange lowLimit = new GarminFitnessDoubleRange(Constants.MinSpeedMetric, Constants.MinSpeedMetric, Constants.MaxSpeedMetric);
            GarminFitnessDoubleRange highLimit = new GarminFitnessDoubleRange(Constants.MinSpeedMetric, Constants.MinSpeedMetric, Constants.MaxSpeedMetric);
            for (int i = 0; i < m_SpeedZones.Count; ++i)
            {
                lowLimit.Deserialize(stream, version);
                m_SpeedZones[i].Low = Length.Convert(lowLimit, Length.Units.Kilometer, Length.Units.Meter) / Constants.SecondsPerHour;

                highLimit.Deserialize(stream, version);
                m_SpeedZones[i].High = Length.Convert(highLimit, Length.Units.Kilometer, Length.Units.Meter) / Constants.SecondsPerHour;

                m_SpeedZones[i].InternalName.Deserialize(stream, version);
            }
        }
        public virtual void Serialize(XmlNode parentNode, String nodeName, XmlDocument document)
        {
            XmlAttribute attributeNode;
            XmlNode activityNode, currentChild;

            activityNode = document.CreateElement(nodeName);
            parentNode.AppendChild(activityNode);

            attributeNode = document.CreateAttribute("Sport");
            attributeNode.Value = Constants.GarminCategoryTCXString[(int)Category];
            activityNode.Attributes.Append(attributeNode);

            attributeNode = document.CreateAttribute(Constants.XsiTypeTCXString, Constants.xsins);
            attributeNode.Value = "ProfileActivity_t";
            activityNode.Attributes.Append(attributeNode);

            // Maximum heart rate
            currentChild = document.CreateElement(Constants.MaxHRBPMTCXString);
            activityNode.AppendChild(currentChild);
            m_MaxHeartRate.Serialize(currentChild, Constants.ValueTCXString, document);

            // Resting HR
            currentChild = document.CreateElement(Constants.RestHRBPMTCXString);
            activityNode.AppendChild(currentChild);
            GarminProfileManager.Instance.UserProfile.InternalRestingHeartRate.Serialize(currentChild, Constants.ValueTCXString, document);

            GarminFitnessDoubleRange gearWeightinKg = new GarminFitnessDoubleRange(Weight.Convert(m_GearWeightInPounds, Weight.Units.Pound, Weight.Units.Kilogram));

            gearWeightinKg.Serialize(activityNode, Constants.GearWeightTCXString, document);

            // HR zones
            for (int i = 0; i < Constants.GarminHRZoneCount; ++i)
            {
                currentChild = document.CreateElement(Constants.HeartRateZonesTCXString);
                activityNode.AppendChild(currentChild);

                // Number
                XmlNode numberNode = document.CreateElement("Number");
                numberNode.AppendChild(document.CreateTextNode((i + 1).ToString()));
                currentChild.AppendChild(numberNode);

                // View as BPM or % max
                GarminFitnessBool HRIsInPercentMax = new GarminFitnessBool(HRZonesReferential != HRReferential.HRReferential_BPM,
                                                                           Constants.PercentMaxTCXString,
                                                                           Constants.BPMTCXString);
                HRIsInPercentMax.Serialize(currentChild, Constants.ViewAsTCXString, document);

                // Low
                GarminFitnessByteRange lowLimit = new GarminFitnessByteRange((Byte)(m_HeartRateZones[i].Lower * MaximumHeartRate));
                XmlNode low = document.CreateElement(Constants.LowTCXString);
                currentChild.AppendChild(low);
                lowLimit.Serialize(low, Constants.ValueTCXString, document);

                // High
                GarminFitnessByteRange highLimit = new GarminFitnessByteRange((Byte)(m_HeartRateZones[i].Upper * MaximumHeartRate));
                XmlNode high = document.CreateElement(Constants.HighTCXString);
                currentChild.AppendChild(high);
                highLimit.Serialize(high, Constants.ValueTCXString, document);
            }

            // Speed zones
            for (int i = 0; i < Constants.GarminSpeedZoneCount; ++i)
            {
                currentChild = document.CreateElement(Constants.SpeedZonesTCXString);
                activityNode.AppendChild(currentChild);

                // Number
                XmlNode numberNode = document.CreateElement("Number");
                numberNode.AppendChild(document.CreateTextNode((i + 1).ToString()));
                currentChild.AppendChild(numberNode);

                // Name
                m_SpeedZones[i].InternalName.Serialize(currentChild, "Name", document);

                XmlNode valueChild = document.CreateElement(Constants.ValueTCXString);
                currentChild.AppendChild(valueChild);

                // View as pace or speed
                m_SpeedIsInPace.Serialize(valueChild, Constants.ViewAsTCXString, document);

                // Low
                m_SpeedZones[i].InternalLow.Serialize(valueChild, Constants.LowInMeterPerSecTCXString, document);

                // High
                m_SpeedZones[i].InternalHigh.Serialize(valueChild, Constants.HighInMeterPerSecTCXString, document);
            }
        }
        public void Deserialize_V10(Stream stream, DataVersion version)
        {
            m_MaxHeartRate.Deserialize(stream, version);

            GarminFitnessDoubleRange gearWeightinKg = new GarminFitnessDoubleRange(Weight.Convert(m_GearWeightInPounds, Weight.Units.Pound, Weight.Units.Kilogram));

            gearWeightinKg.Deserialize(stream, version);
            SetGearWeightInUnits(gearWeightinKg, Weight.Units.Kilogram);

            GarminFitnessBool HRIsInPercentMax = new GarminFitnessBool(true);
            HRIsInPercentMax.Deserialize(stream, version);
            HRZonesReferential = HRIsInPercentMax ? HRReferential.HRReferential_PercentMax : HRReferential.HRReferential_BPM;

            for (int i = 0; i < m_HeartRateZones.Count; ++i)
            {
                m_HeartRateZones[i].Lower.Deserialize(stream, version);

                m_HeartRateZones[i].Upper.Deserialize(stream, version);
            }

            m_SpeedIsInPace.Deserialize(stream, version);

            for (int i = 0; i < m_SpeedZones.Count; ++i)
            {
                m_SpeedZones[i].InternalLow.Deserialize(stream, version);

                m_SpeedZones[i].InternalHigh.Deserialize(stream, version);

                m_SpeedZones[i].InternalName.Deserialize(stream, version);
            }
        }
        public virtual void Deserialize(XmlNode parentNode)
        {
            bool weightRead = false;
            int HRZonesRead = 0;
            int speedZonesRead = 0;

            ReadMaxHR(parentNode);

            for (int i = 0; i < parentNode.ChildNodes.Count; ++i)
            {
                XmlNode currentChild = parentNode.ChildNodes[i];

                if (currentChild.Name == Constants.RestHRBPMTCXString &&
                    currentChild.ChildNodes.Count == 1 &&
                    currentChild.FirstChild.Name == Constants.ValueTCXString)
                {
                    GarminProfileManager.Instance.UserProfile.InternalRestingHeartRate.Deserialize(currentChild.FirstChild);
                }
                else if (currentChild.Name == Constants.GearWeightTCXString)
                {
                    GarminFitnessDoubleRange gearWeightinKg = new GarminFitnessDoubleRange(0);

                    gearWeightinKg.Deserialize(currentChild);
                    SetGearWeightInUnits(gearWeightinKg, Weight.Units.Kilogram);
                    weightRead = true;
                }
                else if (currentChild.Name == Constants.HeartRateZonesTCXString)
                {
                    int zoneIndex = PeekZoneNumber(currentChild);

                    if (zoneIndex != -1)
                    {
                        ReadHRZone(zoneIndex, currentChild);
                            HRZonesRead++;
                    }
                }
                else if (currentChild.Name == Constants.SpeedZonesTCXString)
                {
                    int zoneIndex = PeekZoneNumber(currentChild);

                    if (zoneIndex != -1)
                    {
                        ReadSpeedZone(zoneIndex, currentChild);
                        speedZonesRead++;
                    }
                }
            }

            // Check if all was read successfully
            if (!weightRead ||
                HRZonesRead != Constants.GarminHRZoneCount ||
                speedZonesRead != Constants.GarminSpeedZoneCount)
            {
                throw new GarminFitnessXmlDeserializationException("Missing information in activity profile XML node", parentNode);
            }
        }
        private void ReadSpeedZone(int index, XmlNode parentNode)
        {
            Debug.Assert(index >= 0 && index < Constants.GarminSpeedZoneCount);

            bool nameRead = false;
            bool viewAsRead = false;
            bool lowRead = false;
            bool highRead = false;
            GarminFitnessDoubleRange lowLimit = new GarminFitnessDoubleRange(0);
            GarminFitnessDoubleRange highLimit = new GarminFitnessDoubleRange(0);

            for (int i = 0; i < parentNode.ChildNodes.Count; ++i)
            {
                XmlNode currentChild = parentNode.ChildNodes[i];

                if (currentChild.Name == "Name")
                {
                    m_SpeedZones[index].InternalName.Deserialize(currentChild);
                    nameRead = true;
                }
                else if (currentChild.Name == Constants.ValueTCXString)
                {
                    XmlNode valueNode = currentChild;

                    for (int j = 0; j < valueNode.ChildNodes.Count; ++j)
                    {
                        XmlNode valueChild = valueNode.ChildNodes[j];

                        if (valueChild.Name == Constants.ViewAsTCXString)
                        {
                            m_SpeedIsInPace.Deserialize(valueChild);
                            viewAsRead = true;
                        }
                        else if (valueChild.Name == Constants.LowInMeterPerSecTCXString)
                        {
                            lowLimit.Deserialize(valueChild);
                            lowRead = true;
                        }
                        else if (valueChild.Name == Constants.HighInMeterPerSecTCXString)
                        {
                            highLimit.Deserialize(valueChild);
                            highRead = true;
                        }
                    }
                }
            }

            // Check if all was read successfully
            if (!nameRead || !viewAsRead || !lowRead || !highRead)
            {
                throw new GarminFitnessXmlDeserializationException("Missing information in activity profile XML node", parentNode);
            }

            m_SpeedZones[index].Low = Math.Min(lowLimit, highLimit);
            m_SpeedZones[index].High = Math.Max(lowLimit, highLimit);
        }
예제 #10
0
        public override void Serialize(XmlNode parentNode, String nodeName, XmlDocument document)
        {
            base.Serialize(parentNode, nodeName, document);

            // This node was added by our parent...
            parentNode = parentNode.LastChild;

            XmlAttribute attribute;

            // Type
            attribute = document.CreateAttribute(Constants.XsiTypeTCXString, Constants.xsins);
            attribute.Value = Constants.SpeedRangeZoneTCXString[1];
            parentNode.Attributes.Append(attribute);

            // View as
            GarminFitnessBool viewAs = new GarminFitnessBool(ViewAsPace, Constants.SpeedOrPaceTCXString[0], Constants.SpeedOrPaceTCXString[1]);
            viewAs.Serialize(parentNode, Constants.ViewAsTCXString, document);

            // Low
            GarminFitnessDoubleRange lowInMetersPerSecond = new GarminFitnessDoubleRange(Utils.Clamp(Zone.Low, Constants.MinSpeedMetersPerSecond, Constants.MaxSpeedMetersPerSecond));
            lowInMetersPerSecond.Serialize(parentNode, Constants.LowInMeterPerSecTCXString, document);

            // High
            GarminFitnessDoubleRange highInMetersPerSecond = new GarminFitnessDoubleRange(Utils.Clamp(Zone.High, Constants.MinSpeedMetersPerSecond, Constants.MaxSpeedMetersPerSecond));
            highInMetersPerSecond.Serialize(parentNode, Constants.HighInMeterPerSecTCXString, document);

            // Extension
            Utils.SerializeSTZoneInfoXML(BaseTarget.ParentStep,
                                         BaseTarget.ParentStep.ParentConcreteWorkout.Category.SpeedZone,
                                         Zone, document);
        }
예제 #11
0
        public override void Serialize(XmlNode parentNode, String nodeName, XmlDocument document)
        {
            base.Serialize(parentNode, nodeName, document);

            CultureInfo culture = new CultureInfo("en-us");

            // Low
            GarminFitnessDoubleRange low = new GarminFitnessDoubleRange(Zone.Low);
            low.Serialize(parentNode, "Low", document);

            // High
            GarminFitnessDoubleRange high = new GarminFitnessDoubleRange((Byte)Math.Min(Constants.MaxCadence, Zone.High));
            high.Serialize(parentNode, "High", document);

            // Extension
            Utils.SerializeSTZoneInfoXML(BaseTarget.ParentStep,
                                         Options.Instance.CadenceZoneCategory,
                                         Zone, document);
        }