Ejemplo n.º 1
0
 public void Start(String filename, CacheStore store)
 {
     this.Show ();
     try {
         m_parser.StartUpdate(store);
         FileStream stream = File.OpenRead(filename);
         m_total = m_parser.PreParseForSingle(stream, store);
         stream.Close();
         stream = File.OpenRead(filename);
         m_progress = 0;
         m_progressCount = 0;
         m_timeStart = DateTime.Now;
         ParseFile (stream, store);
         stream.Close();
         if (!m_parser.Cancel)
             m_parser.EndUpdate(store);
     } catch (Exception e) {
         this.Hide ();
         UIMonitor.ShowException(e);
         this.Dispose ();
     }
 }
Ejemplo n.º 2
0
        void HandleStoreReadCache(object sender, CacheStore.ReadCacheArgs args)
        {
            m_intervalCount ++;
            if (m_pulseMode)
            {
                if (m_intervalCount == 50)
                {
                    m_monitor.SetProgressPulse();
                    m_intervalCount = 0;
                }
            }
            else
            {
                m_loadCount ++;

                if (m_intervalCount == 100)
                {
                    m_monitor.SetProgress(m_loadCount, m_loadTotal, String.Format(Catalog.GetString("Loading Caches {0}"), (m_loadCount/m_loadTotal).ToString("0%")), true);
                    m_intervalCount = 0;
                }
            }
            if (args.Cache != null)
                m_cacheModel.AppendValues(args.Cache);
        }
Ejemplo n.º 3
0
 private Engine()
 {
     m_store = new CacheStore();
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 public void StartUpdate(CacheStore store)
 {
     m_trans = store.StartUpdate();
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
 public void EndUpdate(CacheStore store)
 {
     store.EndUpdate(m_trans);
 }
Ejemplo n.º 9
0
        public void StartMulti(String directoryPath, CacheStore store, bool deleteOnCompletion)
        {
            m_isMulti = true;
            m_timeStart = DateTime.Now;
            string[] files = Directory.GetFiles(directoryPath);
            m_parser.StartUpdate(store);

            // Count total files
            m_progress = 0;
            m_progressCount = 0;
            m_total = 0;
            multiFileLabel.Visible = true;

            List<string> dirs = new List<string>();

            // Prescan for zip files and uncompress
            for (int i=0; i < files.Length; i++)
            {
                if (files[i].EndsWith(".zip"))
                {
                    this.progressbar6.Text = Catalog.GetString("Unzipping");
                    DirectoryInfo info = Directory.CreateDirectory(files[i].Substring(0, files[i].Length -4));
                    dirs.Add(info.FullName);
                    multiFileLabel.Text = Catalog.GetString("Unizpping");
                    this.waypointName.Markup = "<i>" + Catalog.GetString("Unzipping") + ":" + files[i] + "</i>";
                    while (Gtk.Application.EventsPending ())
                        Gtk.Application.RunIteration (false);
                    ProcessStartInfo start = new ProcessStartInfo();
                    start.FileName = "unzip";
                    start.Arguments = "-o \"" + files[i] + "\" -d \"" + info.FullName + "\"";
                    Process unzip =  Process.Start(start);
                    while (!unzip.HasExited)
                    {
                        // Do nothing until exit
                    }
                    if (deleteOnCompletion)
                    {
                        File.Delete(files[i]);
                    }
                }
            }

            // Rescan for all GPX files, including those uncompressed by ZIP files
            List<string> fileList = new List<string>();
            string[] directories = Directory.GetDirectories(directoryPath);
            BuildFileList (directoryPath, fileList);
            foreach (string dir in directories)
            {
                BuildFileList(dir, fileList);
            }

            int currCount = 0;
            foreach (string file in fileList)
            {
                if (file.EndsWith(".gpx"))
                {
                    currCount++;
                    //Clean out attributes,tbs,and logs that will be overwritten
                    if (m_parser.Cancel)
                        return;
                    FileStream fs =  System.IO.File.OpenRead (file);
                    m_parser.clearForImport(fs, store);
                    fs.Close();
                    // Need to reopen the file
                    fs =  System.IO.File.OpenRead (file);
                    multiFileLabel.Text = String.Format(Catalog.GetString("Processing File {0} of {1}"), currCount, fileList.Count);
                    ParseFile(fs, store);
                    fs.Close();
                    if (deleteOnCompletion)
                        File.Delete(file);
                }
            }

            if (deleteOnCompletion)
            {
                foreach (string dir in dirs)
                {
                    Directory.Delete(dir);
                }
            }
            m_parser.EndUpdate(store);
            HandleCompletion();
        }
Ejemplo n.º 10
0
 private void ParseFile(FileStream fs, CacheStore store)
 {
     fileLabel.Markup = Catalog.GetString("<b>File: </b>") + fs.Name;
         m_parser.parseGPXFile (fs, store);
 }
Ejemplo n.º 11
0
        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);
        }