Beispiel #1
0
        public void Start(String targetDB, bool isMove, ModeEnum modeType, OCMMainWindow win)
        {
            if (isMove)
            {
                Title            = Catalog.GetString("Move Caches...");
                copyLabel.Markup = Catalog.GetString("Moving Geocaches");
            }
            List <Geocache> caches;

            if (modeType == CopyingProgress.ModeEnum.VISIBLE)
            {
                caches = win.CacheList.UnfilteredCaches;
            }
            else if (modeType == CopyingProgress.ModeEnum.SELECTED)
            {
                caches = new List <Geocache> ();
                caches.Add(win.CacheList.SelectedCache);
            }
            else
            {
                caches = null;
                //caches = new List<Geocache> (UIMonitor.getInstance ().CacheStore.GetUnfilteredCaches(0d,0d,new string[0]));
            }
            ACacheStore target = new FileStore(targetDB);
            ACacheStore source = win.App.CacheStore;

            targetDBLabel.Text = targetDB;
            double count = 0;

            total = caches.Count;
            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);
            }

            target.StartUpdate();
            target.PurgeAllLogs(str.ToArray());
            target.PurgeAllAttributes(str.ToArray());
            target.PurgeAllTravelBugs(str.ToArray());
            foreach (Geocache cache in caches)
            {
                if (cancel)
                {
                    target.CancelUpdate();
                    this.Hide();
                    this.Dispose();
                    return;
                }

                count++;
                UpdateProgress(count, cache.Name);
                target.AddWaypointOrCache(cache, false, false);
                List <CacheLog> logs = source.GetCacheLogs(cache.Name);
                foreach (CacheLog log in logs)
                {
                    target.AddLog(cache.Name, log);
                }

                List <Waypoint> children = source.GetChildWaypoints(new string[] { cache.Name });
                foreach (Waypoint child in children)
                {
                    target.AddWaypointOrCache(child, false, false);
                }

                CacheAttribute[] attributes = source.GetAttributes(cache.Name);
                foreach (CacheAttribute attribute in attributes)
                {
                    target.AddAttribute(cache.Name, attribute);
                }

                if (isMove)
                {
                    source.DeleteWaypoint(cache.Name);
                }
            }
            statusLabel.Markup   = Catalog.GetString("<i>Complete</i>");
            progressBar.Text     = Catalog.GetString("Complete");
            buttonOk.Visible     = true;
            buttonCancel.Visible = false;
            target.CompleteUpdate();
        }