Пример #1
0
 private void threadMethod()
 {
     try
     {
         using (ProgressBlock progress = new ProgressBlock(_plugin, "Update archived geocaches", "Downloading data from globalcaching.eu", 1, 0))
         {
             using (System.Net.WebClient wc = new System.Net.WebClient())
             {
                 byte[] data = wc.DownloadData(string.Format("https://www.4geocaching.eu/Service/Archived.aspx?country=Belgium&prefix=GC&token={0}", System.Web.HttpUtility.UrlEncode(_core.GeocachingComAccount.APIToken)));
                 string sdoc = CompressText.UnzipText(data);
                 //_core.DebugLog(DebugLogLevel.Info, _plugin, null, sdoc);
                 XmlDocument doc = new XmlDocument();
                 doc.LoadXml(sdoc);
                 XmlElement  root   = doc.DocumentElement;
                 XmlNodeList strngs = root.SelectNodes("wp");
                 if (strngs != null)
                 {
                     progress.UpdateProgress("Update archived geocaches", "Updating geocaches...", strngs.Count, 0);
                     Geocache gc;
                     int      index = 0;
                     foreach (XmlNode sn in strngs)
                     {
                         gc = DataAccess.GetGeocache(_core.Geocaches, sn.InnerText);
                         if (gc != null)
                         {
                             gc.Archived  = true;
                             gc.Available = false;
                         }
                         index++;
                         if (index % 50 == 0)
                         {
                             //_core.DebugLog(DebugLogLevel.Info, _plugin, null, index.ToString());
                             progress.UpdateProgress("Update archived geocaches", "Updating geocaches...", strngs.Count, index);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         _errormessage = e.Message;
     }
     _actionReady.Set();
 }
 private void threadMethod()
 {
     try
     {
         using (ProgressBlock progress = new ProgressBlock(_plugin, "Update Favorite for Netherlands, Belgium and Italy", "Downloading data from globalcaching.eu", 1, 0))
         {
             using (System.Net.WebClient wc = new System.Net.WebClient())
             {
                 string doc = wc.DownloadString(string.Format("https://www.4geocaching.eu/Service/CacheFavorites.aspx?token={0}", System.Web.HttpUtility.UrlEncode(_core.GeocachingComAccount.APIToken)));
                 if (doc != null)
                 {
                     string[] lines = doc.Replace("\r", "").Split(new char[] { '\n' });
                     progress.UpdateProgress("Update Favorite of geocaches", "Updating geocaches...", lines.Length, 0);
                     Geocache gc;
                     char[]   sep = new char[] { ',' };
                     string[] parts;
                     foreach (string s in lines)
                     {
                         parts = s.Split(sep);
                         if (parts.Length > 0)
                         {
                             gc = DataAccess.GetGeocache(_core.Geocaches, parts[0]);
                             if (gc != null)
                             {
                                 gc.Favorites = int.Parse(parts[1]);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         _errormessage = e.Message;
     }
     _actionReady.Set();
 }
Пример #3
0
        public bool RepairV1()
        {
            bool result = true;

            if (File.Exists(_fileCollection.DatabaseInfoFilename))
            {
                int    lsize     = sizeof(long);
                byte[] memBuffer = new byte[10 * 1024 * 1024];
                using (MemoryStream ms = new MemoryStream(memBuffer))
                    using (BinaryReader br = new BinaryReader(ms))
                    {
                        int gcCount     = 0;
                        int logCount    = 0;
                        int logimgCount = 0;
                        int wptCount    = 0;
                        int usrwptCount = 0;

                        XmlDocument doc = new XmlDocument();
                        doc.Load(_fileCollection.DatabaseInfoFilename);
                        XmlElement root = doc.DocumentElement;
                        gcCount     = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText);
                        logCount    = int.Parse(root.SelectSingleNode("LogCount").InnerText);
                        logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText);
                        wptCount    = int.Parse(root.SelectSingleNode("WaypointCount").InnerText);
                        usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText);

                        DateTime nextUpdateTime = DateTime.MinValue;
                        using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0))
                        {
                            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0))
                            {
                                int index = 0;

                                FileStream fs = _fileCollection._fsGeocaches;
                                fs.Position = 0;
                                long       eof            = fs.Length;
                                long       lastOKPosition = 0;
                                RecordInfo ri             = new RecordInfo();
                                try
                                {
                                    while (fs.Position < eof)
                                    {
                                        lastOKPosition = fs.Position;
                                        ri.Offset      = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length   = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            ri.FreeSlot = true;
                                            ri.ID       = string.Concat("_", ri.Offset.ToString());
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else if (memBuffer[lsize] == 2)
                                        {
                                            ri.FreeSlot = false;
                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            ri.ID       = br.ReadString();
                                            br.ReadString();
                                            br.ReadBoolean();
                                            br.ReadString();
                                            br.ReadBoolean();
                                        }
                                        else
                                        {
                                            //read
                                            ri.FreeSlot = false;
                                            Framework.Data.Geocache gc = new Framework.Data.Geocache();

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            gc.Code     = br.ReadString();
                                            ri.ID       = gc.Code;

                                            gc.Archived     = br.ReadBoolean();
                                            gc.AttributeIds = ReadIntegerArray(br);
                                            gc.Available    = br.ReadBoolean();
                                            gc.City         = br.ReadString();
                                            gc.Container    = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32());
                                            gc.CustomCoords = br.ReadBoolean();
                                            gc.Country      = br.ReadString();
                                            if (br.ReadBoolean())
                                            {
                                                gc.CustomLat = br.ReadDouble();
                                                gc.CustomLon = br.ReadDouble();
                                            }
                                            gc.Difficulty    = br.ReadDouble();
                                            gc.EncodedHints  = br.ReadString();
                                            gc.Favorites     = br.ReadInt32();
                                            gc.Flagged       = br.ReadBoolean();
                                            gc.Found         = br.ReadBoolean();
                                            gc.GeocacheType  = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32());
                                            gc.ID            = br.ReadString();
                                            gc.Lat           = br.ReadDouble();
                                            gc.Lon           = br.ReadDouble();
                                            gc.MemberOnly    = br.ReadBoolean();
                                            gc.Municipality  = br.ReadString();
                                            gc.Name          = br.ReadString();
                                            gc.Notes         = br.ReadString();
                                            gc.Owner         = br.ReadString();
                                            gc.OwnerId       = br.ReadString();
                                            gc.PersonaleNote = br.ReadString();
                                            gc.PlacedBy      = br.ReadString();
                                            gc.PublishedTime = DateTime.Parse(br.ReadString());
                                            gc.State         = br.ReadString();
                                            gc.Terrain       = br.ReadDouble();
                                            gc.Title         = br.ReadString();
                                            gc.Url           = br.ReadString();
                                            gc.DataFromDate  = DateTime.Parse(br.ReadString());
                                            gc.Locked        = br.ReadBoolean();

                                            gc.Saved         = true;
                                            gc.IsDataChanged = false;

                                            index++;
                                            if (DateTime.Now >= nextUpdateTime)
                                            {
                                                progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index);
                                                nextUpdateTime = DateTime.Now.AddSeconds(1);
                                            }
                                        }

                                        checkUniqueID(ri, fs);
                                    }
                                }
                                catch
                                {
                                    //error in file after lastOKPosition
                                    fs.SetLength(lastOKPosition);
                                }
                            }

                            _uniqueCheckList.Clear();
                            using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0))
                            {
                                int index = 0;
                                nextUpdateTime = DateTime.MinValue;

                                FileStream fs = _fileCollection._fsLogs;
                                fs.Position = 0;
                                long       lastOKPosition = 0;
                                long       eof            = fs.Length;
                                RecordInfo ri             = new RecordInfo();
                                try
                                {
                                    while (fs.Position < eof)
                                    {
                                        lastOKPosition = fs.Position;
                                        ri.Offset      = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length   = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            ri.FreeSlot = true;
                                            ri.ID       = string.Concat("_", ri.Offset.ToString());
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else if (memBuffer[lsize] == 2)
                                        {
                                            ri.FreeSlot = false;
                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            ri.ID       = br.ReadString();
                                            br.ReadString();
                                            br.ReadString();
                                            br.ReadString();
                                            br.ReadBoolean();
                                        }
                                        else
                                        {
                                            //read
                                            ri.FreeSlot = false;
                                            Framework.Data.Log log = new Framework.Data.Log();

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            log.ID      = br.ReadString();
                                            ri.ID       = log.ID;

                                            log.DataFromDate = DateTime.Parse(br.ReadString());
                                            log.Date         = DateTime.Parse(br.ReadString());
                                            log.Finder       = br.ReadString();
                                            log.GeocacheCode = br.ReadString();
                                            log.ID           = br.ReadString();
                                            log.LogType      = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32());

                                            log.Saved         = true;
                                            log.IsDataChanged = false;

                                            index++;
                                            if (DateTime.Now >= nextUpdateTime)
                                            {
                                                progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index);
                                                nextUpdateTime = DateTime.Now.AddSeconds(1);
                                            }
                                        }
                                        checkUniqueID(ri, fs);
                                    }
                                }
                                catch
                                {
                                    //error in file after lastOKPosition
                                    fs.SetLength(lastOKPosition);
                                }
                            }

                            _uniqueCheckList.Clear();
                            using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0))
                            {
                                int index    = 0;
                                int procStep = 0;

                                using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                                {
                                    fs.Position = 0;
                                    long       eof            = fs.Length;
                                    long       lastOKPosition = 0;
                                    RecordInfo ri             = new RecordInfo();
                                    try
                                    {
                                        while (fs.Position < eof)
                                        {
                                            lastOKPosition = fs.Position;
                                            ri.Offset      = fs.Position;
                                            fs.Read(memBuffer, 0, lsize + 1);
                                            ms.Position = 0;
                                            ri.Length   = br.ReadInt64();
                                            if (memBuffer[lsize] == 0)
                                            {
                                                //free
                                                ri.FreeSlot = true;
                                                ri.ID       = string.Concat("_", ri.Offset.ToString());
                                                fs.Position = ri.Offset + ri.Length;
                                            }
                                            else
                                            {
                                                //read
                                                ri.FreeSlot = false;
                                                Framework.Data.Waypoint wp = new Framework.Data.Waypoint();

                                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                                ms.Position = 0;
                                                wp.Code     = br.ReadString();
                                                ri.ID       = wp.Code;

                                                wp.Comment      = br.ReadString();
                                                wp.DataFromDate = DateTime.Parse(br.ReadString());
                                                wp.Description  = br.ReadString();
                                                wp.GeocacheCode = br.ReadString();
                                                wp.ID           = br.ReadString();
                                                if (br.ReadBoolean())
                                                {
                                                    wp.Lat = br.ReadDouble();
                                                    wp.Lon = br.ReadDouble();
                                                }
                                                wp.Name    = br.ReadString();
                                                wp.Time    = DateTime.Parse(br.ReadString());
                                                wp.Url     = br.ReadString();
                                                wp.UrlName = br.ReadString();
                                                wp.WPType  = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32());

                                                wp.Saved         = true;
                                                wp.IsDataChanged = false;

                                                index++;
                                                procStep++;
                                                if (procStep >= 1000)
                                                {
                                                    progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index);
                                                    procStep = 0;
                                                }
                                            }
                                            checkUniqueID(ri, fs);
                                        }
                                    }
                                    catch
                                    {
                                        //error in file after lastOKPosition
                                        fs.SetLength(lastOKPosition);
                                    }
                                }
                            }

                            _uniqueCheckList.Clear();
                            using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0))
                            {
                                int index    = 0;
                                int procStep = 0;

                                using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                                {
                                    fs.Position = 0;
                                    long       eof            = fs.Length;
                                    long       lastOKPosition = 0;
                                    RecordInfo ri             = new RecordInfo();
                                    try
                                    {
                                        while (fs.Position < eof)
                                        {
                                            lastOKPosition = fs.Position;
                                            ri.Offset      = fs.Position;
                                            fs.Read(memBuffer, 0, lsize + 1);
                                            ms.Position = 0;
                                            ri.Length   = br.ReadInt64();
                                            if (memBuffer[lsize] == 0)
                                            {
                                                //free
                                                ri.FreeSlot = true;
                                                ri.ID       = string.Concat("_", ri.Offset.ToString());
                                                fs.Position = ri.Offset + ri.Length;
                                            }
                                            else
                                            {
                                                //read
                                                ri.FreeSlot = false;
                                                Framework.Data.LogImage li = new Framework.Data.LogImage();

                                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                                ms.Position = 0;
                                                li.ID       = br.ReadString();
                                                ri.ID       = li.ID;

                                                li.DataFromDate = DateTime.Parse(br.ReadString());
                                                li.LogID        = br.ReadString();
                                                li.Name         = br.ReadString();
                                                li.Url          = br.ReadString();

                                                li.Saved         = true;
                                                li.IsDataChanged = false;

                                                index++;
                                                procStep++;
                                                if (procStep >= 1000)
                                                {
                                                    progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index);
                                                    procStep = 0;
                                                }
                                            }
                                            checkUniqueID(ri, fs);
                                        }
                                    }
                                    catch
                                    {
                                        //error in file after lastOKPosition
                                        fs.SetLength(lastOKPosition);
                                    }
                                }
                            }

                            {
                                int index = 0;
                                _uniqueCheckList.Clear();
                                using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                                {
                                    fs.Position = 0;
                                    long       eof            = fs.Length;
                                    long       lastOKPosition = 0;
                                    RecordInfo ri             = new RecordInfo();
                                    try
                                    {
                                        while (fs.Position < eof)
                                        {
                                            lastOKPosition = fs.Position;
                                            ri.Offset      = fs.Position;
                                            fs.Read(memBuffer, 0, lsize + 1);
                                            ms.Position = 0;
                                            ri.Length   = br.ReadInt64();
                                            if (memBuffer[lsize] == 0)
                                            {
                                                //free
                                                ri.FreeSlot = true;
                                                ri.ID       = string.Concat("_", ri.Offset.ToString());
                                                fs.Position = ri.Offset + ri.Length;
                                            }
                                            else
                                            {
                                                //read
                                                ri.FreeSlot = false;
                                                Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint();

                                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                                ms.Position = 0;
                                                ri.ID       = br.ReadString();
                                                wp.ID       = int.Parse(ri.ID);

                                                wp.Description  = br.ReadString();
                                                wp.GeocacheCode = br.ReadString();
                                                wp.Lat          = br.ReadDouble();
                                                wp.Lon          = br.ReadDouble();
                                                wp.Date         = DateTime.Parse(br.ReadString());

                                                wp.Saved         = true;
                                                wp.IsDataChanged = false;

                                                index++;
                                            }
                                            checkUniqueID(ri, fs);
                                        }
                                    }
                                    catch
                                    {
                                        //error in file after lastOKPosition
                                        fs.SetLength(lastOKPosition);
                                    }
                                }
                            }
                        }
                    }
            }

            return(result);
        }
