private bool IsEqual(MaptileData a, MaptileData b) { var mismatches = new List <string>(); if (a.Location != b.Location) { mismatches.Add("Location"); } if (a.LastUpdate.AsULong != b.LastUpdate.AsULong) { m_Log.InfoFormat("LastUpdate mismatch {0} != {1}", a.LastUpdate.AsULong, b.LastUpdate.AsULong); mismatches.Add("LastUpdate"); } if (a.ZoomLevel != b.ZoomLevel) { mismatches.Add("ZoomLevel"); } if (!a.Data.SequenceEqual(b.Data)) { mismatches.Add("Data"); } if (mismatches.Count != 0) { m_Log.InfoFormat("Mismatches: {0}", string.Join(" ", mismatches)); } return(mismatches.Count == 0); }
public override bool TryGetValue(GridVector location, int zoomlevel, out MaptileData data) { data = default(MaptileData); using (var connection = new NpgsqlConnection(m_ConnectionString)) { connection.Open(); using (var cmd = new NpgsqlCommand("SELECT * FROM maptiles WHERE \"LocX\" = @locx AND \"LocY\" = @locy AND \"ZoomLevel\" = @zoomlevel LIMIT 1", connection)) { cmd.Parameters.AddParameter("@locx", location.X); cmd.Parameters.AddParameter("@locy", location.Y); cmd.Parameters.AddParameter("@zoomlevel", zoomlevel); using (NpgsqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { data = new MaptileData(); data.Location.X = (uint)(int)reader["LocX"]; data.Location.Y = (uint)(int)reader["LocY"]; data.LastUpdate = reader.GetDate("LastUpdate"); data.ContentType = (string)reader["ContentType"]; data.ZoomLevel = (int)reader["ZoomLevel"]; data.Data = reader.GetBytes("Data"); return(true); } } } } return(false); }
private static Image FromMaptileData(MaptileData data) { using (var ms = new MemoryStream(data.Data)) { return(new Bitmap(ms)); } }
public override bool TryGetValue(UUID scopeid, GridVector location, int zoomlevel, out MaptileData data) { data = default(MaptileData); using (var connection = new MySqlConnection(m_ConnectionString)) { connection.Open(); using (var cmd = new MySqlCommand("SELECT * FROM maptiles WHERE LocX = @locx AND LocY = @locy AND ZoomLevel = @zoomlevel", connection)) { cmd.Parameters.AddParameter("@locx", location.X); cmd.Parameters.AddParameter("@locy", location.Y); cmd.Parameters.AddParameter("@zoomlevel", zoomlevel); using (MySqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { data = new MaptileData(); data.Location.X = reader.GetUInt32("LocX"); data.Location.Y = reader.GetUInt32("LocY"); data.ScopeID = reader.GetUUID("ScopeID"); data.LastUpdate = reader.GetDate("LastUpdate"); data.ContentType = reader.GetString("ContentType"); data.ZoomLevel = reader.GetInt32("ZoomLevel"); data.Data = reader.GetBytes("Data"); return(true); } } } } return(false); }
public override void Store(MaptileData data) { m_MaptileService.Store(data); int zoomlevel = data.ZoomLevel; GridVector location = data.Location; while (++zoomlevel < MaxZoomLevel) { location = location.AlignToZoomlevel(zoomlevel); m_MaptileService.Remove(location, zoomlevel); } }
public override void Store(MaptileData data) { using (var connection = new NpgsqlConnection(m_ConnectionString)) { connection.Open(); var vals = new Dictionary <string, object> { ["LocX"] = data.Location.X, ["LocY"] = data.Location.Y, ["LastUpdate"] = data.LastUpdate, ["ContentType"] = data.ContentType, ["ZoomLevel"] = data.ZoomLevel, ["Data"] = data.Data }; connection.ReplaceInto("maptiles", vals, new string[] { "LocX", "LocY", "ZoomLevel" }, true); } }
public override void Store(MaptileData data) { using (var connection = new MySqlConnection(m_ConnectionString)) { connection.Open(); var vals = new Dictionary <string, object> { ["LocX"] = data.Location.X, ["LocY"] = data.Location.Y, ["ScopeID"] = data.ScopeID, ["LastUpdate"] = Date.Now, ["ContentType"] = data.ContentType, ["ZoomLevel"] = data.ZoomLevel, ["Data"] = data.Data }; connection.ReplaceInto("maptiles", vals); } }
public abstract void Store(MaptileData data);
public abstract bool TryGetValue(GridVector location, int zoomlevel, out MaptileData data);
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 override bool TryGetValue(GridVector location, int zoomlevel, out MaptileData data) => m_Maptiles.TryGetValue(GetKey(location, zoomlevel), out data);
public override void Store(MaptileData data) { m_Maptiles[GetKey(data)] = new MaptileData(data); }
private static string GetKey(MaptileData data) => GetKey(data.Location, data.ZoomLevel);
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); }