Esempio n. 1
0
        private void WriteTrackOrRoute(GpxTrackOrRoute trackOrRoute)
        {
            if (trackOrRoute.Name != null)
            {
                Writer_.WriteElementString("name", trackOrRoute.Name);
            }
            if (trackOrRoute.Comment != null)
            {
                Writer_.WriteElementString("cmt", trackOrRoute.Comment);
            }
            if (trackOrRoute.Description != null)
            {
                Writer_.WriteElementString("desc", trackOrRoute.Description);
            }
            if (trackOrRoute.Source != null)
            {
                Writer_.WriteElementString("src", trackOrRoute.Source);
            }

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

            if (trackOrRoute.Number != null)
            {
                Writer_.WriteElementString("number", trackOrRoute.Number.Value.ToString(CultureInfo.InvariantCulture));
            }
            if (trackOrRoute.Type != null)
            {
                Writer_.WriteElementString("type", trackOrRoute.Type);
            }

            if (trackOrRoute.HasExtensions)
            {
                Writer_.WriteStartElement("extensions");
                Writer_.WriteStartElement(trackOrRoute is GpxTrack ? "TrackExtension" : "RouteExtension", GpxNamespaces.GARMIN_EXTENSIONS_NAMESPACE);

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

                Writer_.WriteEndElement();
                Writer_.WriteEndElement();
            }
        }
Esempio n. 2
0
        private void ReadGarminTrackOrRouteExtensions(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),
                                                                         reader.ReadElementContentAsString(), false);
                        break;

                    default:
                        reader.SkipElement();
                        break;
                    }

                    break;

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

            throw new FormatException(elementName);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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();
            }
        }