/Main/src/DynamicDataDisplay.Maps/Servers/MemoryServers/MemoryTileServer.cs
C# | 59 lines | 47 code | 12 blank | 0 comment | 1 complexity | fbd8eae46b46edb5a76f3b366c935d26 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Text; 5using System.Windows.Media.Imaging; 6using System.Windows.Media; 7using System.IO; 8 9namespace Microsoft.Research.DynamicDataDisplay.Charts.Maps 10{ 11 public sealed class MemoryTileServer : TileServerBase, ITileSystem { 12 public MemoryTileServer(string name) 13 { 14 ServerName = name; 15 } 16 17 private readonly Dictionary<TileIndex, BitmapSource> cache = new Dictionary<TileIndex, BitmapSource>(new TileIndex.TileIndexEqualityComparer()); 18 19 public override bool Contains(TileIndex id) 20 { 21 return cache.ContainsKey(id); 22 } 23 24 public override void BeginLoadImage(TileIndex id) 25 { 26 if (Contains(id)) 27 ReportSuccess(cache[id], id); 28 else 29 ReportFailure(id); 30 } 31 32 public BitmapSource this[TileIndex id] 33 { 34 get 35 { 36 return cache[id]; 37 } 38 } 39 40 #region ITileStore Members 41 42 public void BeginSaveImage(TileIndex id, BitmapSource image, Stream stream) 43 { 44 cache[id] = image; 45 } 46 47 #endregion 48 49 #region ITileStore Members 50 51 52 public void Clear() 53 { 54 throw new NotImplementedException(); 55 } 56 57 #endregion 58 } 59}