Пример #4
0
    private void threadMethod()
    {
        try
        {
            bool cancel = false;
            using (ProgressBlock progress = new ProgressBlock(_plugin, "Bijwerken van status en nieuwe geocaches", "Download gegevens van globalcaching.eu", 1, 0, true))
            {
                using (System.Net.WebClient wc = new System.Net.WebClient())
                {
                    string doc = wc.DownloadString(string.Format("http://www.globalcaching.eu/Service/GeocacheCodes.aspx?country=Belgium&token={0}", System.Web.HttpUtility.UrlEncode(_core.GeocachingComAccount.APIToken)));
                    if (doc != null)
                    {
                        List <string> gcList = new List <string>();

                        string[] lines = doc.Replace("\r", "").Split(new char[] { '\n' });
                        progress.UpdateProgress("Bijwerken van status en nieuwe geocaches", "Bijwerken van de status...", lines.Length, 0);
                        Geocache gc;
                        char[]   sep = new char[] { ',' };
                        string[] parts;
                        foreach (string s in lines)
                        {
                            parts = s.Split(sep);
                            if (parts.Length > 2)
                            {
                                gc = DataAccess.GetGeocache(_core.Geocaches, parts[0]);
                                if (gc != null)
                                {
                                    gc.Archived  = parts[1] != "0";
                                    gc.Available = parts[2] != "0";
                                }
                                else if (parts[1] == "0") //add only none archived
                                {
                                    gcList.Add(parts[0]);
                                }
                            }
                        }

                        if (gcList.Count == 0)
                        {
                            System.Windows.Forms.MessageBox.Show("Er zijn geen nieuwe geocaches gevonden", "Bericht", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                        }
                        else
                        {
                            if (System.Windows.Forms.MessageBox.Show(string.Format("Er zijn {0} nieuwe geocaches gevonden\r\nDeze downloaden?", gcList.Count), "Bericht", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Yes)
                            {
                                progress.UpdateProgress("Bijwerken van status en nieuwe geocaches", "Importeren van geocaches...", gcList.Count, 0);

                                using (GeocachingLiveV6 client = new GeocachingLiveV6(_core, string.IsNullOrEmpty(_core.GeocachingComAccount.APIToken)))
                                {
                                    int      index = 0;
                                    int      total = gcList.Count;
                                    int      gcupdatecount;
                                    TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100);
                                    DateTime prevCall = DateTime.MinValue;
                                    bool     dodelay;
                                    gcupdatecount = 30;
                                    dodelay       = (gcList.Count > 30);
                                    while (gcList.Count > 0)
                                    {
                                        if (dodelay)
                                        {
                                            TimeSpan ts = DateTime.Now - prevCall;
                                            if (ts < interval)
                                            {
                                                Thread.Sleep(interval - ts);
                                            }
                                        }
                                        GlobalcachingApplication.Utils.API.LiveV6.SearchForGeocachesRequest req = new GlobalcachingApplication.Utils.API.LiveV6.SearchForGeocachesRequest();
                                        req.IsLite               = false;
                                        req.AccessToken          = client.Token;
                                        req.CacheCode            = new GlobalcachingApplication.Utils.API.LiveV6.CacheCodeFilter();
                                        req.CacheCode.CacheCodes = (from a in gcList select a).Take(gcupdatecount).ToArray();
                                        req.MaxPerPage           = gcupdatecount;
                                        req.GeocacheLogCount     = 5;
                                        index += req.CacheCode.CacheCodes.Length;
                                        gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length);
                                        prevCall = DateTime.Now;
                                        var resp = client.Client.SearchForGeocaches(req);
                                        if (resp.Status.StatusCode == 0 && resp.Geocaches != null)
                                        {
                                            Import.AddGeocaches(_core, resp.Geocaches);
                                        }
                                        else
                                        {
                                            _errormessage = resp.Status.StatusMessage;
                                            break;
                                        }
                                        if (!progress.UpdateProgress("Bijwerken van status en nieuwe geocaches", "Importeren van geocaches...", total, index))
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            _errormessage = e.Message;
        }
        _actionReady.Set();
    }
    public static bool Run(Plugin plugin, ICore core)
    {
        int[,] DTMatrix = new int[9, 9];
        int numMissing = 9 * 9;
        int count      = 0;
        int prog       = 0;

        List <Geocache> gcList = null;

        gcList = DataAccess.GetFoundGeocaches(core.Geocaches, core.Logs, core.GeocachingComAccount);

        using (ProgressBlock progress = new ProgressBlock(plugin,
                                                          "Creating S/T Matrix", "Seeking for Neo", gcList.Count, 0))
        {
            foreach (Geocache gc in gcList)
            {
                int ixD = (int)(gc.Difficulty * 2 + 0.001) - 2;
                int ixT = (int)(gc.Terrain * 2 + 0.001) - 2;
                //range checking is for cowards!
                if (DTMatrix[ixD, ixT] == 0)
                {
                    numMissing--;
                }
                DTMatrix[ixD, ixT]++;

                prog++;
                if (prog % 10 == 0)
                {
                    progress.UpdateProgress("Creating S/T Matrix", "Seeking for Neo", gcList.Count, prog);
                }
            }
        }

        prog = 0;
        using (ProgressBlock progress = new ProgressBlock(plugin,
                                                          "Selecting Caches", "", core.Geocaches.Count, 0))
        {
            //reset current selection
            foreach (Geocache gc in core.Geocaches)
            {
                int ixD = (int)(gc.Difficulty * 2 + 0.001) - 2;
                int ixT = (int)(gc.Terrain * 2 + 0.001) - 2;

                gc.Selected = (DTMatrix[ixD, ixT] == 0);
                if (DTMatrix[ixD, ixT] == 0)
                {
                    count++;
                }
                prog++;
                if (prog % 50 == 0)
                {
                    progress.UpdateProgress("Selecting Caches", "", core.Geocaches.Count, prog);
                }
            }
        }

        System.Windows.Forms.MessageBox.Show("Selected: " + count.ToString() +
                                             "; Missing combinations in D/T Matrix: " + numMissing.ToString() +
                                             " of " + gcList.Count.ToString() + " found Geocaches.");

        return(true);
    }
    public static bool Run(Plugin plugin, ICore core)
    {
        string baseSite    = "http://xylanthrop.de/";
        string promptValue = MyURLPrompt.ShowDialog(baseSite, "2 Select a count(r)y to update the archived caches:", "Update Archived Caches from xylanthrop.de");

//        System.Windows.Forms.MessageBox.Show("promptValue: "+promptValue);
        if (promptValue != "")
        {
            //get page
            using (System.Net.WebClient wc = new System.Net.WebClient()) {
                string html = wc.DownloadString(baseSite + promptValue);
                int    prog;
                int    numgc  = 0;
                int    updc   = 0;
                int    foundc = 0;
                int    nonarc = 0;//counter for caches "not" archived
                //parse GC-Codes from links
                Regex           rgc = new Regex(@"<waypoint>(GC[A-Z0-9]*)<.*?<archived>([^<]*)<", RegexOptions.Singleline);
                MatchCollection mc  = rgc.Matches(html);
                StringBuilder   gcs = new StringBuilder();

                prog = 0;
                using (ProgressBlock progress = new ProgressBlock(plugin,
                                                                  "Retrieving GC-Codes", "", mc.Count, 0))
                {
                    foreach (Match m in mc)
                    {
                        if (m.Groups[2].Value == "archived")
                        {
                            gcs.Append(m.Groups[1].Value);
                            gcs.Append(" ");
                        }
                        else
                        {
                            nonarc++;
                        }
                        prog++;
                        if (prog % 10 == 0)
                        {
                            progress.UpdateProgress("Retrieving GC-Codes", "", mc.Count, prog);
                        }
                    }
                    numgc = prog;
                }

                if (numgc > 0)
                {
                    string gcstr = gcs.ToString();//searchable string of gc-codes
                    prog = 0;
                    core.Geocaches.BeginUpdate();

                    using (ProgressBlock progress = new ProgressBlock(plugin,
                                                                      "Updating Caches", "", core.Geocaches.Count, 0))
                    {
                        foreach (Geocache gc in core.Geocaches)
                        {
                            if (gc.Code != "")
                            {
                                if (gcstr.IndexOf(gc.Code + " ") >= 0)
                                {
                                    foundc++;
                                    if (!gc.Archived)
                                    {
                                        updc++;
                                        gc.Archived  = true;//Set Cache to Archived state
                                        gc.Available = false;
                                    }
                                }
                            }
                            prog++;
                            if (prog % 100 == 0)
                            {
                                progress.UpdateProgress("Updating Caches", String.Format("Found: {0}", updc), core.Geocaches.Count, prog);
                            }
                        }
                    }
                    core.Geocaches.EndUpdate();
                }
                System.Windows.Forms.MessageBox.Show(
                    "Update completed:\r" +
                    "Source URL: " + promptValue + "\r" +
                    String.Format("#Caches on page: {0}\r", numgc) +
                    String.Format("#Caches found in DB: {0}\r", foundc) +
                    String.Format("#Caches updated: {0}\r", updc) +
                    String.Format("#Caches non archived in src: {0}", nonarc));
                //System.Windows.Forms.MessageBox.Show("Val: "+html);
            }
        }
        //System.Windows.Forms.MessageBox.Show("Val: "+promptValue);
        return(true);
    }
Пример #7
0
        private bool insertFromDatabase(bool overwrite)
        {
            bool result = false;

            try
            {
                int    lsize     = sizeof(long);
                byte[] memBuffer = new byte[10 * 1024 * 1024];
                using (MemoryStream ms = new MemoryStream(memBuffer))
                    using (BinaryReader br = new BinaryReader(ms))
                        using (FileCollection fc = new FileCollection(_selectedInsertFromFilename))
                        {
                            int gcCount          = 0;
                            int logCount         = 0;
                            int logimgCount      = 0;
                            int geocacheimgCount = 0;
                            int wptCount         = 0;
                            int usrwptCount      = 0;

                            Hashtable htInsertedGeocaches = new Hashtable();
                            Hashtable htInsertedLogs      = new Hashtable();

                            XmlDocument doc = new XmlDocument();
                            doc.Load(fc.DatabaseInfoFilename);
                            XmlElement root = doc.DocumentElement;
                            gcCount     = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText);
                            logCount    = int.Parse(root.SelectSingleNode("LogCount").InnerText);
                            logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText);
                            wptCount    = int.Parse(root.SelectSingleNode("WaypointCount").InnerText);
                            usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText);
                            if (root.SelectSingleNode("GeocacheImagesCount") != null)
                            {
                                geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText);
                            }

                            DateTime   nextUpdateTime = DateTime.MinValue;
                            RecordInfo ri             = new RecordInfo();
                            using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0))
                            {
                                using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0))
                                {
                                    int index = 0;

                                    FileStream fs = fc._fsGeocaches;
                                    fs.Position = 0;
                                    long eof = fs.Length;
                                    while (fs.Position < eof)
                                    {
                                        ri.Offset = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length   = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            //ignore
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else if (memBuffer[lsize] == 2)
                                        {
                                            //read
                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            ri.ID       = br.ReadString().Substring(2);
                                            bool newGeocache;
                                            Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID);
                                            if (gc == null)
                                            {
                                                gc = new Framework.Data.Geocache();
                                                htInsertedGeocaches.Add(ri.ID, gc);
                                                newGeocache = true;
                                            }
                                            else
                                            {
                                                if (overwrite || htInsertedGeocaches[ri.ID] != null)
                                                {
                                                    newGeocache = false;
                                                }
                                                else
                                                {
                                                    continue;
                                                }
                                            }
                                            gc.BeginUpdate();
                                            try
                                            {
                                                gc.Code                   = ri.ID;
                                                gc.ShortDescription       = br.ReadString();
                                                gc.ShortDescriptionInHtml = br.ReadBoolean();
                                                gc.LongDescription        = br.ReadString();
                                                gc.LongDescriptionInHtml  = br.ReadBoolean();
                                            }
                                            catch
                                            {
                                            }
                                            gc.EndUpdate();
                                            if (newGeocache)
                                            {
                                                Core.Geocaches.Add(gc);
                                            }
                                        }
                                        else
                                        {
                                            //read

                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            ri.ID       = br.ReadString();

                                            bool newGeocache;
                                            Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID);
                                            if (gc == null)
                                            {
                                                gc = new Framework.Data.Geocache();
                                                htInsertedGeocaches.Add(ri.ID, gc);
                                                newGeocache = true;
                                            }
                                            else
                                            {
                                                if (overwrite || htInsertedGeocaches[ri.ID] != null)
                                                {
                                                    newGeocache = false;
                                                }
                                                else
                                                {
                                                    continue;
                                                }
                                            }
                                            gc.BeginUpdate();
                                            try
                                            {
                                                gc.Code         = ri.ID;
                                                gc.Archived     = br.ReadBoolean();
                                                gc.AttributeIds = ReadIntegerArray(br);
                                                gc.Available    = br.ReadBoolean();
                                                gc.City         = br.ReadString();
                                                gc.Container    = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32());
                                                gc.CustomCoords = br.ReadBoolean();
                                                gc.Country      = br.ReadString();
                                                if (br.ReadBoolean())
                                                {
                                                    gc.CustomLat = br.ReadDouble();
                                                    gc.CustomLon = br.ReadDouble();
                                                }
                                                gc.Difficulty    = br.ReadDouble();
                                                gc.EncodedHints  = br.ReadString();
                                                gc.Favorites     = br.ReadInt32();
                                                gc.Flagged       = br.ReadBoolean();
                                                gc.Found         = br.ReadBoolean();
                                                gc.GeocacheType  = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32());
                                                gc.ID            = br.ReadString();
                                                gc.Lat           = br.ReadDouble();
                                                gc.Lon           = br.ReadDouble();
                                                gc.MemberOnly    = br.ReadBoolean();
                                                gc.Municipality  = br.ReadString();
                                                gc.Name          = br.ReadString();
                                                gc.Notes         = br.ReadString();
                                                gc.Owner         = br.ReadString();
                                                gc.OwnerId       = br.ReadString();
                                                gc.PersonaleNote = br.ReadString();
                                                gc.PlacedBy      = br.ReadString();
                                                gc.PublishedTime = DateTime.Parse(br.ReadString());
                                                gc.State         = br.ReadString();
                                                gc.Terrain       = br.ReadDouble();
                                                gc.Title         = br.ReadString();
                                                gc.Url           = br.ReadString();
                                                gc.DataFromDate  = DateTime.Parse(br.ReadString());
                                                gc.Locked        = br.ReadBoolean();

                                                Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation);
                                            }
                                            catch
                                            {
                                            }
                                            gc.EndUpdate();

                                            if (newGeocache)
                                            {
                                                Core.Geocaches.Add(gc);
                                            }

                                            index++;
                                            if (DateTime.Now >= nextUpdateTime)
                                            {
                                                progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index);
                                                nextUpdateTime = DateTime.Now.AddSeconds(1);
                                            }
                                        }
                                    }
                                }

                                using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0))
                                {
                                    int index = 0;
                                    nextUpdateTime = DateTime.MinValue;

                                    FileStream fs = fc._fsLogs;
                                    fs.Position = 0;
                                    long eof = fs.Length;
                                    while (fs.Position < eof)
                                    {
                                        ri.Offset = fs.Position;
                                        fs.Read(memBuffer, 0, lsize + 1);
                                        ms.Position = 0;
                                        ri.Length   = br.ReadInt64();
                                        if (memBuffer[lsize] == 0)
                                        {
                                            //free
                                            fs.Position = ri.Offset + ri.Length;
                                        }
                                        else if (memBuffer[lsize] == 2)
                                        {
                                            //read
                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            ri.ID       = br.ReadString().Substring(2);
                                            fs.Position = ri.Offset + ri.Length;

                                            bool newLog;
                                            bool logComplete       = true;
                                            Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID);
                                            if (log == null)
                                            {
                                                newLog = true;
                                                log    = htInsertedLogs[ri.ID] as Framework.Data.Log;
                                                if (log == null)
                                                {
                                                    log = new Framework.Data.Log();
                                                    htInsertedLogs.Add(ri.ID, log);
                                                    logComplete = false;
                                                }
                                                else
                                                {
                                                    logComplete = true;
                                                }
                                            }
                                            else
                                            {
                                                if (overwrite)
                                                {
                                                    newLog = false;
                                                }
                                                else
                                                {
                                                    continue;
                                                }
                                            }
                                            log.BeginUpdate();
                                            try
                                            {
                                                log.ID       = ri.ID;
                                                log.TBCode   = br.ReadString();
                                                log.FinderId = br.ReadString();
                                                log.Text     = br.ReadString();
                                                log.Encoded  = br.ReadBoolean();
                                            }
                                            catch
                                            {
                                            }
                                            log.EndUpdate();
                                            if (newLog && logComplete && htInsertedLogs[ri.ID] != null)
                                            {
                                                if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null)
                                                {
                                                    Core.Logs.Add(log);
                                                }
                                                htInsertedLogs.Remove(ri.ID);
                                            }
                                        }
                                        else
                                        {
                                            //read
                                            fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                            ms.Position = 0;
                                            ri.ID       = br.ReadString();

                                            bool newLog;
                                            bool logComplete       = true;
                                            Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID);
                                            if (log == null)
                                            {
                                                newLog = true;
                                                log    = htInsertedLogs[ri.ID] as Framework.Data.Log;
                                                if (log == null)
                                                {
                                                    log = new Framework.Data.Log();
                                                    htInsertedLogs.Add(ri.ID, log);
                                                    logComplete = false;
                                                }
                                                else
                                                {
                                                    logComplete = true;
                                                }
                                            }
                                            else
                                            {
                                                if (overwrite)
                                                {
                                                    newLog = false;
                                                }
                                                else
                                                {
                                                    continue;
                                                }
                                            }
                                            log.BeginUpdate();
                                            try
                                            {
                                                log.ID           = ri.ID;
                                                log.DataFromDate = DateTime.Parse(br.ReadString());
                                                log.Date         = DateTime.Parse(br.ReadString());
                                                log.Finder       = br.ReadString();
                                                log.GeocacheCode = br.ReadString();
                                                log.ID           = br.ReadString();
                                                log.LogType      = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32());
                                            }
                                            catch
                                            {
                                            }
                                            log.EndUpdate();

                                            if (newLog && logComplete && htInsertedLogs[ri.ID] != null)
                                            {
                                                //check if geocache is present
                                                if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null)
                                                {
                                                    Core.Logs.Add(log);
                                                }
                                                htInsertedLogs.Remove(ri.ID);
                                            }

                                            index++;
                                            if (DateTime.Now >= nextUpdateTime)
                                            {
                                                progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index);
                                                nextUpdateTime = DateTime.Now.AddSeconds(1);
                                            }
                                        }
                                    }
                                }


                                using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0))
                                {
                                    int index    = 0;
                                    int procStep = 0;

                                    using (FileStream fs = File.Open(fc.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                                    {
                                        fs.Position = 0;
                                        long eof = fs.Length;
                                        while (fs.Position < eof)
                                        {
                                            ri.Offset = fs.Position;
                                            fs.Read(memBuffer, 0, lsize + 1);
                                            ms.Position = 0;
                                            ri.Length   = br.ReadInt64();
                                            if (memBuffer[lsize] == 0)
                                            {
                                                //free
                                                fs.Position = ri.Offset + ri.Length;
                                            }
                                            else
                                            {
                                                //read
                                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                                ms.Position = 0;
                                                ri.ID       = br.ReadString();

                                                bool newWp;
                                                Framework.Data.Waypoint wp = Utils.DataAccess.GetWaypoint(Core.Waypoints, ri.ID);
                                                if (wp == null)
                                                {
                                                    newWp = true;
                                                    wp    = new Framework.Data.Waypoint();
                                                }
                                                else
                                                {
                                                    if (overwrite)
                                                    {
                                                        newWp = false;
                                                    }
                                                    else
                                                    {
                                                        continue;
                                                    }
                                                }

                                                wp.BeginUpdate();
                                                try
                                                {
                                                    wp.Code         = ri.ID;
                                                    wp.Comment      = br.ReadString();
                                                    wp.DataFromDate = DateTime.Parse(br.ReadString());
                                                    wp.Description  = br.ReadString();
                                                    wp.GeocacheCode = br.ReadString();
                                                    wp.ID           = br.ReadString();
                                                    if (br.ReadBoolean())
                                                    {
                                                        wp.Lat = br.ReadDouble();
                                                        wp.Lon = br.ReadDouble();
                                                    }
                                                    wp.Name    = br.ReadString();
                                                    wp.Time    = DateTime.Parse(br.ReadString());
                                                    wp.Url     = br.ReadString();
                                                    wp.UrlName = br.ReadString();
                                                    wp.WPType  = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32());
                                                }
                                                catch
                                                {
                                                }
                                                wp.EndUpdate();
                                                if (newWp)
                                                {
                                                    if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null)
                                                    {
                                                        Core.Waypoints.Add(wp);
                                                    }
                                                }

                                                index++;
                                                procStep++;
                                                if (procStep >= 1000)
                                                {
                                                    progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index);
                                                    procStep = 0;
                                                }
                                            }
                                        }
                                    }
                                }

                                using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0))
                                {
                                    int index    = 0;
                                    int procStep = 0;

                                    using (FileStream fs = File.Open(fc.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read))
                                    {
                                        fs.Position = 0;
                                        long eof = fs.Length;
                                        while (fs.Position < eof)
                                        {
                                            ri.Offset = fs.Position;
                                            fs.Read(memBuffer, 0, lsize + 1);
                                            ms.Position = 0;
                                            ri.Length   = br.ReadInt64();
                                            if (memBuffer[lsize] == 0)
                                            {
                                                //free
                                                fs.Position = ri.Offset + ri.Length;
                                            }
                                            else
                                            {
                                                //read
                                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                                ms.Position = 0;
                                                ri.ID       = br.ReadString();

                                                bool newWp;
                                                Framework.Data.LogImage li = Utils.DataAccess.GetLogImage(Core.LogImages, ri.ID);
                                                if (li == null)
                                                {
                                                    newWp = true;
                                                    li    = new Framework.Data.LogImage();
                                                }
                                                else
                                                {
                                                    if (overwrite)
                                                    {
                                                        newWp = false;
                                                    }
                                                    else
                                                    {
                                                        continue;
                                                    }
                                                }

                                                li.BeginUpdate();
                                                try
                                                {
                                                    li.ID           = ri.ID;
                                                    li.DataFromDate = DateTime.Parse(br.ReadString());
                                                    li.LogID        = br.ReadString();
                                                    li.Name         = br.ReadString();
                                                    li.Url          = br.ReadString();
                                                }
                                                catch
                                                {
                                                }
                                                li.EndUpdate();

                                                if (newWp)
                                                {
                                                    if (Utils.DataAccess.GetLog(Core.Logs, li.LogID ?? "") != null)
                                                    {
                                                        Core.LogImages.Add(li);
                                                    }
                                                }

                                                index++;
                                                procStep++;
                                                if (procStep >= 1000)
                                                {
                                                    progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index);
                                                    procStep = 0;
                                                }
                                            }
                                        }
                                    }
                                }

                                using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0))
                                {
                                    int index    = 0;
                                    int procStep = 0;

                                    using (FileStream fs = File.Open(fc.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read))
                                    {
                                        fs.Position = 0;
                                        long eof = fs.Length;
                                        while (fs.Position < eof)
                                        {
                                            ri.Offset = fs.Position;
                                            fs.Read(memBuffer, 0, lsize + 1);
                                            ms.Position = 0;
                                            ri.Length   = br.ReadInt64();
                                            if (memBuffer[lsize] == 0)
                                            {
                                                //free
                                                fs.Position = ri.Offset + ri.Length;
                                            }
                                            else
                                            {
                                                //read
                                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                                ms.Position = 0;
                                                ri.ID       = br.ReadString();

                                                bool newWp;
                                                Framework.Data.GeocacheImage wp = Utils.DataAccess.GetGeocacheImage(Core.GeocacheImages, ri.ID);
                                                if (wp == null)
                                                {
                                                    newWp = true;
                                                    wp    = new Framework.Data.GeocacheImage();
                                                }
                                                else
                                                {
                                                    if (overwrite)
                                                    {
                                                        newWp = false;
                                                    }
                                                    else
                                                    {
                                                        continue;
                                                    }
                                                }

                                                wp.BeginUpdate();
                                                try
                                                {
                                                    wp.ID           = ri.ID;
                                                    wp.DataFromDate = DateTime.Parse(br.ReadString());
                                                    wp.GeocacheCode = br.ReadString();
                                                    wp.Description  = br.ReadString();
                                                    wp.Name         = br.ReadString();
                                                    wp.Url          = br.ReadString();
                                                    wp.MobileUrl    = br.ReadString();
                                                    wp.ThumbUrl     = br.ReadString();
                                                }
                                                catch
                                                {
                                                }
                                                wp.EndUpdate();
                                                if (newWp)
                                                {
                                                    if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null)
                                                    {
                                                        Core.GeocacheImages.Add(wp);
                                                    }
                                                }

                                                index++;
                                                procStep++;
                                                if (procStep >= 1000)
                                                {
                                                    progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index);
                                                    procStep = 0;
                                                }
                                            }
                                        }
                                    }
                                }

                                {
                                    using (FileStream fs = File.Open(fc.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read))
                                    {
                                        fs.Position = 0;
                                        long eof = fs.Length;
                                        while (fs.Position < eof)
                                        {
                                            ri.Offset = fs.Position;
                                            fs.Read(memBuffer, 0, lsize + 1);
                                            ms.Position = 0;
                                            ri.Length   = br.ReadInt64();
                                            if (memBuffer[lsize] == 0)
                                            {
                                                //free
                                                fs.Position = ri.Offset + ri.Length;
                                            }
                                            else
                                            {
                                                //read
                                                fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1));
                                                ms.Position = 0;
                                                ri.ID       = br.ReadString();

                                                bool newWp;
                                                Framework.Data.UserWaypoint wp = Utils.DataAccess.GetUserWaypoint(Core.UserWaypoints, int.Parse(ri.ID));
                                                if (wp == null)
                                                {
                                                    newWp = true;
                                                    wp    = new Framework.Data.UserWaypoint();
                                                }
                                                else
                                                {
                                                    if (overwrite)
                                                    {
                                                        newWp = false;
                                                    }
                                                    else
                                                    {
                                                        continue;
                                                    }
                                                }

                                                wp.BeginUpdate();
                                                try
                                                {
                                                    wp.ID           = int.Parse(ri.ID);
                                                    wp.Description  = br.ReadString();
                                                    wp.GeocacheCode = br.ReadString();
                                                    wp.Lat          = br.ReadDouble();
                                                    wp.Lon          = br.ReadDouble();
                                                    wp.Date         = DateTime.Parse(br.ReadString());
                                                }
                                                catch
                                                {
                                                }
                                                if (newWp)
                                                {
                                                    if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null)
                                                    {
                                                        Core.UserWaypoints.Add(wp);
                                                    }
                                                }

                                                wp.EndUpdate();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                result = true;
            }
            catch
            {
            }
            return(result);
        }