Пример #1
0
        public void parseGPXFile(FileStream fs, CacheStore store)
        {
            m_store = store;
            XmlReader reader = XmlReader.Create(fs);
            reader.Settings.IgnoreWhitespace = true;
            while (reader.Read())
            {
                if (m_cancel)
                {
                    m_store.CancelUpdate(m_trans);
                    return;
                }
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (reader.Name == "time")
                            gpx_date = reader.ReadElementContentAsDateTime();
                        if (reader.Name == "loc")
                            m_source = reader.GetAttribute("src");
                        if (reader.Name == "url")
                        {
                            string val = reader.ReadElementContentAsString();
                            if (val.Contains("opencaching")||val.Contains("gctour"))
                                m_source = "opencaching";
                        }
                        if (reader.Name == "wpt")
                        {
                            Waypoint pt = processWaypoint(reader);
                            pt.Updated = gpx_date;
                            m_store.AddWaypoint(pt, m_preserveFound);
                            if ((pt is Geocache) && (m_bookmark != null))
                                m_store.BookMarkCache(pt.Name, m_bookmark);
                        }

                        if (reader.Name == "waypoint" && reader.IsStartElement())
                        {
                            Waypoint pt = processLocWaypoint(reader);
                            pt.Updated = System.DateTime.Now;
                            m_store.AddWaypoint(pt, m_preserveFound);
                            if ((pt is Geocache) && (m_bookmark != null))
                                m_store.BookMarkCache(pt.Name, m_bookmark);
                        }
                        break;
                    case XmlNodeType.EndElement:
                        break;
                }
            }
            reader.Close();
            this.Complete(this, EventArgs.Empty);
        }
        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);
        }