public int PreParseForSingle(FileStream fs, CacheStore store) { XmlReader rdr = XmlReader.Create(fs); rdr.Settings.IgnoreWhitespace = true; int count = 0; List<String> waypoints = new List<String>(); while (rdr.Read()) { if (rdr.Name == "wpt" && rdr.IsStartElement()) { count++; } else if (rdr.Name == "waypoint" && rdr.IsStartElement()) { count++; } else if (rdr.LocalName == "name" && rdr.IsStartElement()) { waypoints.Add(CacheStore.SQLEscape(rdr.ReadElementContentAsString())); } } rdr.Close(); store.ClearTBs(waypoints); if (m_purgeLogs) store.ClearLogs(waypoints); store.ClearAttributes(waypoints); return count; }
public void clearForImport(FileStream fs, CacheStore store) { XmlReader rdr = XmlReader.Create(fs); rdr.Settings.IgnoreWhitespace = true; List<String> waypoints = new List<String>(); while (rdr.Read()) { if (rdr.LocalName == "name" && rdr.IsStartElement()) { waypoints.Add(CacheStore.SQLEscape(rdr.ReadElementContentAsString())); } } rdr.Close(); store.ClearTBs(waypoints); if (m_purgeLogs) store.ClearLogs(waypoints); store.ClearAttributes(waypoints); return; }
public void Start(String targetDB, bool isMove, ModeEnum modeType) { if (isMove) { Title = Catalog.GetString("Move Caches..."); copyLabel.Markup = Catalog.GetString("Moving Geocaches"); } List <Geocache> caches; if (modeType == CopyingProgress.ModeEnum.VISIBLE) { caches = UIMonitor.getInstance().GetVisibleCacheList(); } else if (modeType == CopyingProgress.ModeEnum.SELECTED) { caches = new List<Geocache>(); caches.Add(UIMonitor.getInstance().SelectedCache); } else { caches = Engine.getInstance().Store.GetCaches(0,0); } CacheStore target = new CacheStore(); CacheStore source = Engine.getInstance().Store; targetDBLabel.Text = targetDB; double count = 0; total = caches.Count; target.SetDB(targetDB); if (target.NeedsUpgrade()) { MessageDialog dlg = new MessageDialog(null, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, Catalog.GetString("The target database needs to be upgraded. " + "Please open the target database before trying to copy/move caches.")); dlg.Run(); dlg.Hide(); this.Hide(); return; } buttonOk.Visible = false; List<String> str = new List<String>(); foreach(Geocache c in caches) { str.Add(c.Name); } IDbTransaction trans = target.StartUpdate(); target.ClearAttributes(str); target.ClearTBs(str); foreach(Geocache cache in caches) { if (cancel) { target.CancelUpdate(trans); this.Hide(); this.Dispose(); return; } count++; UpdateProgress(count, cache.Name); target.AddCache(cache); target.AddWaypoint(cache); List<CacheLog> logs = source.GetCacheLogs(cache.Name); //target.ClearLogs(cache.Name); foreach(CacheLog log in logs) { System.Console.WriteLine("Adding logs"); target.AddLog(cache.Name, log); } List<Waypoint> children = source.GetChildren(cache.Name); foreach (Waypoint child in children) { target.AddWaypoint(child); } List<CacheAttribute> attributes = source.GetAttributes(cache.Name); foreach (CacheAttribute attribute in attributes) { target.AddAttribute(attribute, cache.Name); } if (isMove) source.DeleteGeocacheAtomic(cache); } statusLabel.Markup = Catalog.GetString("<i>Complete</i>"); progressBar.Text = Catalog.GetString("Complete"); buttonOk.Visible = true; buttonCancel.Visible = false; target.EndUpdate(trans); }