public override bool TryGetValue(GridVector rawlocation, int zoomlevel, out MaptileData data)
        {
            data = null;
            if (zoomlevel < 1)
            {
                return(false);
            }
            GridVector location = rawlocation.AlignToZoomlevel(zoomlevel);

            if (m_MaptileService.TryGetValue(location, zoomlevel, out data))
            {
                return(true);
            }
            else if (zoomlevel > MaxZoomLevel || zoomlevel < 2)
            {
                return(false);
            }
            var zoomsize = (uint)(256 << (zoomlevel - 1));

            MaptileData map00;
            MaptileData map01;
            MaptileData map10;
            MaptileData map11;
            MaptileData outmap;

            if (!TryGetValue(location, zoomlevel - 1, out map00))
            {
                map00 = null;
            }
            GridVector v  = location;
            GridVector v2 = location;

            v2.X += zoomsize / 2;
            v2.Y += zoomsize / 2;

            if (m_MaptileService.TryGetValue(v, zoomlevel, out outmap))
            {
                List <MaptileInfo> upperInfo = m_MaptileService.GetUpdateTimes(v, v2, zoomlevel - 1);
                Date ownUpdate = outmap.LastUpdate;
                bool haveNewer = false;
                foreach (MaptileInfo up in upperInfo)
                {
                    if (up.LastUpdate.AsULong > ownUpdate.AsULong)
                    {
                        haveNewer = true;
                    }
                }
                if (!haveNewer)
                {
                    return(true);
                }
            }
            else
            {
                outmap = new MaptileData
                {
                    Location  = location,
                    ZoomLevel = zoomlevel,
                };
            }
            outmap.LastUpdate  = Date.Now;
            outmap.ContentType = "image/jpeg";

            v.Y += zoomsize / 2;
            if (!TryGetValue(v, zoomlevel - 1, out map01))
            {
                map01 = null;
            }
            v    = location;
            v.X += zoomsize / 2;
            if (!TryGetValue(location, zoomlevel - 1, out map10))
            {
                map10 = null;
            }
            v    = location;
            v.X += zoomsize / 2;
            v.Y += zoomsize / 2;
            if (!TryGetValue(location, zoomlevel - 1, out map11))
            {
                map11 = null;
            }

            using (var bmp = new Bitmap(256, 256, PixelFormat.Format24bppRgb))
            {
                using (Graphics gfx = Graphics.FromImage(bmp))
                {
                    gfx.FillRectangle(Brushes.Blue, new Rectangle(0, 0, 256, 256));
                    if (map00 != null)
                    {
                        using (Image img = FromMaptileData(map00))
                        {
                            gfx.DrawImage(img, 0, 128, 128, 128);
                        }
                    }
                    if (map01 != null)
                    {
                        using (Image img = FromMaptileData(map01))
                        {
                            gfx.DrawImage(img, 0, 0, 128, 128);
                        }
                    }
                    if (map10 != null)
                    {
                        using (Image img = FromMaptileData(map10))
                        {
                            gfx.DrawImage(img, 128, 128, 128, 128);
                        }
                    }
                    if (map11 != null)
                    {
                        using (Image img = FromMaptileData(map11))
                        {
                            gfx.DrawImage(img, 128, 0, 128, 128);
                        }
                    }
                }
                using (var ms = new MemoryStream())
                {
                    bmp.Save(ms, ImageFormat.Jpeg);
                    outmap.Data = ms.ToArray();
                }
            }

            m_MaptileService.Store(outmap);
            data = outmap;
            return(true);
        }
        public bool Run()
        {
            var         location = new GridVector(256000, 256000);
            MaptileData result;

            m_Log.Info("Testing non-existence 1");
            if (m_MaptileService.TryGetValue(location, 1, out result))
            {
                return(false);
            }

            m_Log.Info("Testing non-existence 2");
            if (m_MaptileService.GetUpdateTimes(location, location, 1).Count != 0)
            {
                return(false);
            }

            var testData = new MaptileData
            {
                ContentType = "application/octet-stream",
                Data        = new byte[] { 1, 2, 3, 4 },
                Location    = location,
                ZoomLevel   = 1,
                LastUpdate  = Date.Now
            };

            m_Log.Info("Store maptile");
            m_MaptileService.Store(testData);

            m_Log.Info("Testing existence 1");
            if (!m_MaptileService.TryGetValue(location, 1, out result))
            {
                return(false);
            }

            m_Log.Info("Testing equality");
            if (!IsEqual(testData, result))
            {
                return(false);
            }

            m_Log.Info("Testing existence 2");
            List <MaptileInfo> reslist;

            reslist = m_MaptileService.GetUpdateTimes(location, location, 1);
            if (reslist.Count != 1)
            {
                return(false);
            }
            m_Log.Info("Testing equality");
            if (!IsEqual(testData, reslist[0]))
            {
                return(false);
            }

            m_Log.Info("Remove maptile");
            m_MaptileService.Remove(location, 1);

            m_Log.Info("Testing non-existence 1");
            if (m_MaptileService.TryGetValue(location, 1, out result))
            {
                return(false);
            }

            m_Log.Info("Testing non-existence 2");
            if (m_MaptileService.GetUpdateTimes(location, location, 1).Count != 0)
            {
                return(false);
            }

            return(true);
        }