private void ParseDatabaseVersion1And2(XmlDocument doc)
{
XmlNode root, node, subnode;
// Run Summary section
root = doc.SelectSingleNode ("/sportsData/runSummary");
if (root == null)
return;
node = root.SelectSingleNode ("workoutName");
if (node != null)
name = node.InnerText;
node = root.SelectSingleNode ("time");
if (node != null)
time = DateTime.Parse (node.InnerText);
node = root.SelectSingleNode ("duration");
if (node != null)
duration = TimeSpan.FromMilliseconds (Convert.ToInt64 (node.InnerText));
node = root.SelectSingleNode ("distance");
if (node != null) {
distance = Convert.ToDouble (node.InnerText);
subnode = node.Attributes["unit"];
if (subnode != null) {
if (subnode.InnerText == KILOMETERS)
distanceUnit = DistanceUnit.Kilometers;
else if (subnode.InnerText == MILES)
distanceUnit = DistanceUnit.Miles;
}
}
node = root.SelectSingleNode ("pace");
if (node != null)
pace = node.InnerText;
node = root.SelectSingleNode ("calories");
if (node != null)
calories = Convert.ToInt32 (node.InnerText);
// ignore battery (what is this for?)
// ignore stepCounts (do we need this?)
// v2: ignore powerSong
// Template section
root = doc.SelectSingleNode ("/sportsData/template");
if (root != null) {
node = root.SelectSingleNode ("templateID");
if (node != null)
templateId = node.InnerText;
node = root.SelectSingleNode ("templateName");
if (node != null)
templateName = node.InnerText;
}
// TODO: Goal section
// TODO: UserInfo section
// StartTime section
root = doc.SelectSingleNode ("/sportsData/startTime");
if (root != null)
startTime = DateTime.Parse (root.InnerText);
// TODO: Snap Shot List section
// Extended Data List section
root = doc.SelectSingleNode ("/sportsData/extendedDataList");
// XXX: Can you have more than one of these?
node = root.SelectSingleNode ("extendedData");
if (node != null) {
subnode = node.Attributes["dataType"];
if (subnode != null && subnode.InnerText != "distance")
throw new FormatException ("Got unknown extendedData dataType: " + subnode.InnerText);
subnode = node.Attributes["intervalType"];
if (subnode != null && subnode.InnerText != "time")
throw new FormatException ("Got unknown extendedData intervalType: " + subnode.InnerText);
subnode = node.Attributes["intervalUnit"];
if (subnode != null && subnode.InnerText != "s")
throw new FormatException ("Got unknown extendedData intervalUnit: " + subnode.InnerText);
subnode = node.Attributes["intervalValue"];
if (subnode != null)
intervalValue = Convert.ToInt32 (subnode.InnerText);
// Now, parse a long, comma + space delimited list of intervals
string[] intervalTokens = node.InnerText.Split (',');
intervals = new double[intervalTokens.Length];
for (int i = 0; i < intervalTokens.Length; i++) {
intervals[i] = Convert.ToDouble (intervalTokens[i].Trim ());
}
}
}