public static void LoadFromIsolatedStorage() { String result = ""; result = App.LoadStringFromIsolatedStorage("CurrentRoute.xml"); if (!String.IsNullOrWhiteSpace(result)) { GRoute currRoute; GPointConverter.FromIsolatedStorageFormatToGRoute(result, out currRoute); if (currRoute.Coordinates.Count > 0) { gRouteTrackViewModel.CurrentRoute = currRoute; MessageBox.Show("Loaded CurrentRoute from isolatedStorage"); //TO-DO Log File } } App.DeleteFileFromIsolatedStorage("CurrentRoute.xml"); result = App.LoadStringFromIsolatedStorage("Routes.xml"); if (!String.IsNullOrWhiteSpace(result)) { List <GRoute> routes = new List <GRoute>(); GPointConverter.FromIsolatedStorageFormatToGRoutes(result, out routes); if (routes.Count > 0) { gRouteTrackViewModel.RoutesOnPhone = new ObservableCollection <GRoute>(routes); MessageBox.Show("Loaded Routes from isolatedStorage"); //TO-DO Log File } } App.DeleteFileFromIsolatedStorage("Routes.xml"); }
private void Email_Icon_Click(object sender, EventArgs e) { try { WriteableBitmap bi = App.ReadImageFromIsolatedStorage("gRouteTemp.jpg"); if (bi != null) { this.TestImage.Source = bi; } Tasks.ComposeEmail("*****@*****.**", "[WP]", GPointConverter.FromGRouteToIsolatedStorageFormat(App.gRouteTrackViewModel.CurrentRoute), ""); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void SaveToIsolatedStorage() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { if (!gRouteTrackViewModel.CurrentRoute.IsFinished) { using (IsolatedStorageFileStream fileStream = isf.CreateFile("CurrentRoute.xml")) { StreamWriter writter = new StreamWriter(fileStream); writter.Write(GPointConverter.FromGRouteToIsolatedStorageFormat(gRouteTrackViewModel.CurrentRoute)); writter.Close(); } } using (IsolatedStorageFileStream fileStream = isf.CreateFile("Routes.xml")) { StreamWriter writter = new StreamWriter(fileStream); writter.Write(GPointConverter.FromGRoutesToIsolatedStorageFormat(gRouteTrackViewModel.RoutesOnPhone.ToList <GRoute>())); writter.Close(); } } }
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); }