

GMap.NET.WindowsPresentation\GMap.NET.WindowsPresentation\GMapControl.cs [1104]

      public bool SetZoomToFitRect(RectLatLng rect, int maxPermittedZoom)
      {
          int maxZoom = Core.GetMaxZoomToFitRect(rect);
          if (maxZoom > 0)
          {
              PointLatLng center = new PointLatLng(rect.Lat - (rect.HeightLat / 2), rect.Lng + (rect.WidthLng / 2));
              Position = center;

              if (maxZoom > MaxZoom)
              {
                  maxZoom = MaxZoom;
              }

              if (maxZoom > maxPermittedZoom)
              {
                  maxZoom = maxPermittedZoom;
              }

              if (Core.Zoom != maxZoom)
              {
                  Zoom = maxZoom;
              }

              return true;
          }
          return false;
      }


-GMap.NET.Core\GMap.NET\GMaps.cs [198]

      public bool ExportToPath(string path)
      {
#if SQLite
          if (PrimaryCache is SQLitePureImageCache)
          {
              StringBuilder db = new StringBuilder((PrimaryCache as SQLitePureImageCache).GtileCache);
              db.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}Data.gmdb", GMapProvider.LanguageStr, Path.DirectorySeparatorChar);

              return SQLitePureImageCache.ExportMapDataToPath(db.ToString(), path);
          }
#endif
          return false;
      }


-GMap.NET.Core\GMap.NET.CacheProviders\SQLitePureImageCache.cs [618]

      public static bool ExportMapDataToPath(string sourceFile, string destPath)
      {
          bool ret = true;

          try
          {
              //if (!File.Exists(destPath))
              //{
              //    ret = CreateEmptyDB(destPath);
              //}

              if (ret)
              {
                  using (SQLiteConnection cn1 = new SQLiteConnection())
                  {
#if !MONO
                      cn1.ConnectionString = string.Format("Data Source=\"{0}\";Page Size=32768", sourceFile);
#else
                      cn1.ConnectionString = string.Format("Version=3,URI=file://{0},FailIfMissing=True,Page Size=32768", sourceFile);
#endif

                      cn1.Open();
                      if (cn1.State == System.Data.ConnectionState.Open)
                      {
                          //using (SQLiteConnection cn2 = new SQLiteConnection())
                          //{
#if !MONO
                          //cn2.ConnectionString = string.Format("Data Source=\"{0}\";Page Size=32768", destPath);
#else
                              //cn2.ConnectionString = string.Format("Version=3,URI=file://{0},FailIfMissing=True,Page Size=32768", destFile);
#endif
                          //cn2.Open();
                          //if (cn2.State == System.Data.ConnectionState.Open)
                          //{
                          //using (SQLiteCommand cmd = new SQLiteCommand(string.Format("ATTACH DATABASE \"{0}\" AS Source", sourceFile), cn2))
                          //{
                          //    cmd.ExecuteNonQuery();
                          //}

#if !MONO
                          //using (SQLiteTransaction tr = cn2.BeginTransaction())
#else
                                  //using(DbTransaction tr = cn2.BeginTransaction())
#endif
                          //{
                          try
                          {
                              List<long> add = new List<long>();
                              using (SQLiteCommand cmd = new SQLiteCommand("SELECT id, X, Y, Zoom, Type FROM Tiles;", cn1))
                              {
                                  using (SQLiteDataReader rd = cmd.ExecuteReader())
                                  {
                                      while (rd.Read())
                                      {
                                          long id = rd.GetInt64(0);
                                          //using (SQLiteCommand cmd2 = new SQLiteCommand(string.Format("SELECT id FROM Tiles WHERE X={0} AND Y={1} AND Zoom={2} AND Type={3};", rd.GetInt32(1), rd.GetInt32(2), rd.GetInt32(3), rd.GetInt32(4)), cn2))
                                          //{
                                          //using (SQLiteDataReader rd2 = cmd2.ExecuteReader())
                                          //{
                                          //if (!rd2.Read())
                                          //{
                                          add.Add(id);
                                          //}
                                          //}
                                          //}
                                      }
                                  }
                              }

                              foreach (long id in add)
                              {
                                  //using (SQLiteCommand cmd = new SQLiteCommand(string.Format("INSERT INTO Tiles(X, Y, Zoom, Type, CacheTime) SELECT X, Y, Zoom, Type, CacheTime FROM Source.Tiles WHERE id={0}; INSERT INTO TilesData(id, Tile) Values((SELECT last_insert_rowid()), (SELECT Tile FROM Source.TilesData WHERE id={0}));", id), cn2))
                                  {
                                      //cmd.Transaction = tr;
                                      //cmd.ExecuteNonQuery();
                                  }







                                  //SQLiteCommand cmd = new SQLiteCommand(string.Format("SELECT X, Y, Zoom, Type, CacheTime FROM Source.Tiles WHERE id={0};
                                  //INSERT INTO TilesData(id, Tile) Values((SELECT last_insert_rowid()), (SELECT Tile FROM Source.TilesData WHERE id={0}));", id), cn2)
                                  //using (SQLiteCommand cmd = new SQLiteCommand("SELECT id, X, Y, Zoom, Type FROM Tiles;", cn1))
                                  //{
                                  //    using (SQLiteDataReader rd = cmd.ExecuteReader())
                                  //    {
                                  //        while (rd.Read())
                                  //        {
                                  //            //long id = rd.GetInt64(0);


                                  //            add.Add(id);

                                  //        }
                                  //    }
                                  //}







                              }
                              add.Clear();

                              //tr.Commit();
                          }
                          catch (Exception exx)
                          {
                              Debug.WriteLine("ExportMapDataToDB: " + exx.ToString());
                              //tr.Rollback();
                              ret = false;
                          }
                          //}

                          //using (SQLiteCommand cmd = new SQLiteCommand("DETACH DATABASE Source;", cn2))
                          //{
                          //    cmd.ExecuteNonQuery();
                          //}
                          //}
                          //}
                      }
                  }
              }
          }
          catch (Exception ex)
          {
              Debug.WriteLine("ExportMapDataToDB: " + ex.ToString());
              ret = false;
          }
          return ret;
      }


DrawToolsLib\DrawingCanvas.cs [112]

        public string Save()
        {
            string result = "";

            try
            {
                SerializationHelper helper = new SerializationHelper(graphicsList);
                XmlSerializer xml = new XmlSerializer(typeof(SerializationHelper));

                StringBuilder sb = new StringBuilder();
                XmlWriter writer = XmlWriter.Create(sb);

                xml.Serialize(writer, helper);

                result = sb.ToString();

                ClearHistory();
                UpdateState();
            }
            catch (IOException e)
            {
                throw new DrawingCanvasException(e.Message, e);
            }
            catch (InvalidOperationException e)
            {
                throw new DrawingCanvasException(e.Message, e);
            }

            return result;
        }

