public static String FromGRouteToIsolatedStorageFormat(GRoute route) { String result = ""; result += "<xml>"; result += Environment.NewLine + "\t" + "<route> "; result += Environment.NewLine + "\t\t" + "<StartTime>" + route.StartTime.ToString("yyyy:MM:dd:HH:mm:ss") + "</StartTime>"; result += Environment.NewLine + "\t\t" + "<EndTime>" + route.EndTime.ToString("yyyy:MM:dd:HH:mm:ss") + "</EndTime> "; result += Environment.NewLine + "\t\t" + "<FullTime>" + route.FullTime.TotalSeconds + "</FullTime> "; result += Environment.NewLine + "\t\t" + "<UploadCheck>" + route.UploadCheck.ToString() + "</UploadCheck> "; result += Environment.NewLine + "\t\t" + "<TotalDistance>" + route.TotalDistance.ToString() + "</TotalDistance> "; result += Environment.NewLine + "\t\t" + "<coordinates>"; foreach (GPoint point in route.Coordinates) { result += Environment.NewLine + "\t\t\t" + "<point>"; result += Environment.NewLine + "\t\t\t\t" + "<Lon>" + point.Longitude.ToString().Replace(",", ".") + "</Lon>"; result += Environment.NewLine + "\t\t\t\t" + "<Lat>" + point.Latitude.ToString().Replace(",", ".") + "</Lat>"; result += Environment.NewLine + "\t\t\t\t" + "<Speed>" + point.Speed.ToString().Replace(",", ".") + "</Speed>"; result += Environment.NewLine + "\t\t\t\t" + "<Alt>" + point.Altitude.ToString().Replace(",", ".") + "</Alt>"; result += Environment.NewLine + "\t\t\t\t" + "<Com>" + point.Comment.ToString() + "</Com>"; result += Environment.NewLine + "\t\t\t\t" + "<TT>" + point.TimeTaken.ToString("yyyy:MM:dd:HH:mm:ss") + "</TT>"; result += Environment.NewLine + "\t\t\t\t" + "<Num>" + point.PointNumber.ToString() + "</Num>"; //TO-DO Make picture paths here result += Environment.NewLine + "\t\t\t" + "</point>"; } result += Environment.NewLine + "\t\t" + "</coordinates>"; result += Environment.NewLine + "\t" + "</route>"; result += Environment.NewLine + "</xml>"; return result; }
public static bool FromIsolatedStorageFormatToGRoutes(String text, out List<GRoute> routes) { routes = new List<GRoute>(); bool succes = false; String[] split = { Environment.NewLine }; String pattern = @">(.*?)<"; GRoute route = new GRoute(); GPoint point = new GPoint(); String lineValue = ""; try { String[] lines = text.Split(split, StringSplitOptions.RemoveEmptyEntries); foreach (String line in lines) { if (line.Contains("<route>")) { route = new GRoute(); } else if (line.Contains("<StartTime>")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); route.StartTime = GPointConverter.FromStringToDateTime(lineValue); } else if (line.Contains("<EndTime>")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); route.EndTime = GPointConverter.FromStringToDateTime(lineValue); } else if (line.Contains("FullTime")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); route.FullTime = TimeSpan.FromSeconds(Int32.Parse(lineValue)); } else if (line.Contains("UploadCheck")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); route.UploadCheck = Boolean.Parse(lineValue); } else if (line.Contains("TotalDistance")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); route.TotalDistance = GPointConverter.ConvertToDouble(lineValue); } else if (line.Contains("<point>")) { point = new GPoint(); } else if (line.Contains("Lon")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); point.Longitude = GPointConverter.ConvertToDouble(lineValue); } else if (line.Contains("Lat")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); point.Latitude = GPointConverter.ConvertToDouble(lineValue); } else if (line.Contains("Speed")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); point.Speed = GPointConverter.ConvertToDouble(lineValue); } else if (line.Contains("Alt")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); point.Altitude = GPointConverter.ConvertToDouble(lineValue); } else if (line.Contains("Com")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); point.Comment = lineValue; } else if (line.Contains("TT")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); point.TimeTaken = new DateTimeOffset(GPointConverter.FromStringToDateTime(lineValue)); } else if (line.Contains("Num")) { lineValue = Regex.Matches(line, pattern)[0].Groups[1].ToString(); point.Altitude = Int32.Parse(lineValue); } else if (line.Contains("/point")) { route.AddNewGPoint(point, false); } else if (line.Contains("/route")) { routes.Add(route); } } } catch (Exception e) { succes = false; MessageBox.Show(e.Message); } return succes; }