Ejemplo n.º 1
0
        private static void CreateXmlGpx(string fileName, Workout workout, List <Track> trackList)
        {
            string sportString;

            switch (workout.Sport)
            {
            case 0:
                sportString = "RUNNING";
                break;

            case 1:
                sportString = "CYCLING_SPORT";
                break;

            case 2:
                sportString = "CYCLING_TRANSPORTATION";
                break;

            default:
                sportString = "OTHER";
                break;
            }

            XmlWriter         writer;
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Indent = true;

            writer = XmlWriter.Create(fileName, xmlSettings);

            writer.WriteComment("Recovered data from Microsoft SQL CE database file: endo.sdf");

            // Write an element (root).
            writer.WriteStartElement("gpx");
            writer.WriteAttributeString("version", "1.1");
            writer.WriteAttributeString("creator", "Endomondo.com");
            writer.WriteAttributeString("xsi", "schemaLocation", null, "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd");
            writer.WriteAttributeString("xmlns", "gpxtpx", null, "http://www.garmin.com/xmlschemas/TrackPointExtension/v1");
            writer.WriteAttributeString("xmlns", "gpxx", null, "http://www.garmin.com/xmlschemas/GpxExtensions/v3");
            writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");

            // Write the title.
            writer.WriteStartElement("metadata");
            writer.WriteStartElement("author");
            writer.WriteElementString("name", "Krzysztof Krysiak");
            writer.WriteStartElement("email");
            writer.WriteAttributeString("id", "krysiak86");
            writer.WriteAttributeString("domain", "gmail.com");
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteStartElement("link");
            writer.WriteAttributeString("href", "http://www.endomondo.com");
            writer.WriteElementString("text", "Endomondo");
            writer.WriteEndElement();
            writer.WriteElementString("time", DateTime.Now.ToString("u").Replace(" ", "T"));
            writer.WriteStartElement("bounds");
            writer.WriteAttributeString("minlat", getMinLatitude(trackList).ToString());
            writer.WriteAttributeString("minlon", getMinLongitude(trackList).ToString());
            writer.WriteAttributeString("maxlat", getMaxLatitude(trackList).ToString());
            writer.WriteAttributeString("maxlon", getMaxLongitude(trackList).ToString());
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteStartElement("trk");
            writer.WriteElementString("src", "http://www.endomondo.com/");
            writer.WriteElementString("type", sportString);
            // trkseg

            // /trkseg
            writer.WriteEndElement();

            // Write the close tag for the root element.
            writer.WriteEndElement();

            // Write the XML to file and close the writer.
            writer.Flush();
            writer.Close();
        }
Ejemplo n.º 2
0
        private static void CreateXmlTcx(string fileName, Workout workout, List <Track> trackList)
        {
            string sportString;

            switch (workout.Sport)
            {
            case 0:
                sportString = "Running";
                break;

            case 1:
                sportString = "Biking";
                break;

            case 2:
                goto case 1;

            default:
                sportString = "Other";
                break;
            }

            XmlWriter         writer;
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Indent = true;

            writer = XmlWriter.Create(fileName, xmlSettings);

            writer.WriteComment("Recovered data from Microsoft SQL CE database file: endo.sdf");

            // Write an element (root).
            writer.WriteStartElement("TrainingCenterDatabase");

            //writer.WriteAttributeString("xmlns", "bk", null, "urn:samples");
            //writer.WriteAttributeString("xmlns", "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2");
            //XmlDocument x = new XmlDocument();
            //XmlAttribute xa = x.CreateAttribute( ??? );

            // Write the namespace declaration.
            writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
            writer.WriteAttributeString("xsi", "schemaLocation", null, "http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd");

            // Write the title.
            writer.WriteStartElement("Activities");
            writer.WriteStartElement("Activity");
            writer.WriteAttributeString("Sport", sportString);

            writer.WriteElementString("Id", trackList[trackList.Count - 1].Timestamp.ToString("u").Replace(" ", "T"));
            writer.WriteStartElement("Lap");
            writer.WriteAttributeString("StartTime", trackList[0].Timestamp.ToString("u").Replace(" ", "T"));
            writer.WriteElementString("TotalTimeSecond", workout.Duration.ToString());
            writer.WriteElementString("DistanceMeters", (trackList[trackList.Count - 1].Distance * 1000).ToString());
            writer.WriteElementString("Intensity", "Active");
            writer.WriteElementString("TriggerMethod", "Manual");
            writer.WriteStartElement("Track");
            foreach (Track track in trackList)
            {
                writer.WriteStartElement("Trackpoint");
                writer.WriteElementString("Time", track.Timestamp.ToString("u").Replace(" ", "T"));
                writer.WriteStartElement("Position");
                writer.WriteElementString("LatitudeDegrees", track.Latitude.ToString());
                writer.WriteElementString("LongitudeDegrees", track.Longitude.ToString());
                writer.WriteEndElement();
                writer.WriteElementString("AltitudeMeters", track.Altitude.ToString("0.0"));
                writer.WriteEndElement();
            }
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndElement();
            writer.WriteEndElement();

            // Write the close tag for the root element.
            writer.WriteEndElement();

            // Write the XML to file and close the writer.
            writer.Flush();
            writer.Close();
        }