private async Task<object> ShowMap(RoomInfo location) { if (location == null) return null; string svgDocContent = await CloudAccesser.LoadMapSvg(location, Waiter); UpdateLoginLogoutUI(); if (svgDocContent == null) return null; ResetMap(); this.roomDisplay.Text = location.ToString(); roomDisplay.Visibility = Visibility.Visible; ContentPanel.Visibility = Visibility.Collapsed; funky.Visibility = Visibility.Visible; Foo.Visibility = Visibility.Visible; funkyKids.Children.Clear(); var f = this.funky; var fk = this.funkyKids; var resources = this.Resources; var textRotation = (CompositeTransform)this.Resources["antiRotation"]; var dispatcher = this.Dispatcher; var tcs = new TaskCompletionSource<object>(); System.Threading.Thread t = new System.Threading.Thread(() => { map = new XamlMapInfo(location, svgDocContent); map.Render(f, fk, Foo, textRotation, (x) => dispatcher.BeginInvoke(x), location); tcs.SetResult(null); }); t.Start(); return tcs.Task; }
async static public Task<string> LoadMapSvg(RoomInfo location, Action<bool> waiter) { // Check cache waiter(true); try { string filename = "Maps/" + location.Building + "-" + location.Floor + ".svg"; IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication(); if (store.FileExists(filename)) { // TODO: Add app-wide support for clearing cache var content = store.OpenFile(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); string svgDocContent = new System.IO.StreamReader(content).ReadToEnd(); return svgDocContent; } // Not in cache, so need to access files on server. if (!await TryLogin()) { return null; } // OK, user has permission so lets try to get the data from the server. var mapTable = service.GetTable<Map>(); List<Map> maps = null; try { maps = await mapTable.Where(p => p.Building == location.Building && p.Floor == location.Floor).ToListAsync(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } if (maps == null || maps.Count() == 0) { MessageBox.Show("Server does not have a map for: " + location.ToString()); #if !NETFX_CORE return null; #else // Upload mode StreamResourceInfo resource = Application.GetResourceStream(new Uri(filename, UriKind.Relative)); string content0 = new StreamReader(resource.Stream).ReadToEnd(); var chunks = Chunker(content0, 1024 * 128); for (int i = 0; i < chunks.Length; i++) { var newMap = new Map() { Floor = location.Floor, Building = location.Building, Part = i, SVG = chunks[i] }; Debug.WriteLine("inserting " + i + " of " + chunks.Length); await mapTable.InsertAsync(newMap); } maps = await mapTable.Where(p => p.Building == location.Building && p.Floor == location.Floor).ToListAsync(); if (maps.Count() == 0) { MessageBox.Show("Still wrong!"); return null; } #endif } // Map is on the server string svg = string.Join("", maps.OrderBy(p => p.Part).Select(p => p.SVG)); if (!store.DirectoryExists("Maps")) { store.CreateDirectory("Maps"); } var content2 = store.OpenFile(filename, FileMode.OpenOrCreate, FileAccess.Write); byte[] bytes = Encoding.UTF8.GetBytes(svg); content2.Write(bytes, 0, bytes.Length); content2.Flush(); content2.Close(); return svg; } finally { waiter(false); } }
private async Task ShowMap(RoomInfo location, GeoCoord? loc = null) { if (location == null) return; string content = await CloudAccesser.LoadMapSvg(location, Waiter); MapMetadata mapMetadata = await CloudAccesser.LoadMapMetadata(location); #if NETFX_CORE || WINDOWS_PHONE UpdateLoginLogoutUI(); #endif if (content == null) return; this.roomDisplay.Text = ""; view.ResetMap(); this.roomDisplay.Text = location.ToString(); roomDisplay.Visibility = Visibility.Visible; ContentPanel.Visibility = Visibility.Collapsed; view.Visibility = Visibility.Visible; overlay.Visibility = Visibility.Visible; var resources = this.Resources; var dispatcher = this.Dispatcher; var map = new XamlMapInfo(location, content, mapScaleFactor); this.view.MapMetadata = mapMetadata; await map.Render(view.LiveChildCollection, view.TextRotation, (a, b, c) => { this.view.SetViewForMap(a, b, c); if (loc.HasValue) { view.ShowScanLoc(loc.Value); } }, RunOnUIThread, location, overlay); }