예제 #1
0
        public void LoadTripData(string folderPath)
        {
            // save the base folder path
            dataPath = folderPath;

            // generate path to the trips.dat XML, and then load it
            string      metadataPath = folderPath + "\\trips.dat";
            XmlDocument xmlDocument  = new XmlDocument();

            xmlDocument.Load(metadataPath);
            // grab ride list via the XML root node in trips.dat
            XmlNodeList xmlNodes = xmlDocument.GetElementsByTagName("TripDetailsItem");

            foreach (XmlNode node in xmlNodes)
            {// loop through the ride list and store the metadata into the variables
                XmlNodeReader xmlNodeReader = new XmlNodeReader(node);
                // for some reason, need to "read" twice to access the data
                xmlNodeReader.Read();
                xmlNodeReader.Read();
                FileName.Add(xmlNodeReader.ReadElementContentAsString());
                Title.Add(xmlNodeReader.ReadElementContentAsString());
                Distance.Add(xmlNodeReader.ReadElementContentAsDouble());
                // the duration is stored as ticks; cast as DateTime
                // for conversion to seconds later
                duration.Add(new DateTime(xmlNodeReader.ReadElementContentAsLong()));
                DateOfRoute.Add(xmlNodeReader.ReadElementContentAsDateTime());
                CaloriesBurned.Add(xmlNodeReader.ReadElementContentAsInt());
                Weather.Add(xmlNodeReader.ReadElementContentAsInt());
                CourseJoy.Add(xmlNodeReader.ReadElementContentAsInt());
                ExtraNotes.Add(xmlNodeReader.ReadElementContentAsString());
            }
        }