Exemple #1
0
        private void WriteTrackOrRoute(GpxTrackOrRoute trackOrRoute)
        {
            if (!string.IsNullOrEmpty(trackOrRoute.Name))
            {
                Writer_.WriteElementString("name", trackOrRoute.Name);
            }
            if (!string.IsNullOrEmpty(trackOrRoute.Comment))
            {
                Writer_.WriteElementString("cmt", trackOrRoute.Comment);
            }
            if (!string.IsNullOrEmpty(trackOrRoute.Description))
            {
                Writer_.WriteElementString("desc", trackOrRoute.Description);
            }
            if (!string.IsNullOrEmpty(trackOrRoute.Source))
            {
                Writer_.WriteElementString("src", trackOrRoute.Source);
            }

            foreach (GpxLink link in trackOrRoute.Links)
            {
                WriteLink("link", link);
            }

            if (trackOrRoute.Number != default(int))
            {
                Writer_.WriteElementString("number", trackOrRoute.Number.ToString(CultureInfo.InvariantCulture));
            }
            if (!string.IsNullOrEmpty(trackOrRoute.Type))
            {
                Writer_.WriteElementString("type", trackOrRoute.Type);
            }

            if (trackOrRoute.HasExtensions)
            {
                Writer_.WriteStartElement("extensions");
                Writer_.WriteStartElement("RouteExtension", GARMIN_EXTENSIONS_NAMESPACE);

                Writer_.WriteElementString("DisplayColor", GARMIN_EXTENSIONS_NAMESPACE, trackOrRoute.DisplayColor.ToString());

                Writer_.WriteEndElement();
                Writer_.WriteEndElement();
            }
        }
Exemple #2
0
        private void ReadGarminTrackOrRouteExtensions(XmlReader reader, GpxTrackOrRoute trackOrRoute)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            string elementName = reader.Name;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (reader.LocalName)
                    {
                    case "DisplayColor":
                        trackOrRoute.DisplayColor = (GpxColor)Enum.Parse(typeof(GpxColor), ReadContentAsString(reader), false);
                        break;

                    case "IsAutoNamed":
                    case "Extensions":
                        SkipElement(reader);
                        break;

                    default:
                        throw new FormatException(reader.Name);
                    }

                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name != elementName)
                    {
                        throw new FormatException(reader.Name);
                    }
                    return;
                }
            }

            throw new FormatException(elementName);
        }