protected virtual bool AddLog(Framework.Data.Log l) { bool result = false; Framework.Data.Log oldwp = Utils.DataAccess.GetLog(Core.Logs, l.ID); if (oldwp == null) { Core.Logs.Add(l); result = true; } else { if (l.DataFromDate >= oldwp.DataFromDate) { Utils.DataAccess.UpdateLogData(oldwp, l); } } if (l.LogType.AsFound && Core.GeocachingAccountNames.GetAccountName(l.GeocacheCode).ToLower() == l.Finder.ToLower()) { //found Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, l.GeocacheCode); if (gc != null) { gc.Found = true; } } return(result); }
protected virtual bool AddLog(Framework.Data.Log l) { bool result = false; if (_logsEmpty) { Core.Logs.Add(l); result = true; } else { Framework.Data.Log oldwp = Utils.DataAccess.GetLog(Core.Logs, l.ID); if (oldwp == null) { Core.Logs.Add(l); result = true; } else { if (l.DataFromDate >= l.DataFromDate) { Utils.DataAccess.UpdateLogData(oldwp, l); } } } return(result); }
public static Framework.Data.Log Log(Framework.Interfaces.ICore core, OKAPIService.Log lg, string finder, string finderId) { Framework.Data.Log result = null; if (lg != null) { Framework.Data.Log tmp = Utils.DataAccess.GetLog(core.Logs, lg.cache_code); result = new Framework.Data.Log(); if (tmp != null) { result.UpdateFrom(tmp); } result.DataFromDate = DateTime.Now; result.Date = DateTime.Parse(lg.date); result.Encoded = false; if (lg.user == null) { result.Finder = finder; result.FinderId = finderId; } else { result.Finder = lg.user.username; result.FinderId = lg.user.uuid; } result.GeocacheCode = lg.cache_code; result.ID = lg.uuid; result.Text = lg.comment; result.LogType = Utils.DataAccess.GetLogType(core.LogTypes, lg.type); } return(result); }
public static bool AddLog(Framework.Interfaces.ICore core, Framework.Data.Log l) { bool result = false; Framework.Data.Log oldwp = DataAccess.GetLog(core.Logs, l.ID); if (oldwp == null) { core.Logs.Add(l); result = true; } else { if (l.DataFromDate >= oldwp.DataFromDate) { DataAccess.UpdateLogData(oldwp, l); } } if (l.LogType.AsFound && core.GeocachingAccountNames.GetAccountName(l.GeocacheCode).ToLower() == l.Finder.ToLower()) { //found Framework.Data.Geocache gc = DataAccess.GetGeocache(core.Geocaches, l.GeocacheCode); if (gc != null) { gc.Found = true; } } return(result); }
public void OnLogRemoved(Framework.Data.Log wp) { if (!_updating && LogRemoved != null) { LogRemoved(this, new Framework.EventArguments.LogEventArgs(wp)); } OnListDataChanged(); }
public override void Remove(object value) { Framework.Data.Log wp = value as Framework.Data.Log; if (wp != null) { RemoveAt(IndexOf(wp)); } }
public void OnDataChanged(Framework.Data.Log wp) { _dataChanged = true; if (!_updating && DataChanged != null) { DataChanged(this, new Framework.EventArguments.LogEventArgs(wp)); _dataChanged = false; wp.IsDataChanged = false; } }
public static bool UpdateLogData(Framework.Data.Log l, Framework.Data.Log newData) { bool result = false; if (l.ID == newData.ID) { l.UpdateFrom(newData); result = true; } return(result); }
public static void DeleteLog(Framework.Interfaces.ICore core, Framework.Data.Log log) { core.Logs.BeginUpdate(); core.LogImages.BeginUpdate(); List <Framework.Data.LogImage> limgs = GetLogImages(core.LogImages, log.ID); foreach (Framework.Data.LogImage li in limgs) { core.LogImages.Remove(li); } core.Logs.Remove(log); core.LogImages.EndUpdate(); core.Logs.EndUpdate(); }
public override void RemoveAt(int index) { if (index >= 0 && index < Count) { Framework.Data.Log wp = this[index] as Framework.Data.Log; //grouping (_logGroups[wp.GeocacheCode ?? ""] as Hashtable).Remove(wp.ID); //end grouping _qaItems.Remove(wp.ID); wp.DataChanged -= new EventArguments.LogEventHandler(gc_DataChanged); wp.LoadFullData -= new EventArguments.LoadFullLogEventHandler(wp_LoadFullData); base.RemoveAt(index); OnLogRemoved(wp); } }
void logList_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { button2.Enabled = (logViewControl1.logList.SelectedItems != null && logViewControl1.logList.SelectedItems.Count > 0); if (radioButton2.Checked) { if (logViewControl1.logList.SelectedItem != null) { Framework.Data.Log l = logViewControl1.logList.SelectedItem as Framework.Data.Log; if (l != null && l.GeocacheCode != null) { Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, l.GeocacheCode); if (gc != null) { Core.ActiveGeocache = gc; } } } } }
public static List <Framework.Data.Geocache> AddGeocaches(Framework.Interfaces.ICore core, List <OKAPIService.Geocache> gcList) { List <Framework.Data.Geocache> result = new List <Framework.Data.Geocache>(); if (gcList != null) { foreach (var gcApi in gcList) { Framework.Data.Geocache activeGC = Convert.Geocache(core, gcApi); if (Utils.API.Import.AddGeocache(core, activeGC)) { if (gcApi.latest_logs != null) { foreach (var l in gcApi.latest_logs) { Framework.Data.Log lg = Convert.Log(core, l, "", ""); Utils.API.Import.AddLog(core, lg); } } if (gcApi.alt_wpts != null) { foreach (var wp in gcApi.alt_wpts) { Utils.API.Import.AddWaypoint(core, Convert.Waypoint(core, wp)); } } if (gcApi.images != null) { foreach (var imgd in gcApi.images) { Utils.API.Import.AddGeocacheImage(core, Convert.GeocacheImage(core, imgd, activeGC.Code)); } } } } } return(result); }
public static Framework.Data.Log Log(Framework.Interfaces.ICore core, LiveV6.GeocacheLog lg) { Framework.Data.Log result = null; if (lg != null) { Framework.Data.Log tmp = DataAccess.GetLog(core.Logs, lg.Code); result = new Framework.Data.Log(); if (tmp != null) { result.UpdateFrom(tmp); } result.DataFromDate = DateTime.Now; result.Date = lg.VisitDate; result.Encoded = lg.LogIsEncoded; result.Finder = lg.Finder.UserName; result.FinderId = lg.Finder.Id.ToString(); result.GeocacheCode = lg.CacheCode; result.ID = lg.Code; result.LogType = DataAccess.GetLogType(core.LogTypes, (int)lg.LogType.WptLogTypeId); result.Text = lg.LogText; } return(result); }
public override int Add(object value) { int result; Framework.Data.Log wp = value as Framework.Data.Log; if (wp != null) { _qaItems[wp.ID] = wp; //grouping if (_logGroups[wp.GeocacheCode ?? ""] == null) { _logGroups[wp.GeocacheCode ?? ""] = new Hashtable(); } (_logGroups[wp.GeocacheCode ?? ""] as Hashtable)[wp.ID] = wp; //end grouping _sorted = false; result = base.Add(wp); wp.DataChanged += new EventArguments.LogEventHandler(gc_DataChanged); wp.LoadFullData += new EventArguments.LoadFullLogEventHandler(wp_LoadFullData); OnLogAdded(wp); } else { //for now, only supported between begin and end update List <Log> lgs = value as List <Log>; if (lgs != null) { _batchAddition = lgs; result = 0; } else { result = -1; } } return(result); }
public void UpdateView() { listView1.Items.Clear(); if (Core.ActiveGeocache != null) { List <Framework.Data.LogImage> logImages = Utils.DataAccess.GetLogImages(Core.LogImages, Core.Logs, Core.ActiveGeocache.Code); foreach (var li in logImages) { Framework.Data.Log l = Core.Logs.GetLog(li.LogID); if (l != null) { ListViewItem lvi = new ListViewItem(new string[] { l.Date.ToString("yyyy-MM-dd"), li.Name ?? "" }); lvi.Tag = li; listView1.Items.Add(lvi); } } } checkImageToLoad(this, EventArgs.Empty); checkSlideshowTimer(); if (timerSlideShow.Enabled) { timerSlideShow_Tick(this, EventArgs.Empty); } }
protected override void ImportMethod() { /* * [{"latitude":"52.383607", * "longitude":"4.641646", * "created_at":"2012-05-15 07:02:53", * "deployed_at":"2013-03-16 05:15:56", * "notes":"hint: bankje", * "friendly_name":"NN# 147. Molen de Adriaan", * "location":", ", * "username":"******", * "code":"147", * "capture_type_id":"http:\/\/www.munzee.com\/images\/pins\/munzee.png", * "special_logo":"", * "updated":"1365761293", * "archived":"0", * "type":"", * "country":"The Netherlands", * "region":"", * "country_2":null, * "region_2":null, * "munzee_id":"233744", * "owned":"0", * "captured":"0", * "captured_at":null, * "special":"0"} * * * * {"latitude":"52.234168", * "longitude":"5.185743", * "created_at":"2012-11-17 15:41:03", * "deployed_at":"2012-11-18 06:06:29", * "notes":"Hint: geel\n\nHeilig Hartkerk - Heilig Joseph kerk \nDeze kerk werd in 1928 ontworpen door H.W. Valk, die behoorde tot de traditionalistische stroming in de architectuur. Het gebouw kenmerkt zich door zijn robuuste bakstenen bouw en de combinatie van gotische en romaanse stijlelementen.\n\nHet was de eerste rooms-katholieke kerk in de arbeiderswijk Over het Spoor. Dat leidde in het begin nog wel eens tot uitingen van ongenoegen zoals het bekladden van de muren. Het interieur is sober. De imposante apostelkoppen van J. Cantre vormen de belangrijkste decoraties. Hij ontwierp ook het H. Hartbeeld aan de achterzijde. De gebrandschilderde ramen zijn van J. Nicolas.", * "friendly_name":"Heilig Hartkerk", * "location":"Hilversum, North Holland The Netherlands", * "username":"******", * "code":"65", * "capture_type_id":"http:\/\/www.munzee.com\/images\/pins\/munzee.png", * "special_logo":"", * "updated":"1365761293", * "archived":"0", * "type":"", //virtual * "country":"The Netherlands", * "region":"", * "country_2":null, * "region_2":null, * "munzee_id":"486901", * "owned":"0", * "captured":"0", //"captured":"1" * "captured_at":null, //"captured_at":"1364119020" * "special":"0"} * */ using (Utils.ProgressBlock fixpr = new Utils.ProgressBlock(this, STR_IMPORTING, STR_DOWNLOADINGDATA, 1, 0)) { int index = 0; MunzeeDataList munzl; try { System.Net.HttpWebRequest webRequest; webRequest = System.Net.WebRequest.Create(_selectedUrl) as System.Net.HttpWebRequest; webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.17 Safari/533.4"; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(MunzeeDataList)); using (System.IO.Stream stream = webRequest.GetResponse().GetResponseStream()) { munzl = ser.ReadObject(stream) as MunzeeDataList; } DateTime nextProgUpdate = DateTime.MinValue; string usrname = Properties.Settings.Default.AccountName.ToLower(); using (Utils.ProgressBlock prog = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTING, munzl.Count, 0)) { foreach (MunzeeData md in munzl) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Archived = md.archived == "1"; gc.Available = !gc.Archived; //gc.City = md.location.Split(new char[]{','})[0]; gc.City = ""; gc.Code = string.Format("MZ{0}", int.Parse(md.munzee_id).ToString("X4")); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, 1); gc.Country = md.country; gc.DataFromDate = DateTime.Now; gc.Difficulty = 1.0; gc.Found = md.captured != "0"; if (md.type == "") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 95342); } else if (md.type == "virtual") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 95343); } else if (md.type == "maintenance") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 95344); } else if (md.type == "business") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 95345); } else if (md.type == "mystery") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 95346); } else if (md.type == "nfc") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 95347); } else if (md.type == "premium") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 95348); } else { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 95342); } gc.ID = md.munzee_id; gc.Lat = Utils.Conversion.StringToDouble(md.latitude); gc.Lon = Utils.Conversion.StringToDouble(md.longitude); gc.LongDescription = md.notes == null ? "" : md.notes.Replace("\r", "").Replace("\n", "\r\n"); gc.LongDescriptionInHtml = false; gc.MemberOnly = false; gc.Municipality = ""; gc.Name = md.friendly_name; gc.Owner = md.username; gc.OwnerId = ""; gc.PlacedBy = md.username; try { gc.PublishedTime = DateTime.ParseExact(md.deployed_at, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); } catch { gc.PublishedTime = DateTime.ParseExact(md.created_at, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); } gc.ShortDescription = ""; gc.ShortDescriptionInHtml = false; gc.State = ""; gc.Terrain = 1.0; gc.Title = gc.Name; gc.Url = string.Format("http://www.munzee.com/m/{0}/{1}/", md.username, md.code); Utils.Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); if (AddGeocache(gc, null)) { //check if found and if so, if log present if (gc.Found && !string.IsNullOrEmpty(md.captured_at)) { //foud and no log, add log bool foundLogPresent = false; List <Framework.Data.Log> lgs = Core.Logs.GetLogs(gc.Code); if (lgs != null) { Framework.Data.Log l = (from Framework.Data.Log lg in lgs where lg.LogType.AsFound && lg.Finder == Core.GeocachingAccountNames.GetAccountName(gc.Code) select lg).FirstOrDefault(); foundLogPresent = (l != null); } if (!foundLogPresent) { Framework.Data.Log l = new Framework.Data.Log(); l.DataFromDate = DateTime.Now; l.Date = new DateTime(1970, 1, 1); l.Date = l.Date.AddSeconds(long.Parse(md.captured_at.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0])); l.Encoded = false; l.Finder = Core.GeocachingAccountNames.GetAccountName(gc.Code); l.FinderId = "0"; l.GeocacheCode = gc.Code; l.ID = string.Format("ML{0}", gc.Code.Substring(2)); l.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, 2); l.Text = "Captured"; AddLog(l); } } } index++; if (DateTime.Now >= nextProgUpdate) { prog.UpdateProgress(STR_IMPORTING, STR_IMPORTING, munzl.Count, index); nextProgUpdate = DateTime.Now.AddSeconds(0.5); } } } } catch (Exception e) { _errorMessage = e.Message; } } }
public void ProcessGeocachingComGPXCaches(ResultData data, string gpxDoc) { bool isGeoSpy = false; try { string firstPart; if (gpxDoc.Length < 2000) { firstPart = gpxDoc; } else { firstPart = gpxDoc.Substring(0, 2000); } XmlDocument doc = new XmlDocument(); doc.LoadXml(gpxDoc); XmlElement root = doc.DocumentElement; XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); if (firstPart.IndexOf("http://www.topografix.com/GPX/1/1", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/1"); } else { nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/0"); } if (firstPart.IndexOf("http://geoget.ararat.cz/GpxExtensions/v2", StringComparison.OrdinalIgnoreCase) > 0) { //GeoSpy isGeoSpy = true; _cachesGpxVersion = new Version(1, 0, 0); nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/0/2", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0/2"); _cachesGpxVersion = new Version(1,0,2); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/0/1", StringComparison.OrdinalIgnoreCase) > 0) { if (firstPart.IndexOf("creator=\"Opencaching.de - http://www.opencaching.de\"") > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else if (firstPart.IndexOf("http://www.opencaching.com/xmlschemas/opencaching/1/0") > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0/1"); } _cachesGpxVersion = new Version(1, 0, 1); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/1", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/1"); _cachesGpxVersion = new Version(1, 1, 0); } else { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); _cachesGpxVersion = new Version(1, 0, 0); } if (isGeoSpy) { _gpxDataTime = DateTime.Parse(root.SelectSingleNode("x:metadata", nsmgr).SelectSingleNode("x:time", nsmgr).InnerText); } else { _gpxDataTime = DateTime.Parse(root.SelectSingleNode("x:time", nsmgr).InnerText); } XmlNodeList wps = root.SelectNodes("x:wpt", nsmgr); if (wps != null) { Version V102 = new Version(1, 0, 2); foreach (XmlNode wp in wps) { XmlNode n; if (isGeoSpy) { n = wp.SelectSingleNode("x:extensions", nsmgr).SelectSingleNode("y:cache", nsmgr); } else { n = wp.SelectSingleNode("y:cache", nsmgr); } if (n == null) { //assume Child waypoint //check if it is a child waypoint by checking the name Framework.Data.Geocache parentGeocache = null; string wpname = wp.SelectSingleNode("x:name", nsmgr).InnerText.Substring(2); parentGeocache = (from g in data.Geocaches where g.Code.Substring(2) == wpname select g).FirstOrDefault(); if (parentGeocache == null) { parentGeocache = (from Framework.Data.Geocache g in _core.Geocaches where g.Code.Substring(2) == wpname select g).FirstOrDefault(); if (parentGeocache == null) { //parent is not available //now what? continue; } } Framework.Data.Waypoint cwp = new Framework.Data.Waypoint(); cwp.Code = wp.SelectSingleNode("x:name", nsmgr).InnerText; cwp.GeocacheCode = string.Concat(parentGeocache.Code.Substring(0,2), cwp.Code.Substring(2)); cwp.DataFromDate = _gpxDataTime; cwp.Comment = wp.SelectSingleNode("x:cmt", nsmgr).InnerText; if (SafeAttributeInnerText(wp, "lat", "").Length > 0) { cwp.Lat = Utils.Conversion.StringToDouble(wp.Attributes["lat"].InnerText); cwp.Lon = Utils.Conversion.StringToDouble(wp.Attributes["lon"].InnerText); if (Math.Abs((double)cwp.Lat) < 0.0001 && Math.Abs((double)cwp.Lon) < 0.0001) { cwp.Lat = null; cwp.Lon = null; } } else { cwp.Lat = null; cwp.Lon = null; } cwp.Description = wp.SelectSingleNode("x:desc", nsmgr).InnerText; cwp.ID = cwp.Code; cwp.Name = cwp.Code; cwp.Comment = wp.SelectSingleNode("x:cmt", nsmgr).InnerText; cwp.Time = DateTime.Parse(wp.SelectSingleNode("x:time", nsmgr).InnerText); cwp.Url = SafeInnerText(wp.SelectSingleNode("x:url", nsmgr),""); cwp.UrlName = SafeInnerText(wp.SelectSingleNode("x:urlname", nsmgr),""); cwp.WPType = DataAccess.GetWaypointType(_core.WaypointTypes, wp.SelectSingleNode("x:sym", nsmgr).InnerText); data.Waypoints.Add(cwp); continue; } Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Lat = Utils.Conversion.StringToDouble(SafeAttributeInnerText(wp, "lat", "0.0")); gc.Lon = Utils.Conversion.StringToDouble(SafeAttributeInnerText(wp, "lon", "0.0")); gc.Code = wp.SelectSingleNode("x:name", nsmgr).InnerText; gc.Title = n.SelectSingleNode("y:name", nsmgr).InnerText; gc.DataFromDate = _gpxDataTime; gc.PublishedTime = DateTime.Parse(wp.SelectSingleNode("x:time", nsmgr).InnerText); if (isGeoSpy) { gc.Url = wp.SelectSingleNode("x:link", nsmgr).Attributes["href"].Value; } else { gc.Url = SafeInnerText(wp.SelectSingleNode("x:url", nsmgr), ""); } if (SafeInnerText(wp.SelectSingleNode("x:sym", nsmgr), "").EndsWith(" Found")) { gc.Found = true; } gc.Available = bool.Parse(n.Attributes["available"].InnerText); gc.Archived = bool.Parse(SafeInnerText(n.Attributes["archived"], "False")); gc.Country = SafeInnerText(n.SelectSingleNode("y:country", nsmgr), ""); gc.State = SafeInnerText(n.SelectSingleNode("y:state", nsmgr), ""); gc.ID = SafeInnerText(n.Attributes["id"], ""); gc.OwnerId = SafeAttributeInnerText(n.SelectSingleNode("y:owner", nsmgr), "id", ""); if (_cachesGpxVersion >= V102) { gc.GeocacheType = DataAccess.GetGeocacheType(_core.GeocacheTypes, int.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:type", nsmgr), "id", "-1"))); gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, int.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:container", nsmgr), "id", "-1"))); gc.Favorites = int.Parse(SafeInnerText(n.SelectSingleNode("y:favorite_points", nsmgr), "0")); gc.MemberOnly = bool.Parse(SafeInnerText(n.Attributes["memberonly"], "False")); gc.CustomCoords = bool.Parse(SafeInnerText(n.Attributes["customcoords"], "False")); gc.PersonaleNote = SafeInnerText(n.Attributes["personal_note"], ""); } else { string srchTxt = SafeInnerText(n.SelectSingleNode("y:type", nsmgr), "Unknown"); if (!srchTxt.StartsWith("Groundspeak")) { if (srchTxt.Contains("Trash")) { srchTxt = "Trash"; } else { int pos = srchTxt.IndexOf(' '); if (pos > 0) { srchTxt = srchTxt.Substring(0, pos); } } } gc.GeocacheType = DataAccess.GetGeocacheType(_core.GeocacheTypes, srchTxt); if (isGeoSpy) { gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, "Virtual"); } else { gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, SafeInnerText(n.SelectSingleNode("y:container", nsmgr), "Unknown")); } } gc.PlacedBy = SafeInnerText(n.SelectSingleNode("y:placed_by", nsmgr),""); gc.Owner = SafeInnerText(n.SelectSingleNode("y:owner", nsmgr),""); gc.Terrain = Conversion.StringToDouble(SafeInnerText(n.SelectSingleNode("y:terrain", nsmgr), "1")); gc.Difficulty = Conversion.StringToDouble(SafeInnerText(n.SelectSingleNode("y:difficulty", nsmgr), "1")); gc.ShortDescription = SafeInnerText(n.SelectSingleNode("y:short_description", nsmgr), ""); gc.ShortDescriptionInHtml = bool.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:short_description", nsmgr), "html", "False")); gc.LongDescription = SafeInnerText(n.SelectSingleNode("y:long_description", nsmgr), ""); gc.LongDescriptionInHtml = bool.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:long_description", nsmgr), "html", "False")); gc.EncodedHints = SafeInnerText(n.SelectSingleNode("y:encoded_hints", nsmgr), ""); XmlNode attrs = n.SelectSingleNode("y:attributes", nsmgr); if (attrs != null && attrs.ChildNodes!=null) { foreach (XmlNode attr in attrs.ChildNodes) { int attrId = int.Parse(attr.Attributes["id"].InnerText); int attrInc = int.Parse(SafeAttributeInnerText(attr, "inc", "1")); if (attrInc == 1) { gc.AttributeIds.Add(attrId); } else { gc.AttributeIds.Add(-1*attrId); } } } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, _core.CenterLocation); data.Geocaches.Add(gc); //Logs XmlNode ln = n.SelectSingleNode("y:logs", nsmgr); if (ln != null) { XmlNodeList logs = ln.SelectNodes("y:log", nsmgr); if (logs != null) { foreach (XmlNode l in logs) { Framework.Data.Log lg = new Framework.Data.Log(); lg.GeocacheCode = gc.Code; string lid = SafeAttributeInnerText(l, "id", ""); if (lid.StartsWith("GL")) { lg.ID = lid; } else { if (string.IsNullOrEmpty(lid) || lid.StartsWith("-")) { continue; } try { lg.ID = string.Concat("GL", Utils.Conversion.GetCacheCodeFromCacheID(int.Parse(lid)).Substring(2)); } catch { continue; } } lg.DataFromDate = _gpxDataTime; lg.Date = DateTime.Parse(l.SelectSingleNode("y:date", nsmgr).InnerText); lg.Encoded = bool.Parse(l.SelectSingleNode("y:text", nsmgr).Attributes["encoded"].InnerText); if (isGeoSpy) { lg.Text = Conversion.StripHtmlTags(System.Web.HttpUtility.HtmlDecode(l.SelectSingleNode("y:text", nsmgr).InnerText).Replace("</p>", "\r\n\r\n")); } else { lg.Text = l.SelectSingleNode("y:text", nsmgr).InnerText; } lg.Finder = l.SelectSingleNode("y:finder", nsmgr).InnerText; if (l.SelectSingleNode("y:finder", nsmgr).Attributes["id"] != null) { lg.FinderId = l.SelectSingleNode("y:finder", nsmgr).Attributes["id"].InnerText; } else { //GCTour has no finder id lg.FinderId = "1"; } if (_cachesGpxVersion >= V102) { lg.LogType = DataAccess.GetLogType(_core.LogTypes, int.Parse(l.SelectSingleNode("y:type", nsmgr).Attributes["id"].InnerText)); } else { lg.LogType = DataAccess.GetLogType(_core.LogTypes, l.SelectSingleNode("y:type", nsmgr).InnerText); } data.Logs.Add(lg); //log images XmlNode lni = l.SelectSingleNode("y:images", nsmgr); if (lni != null) { XmlNodeList logis = lni.SelectNodes("y:image", nsmgr); if (logis != null) { foreach (XmlNode li in logis) { Framework.Data.LogImage lgi = new Framework.Data.LogImage(); lgi.Url = li.SelectSingleNode("y:url", nsmgr).InnerText; lgi.ID = lgi.Url; lgi.LogID = lg.ID; lgi.Name = li.SelectSingleNode("y:name", nsmgr).InnerText; lgi.DataFromDate = _gpxDataTime; data.LogImages.Add(lgi); } } } } } } } } } catch { } }
public static Framework.Data.Log Log(Framework.Interfaces.ICore core, OKAPIService.Log lg, string finder, string finderId) { Framework.Data.Log result = null; if (lg != null) { Framework.Data.Log tmp = Utils.DataAccess.GetLog(core.Logs, lg.cache_code); result = new Framework.Data.Log(); if (tmp != null) { result.UpdateFrom(tmp); } result.DataFromDate = DateTime.Now; result.Date = DateTime.Parse(lg.date); result.Encoded = false; if (lg.user == null) { result.Finder = finder; result.FinderId = finderId; } else { result.Finder = lg.user.username; result.FinderId = lg.user.uuid; } result.GeocacheCode = lg.cache_code; result.ID = lg.uuid; result.Text = lg.comment; result.LogType = Utils.DataAccess.GetLogType(core.LogTypes, lg.type); } return result; }
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; }
protected override void ImportMethod() { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, _gcList.Count, 0, true)) { int totalcount = _gcList.Count; using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken))) { int index = 0; bool cancel = false; while (_gcList.Count > 0 && !cancel) { int logCount = 0; int maxPerPage = 30; bool done = false; if (PluginSettings.Instance.UpdateLogsMaxLogCount > 0 && PluginSettings.Instance.UpdateLogsMaxLogCount < 30) { maxPerPage = PluginSettings.Instance.UpdateLogsMaxLogCount; } List <string> ids = new List <string>(); Thread.Sleep(PluginSettings.Instance.AdditionalDelayBetweenLogImport); var resp = client.Client.GetGeocacheLogsByCacheCode(client.Token, _gcList[0].Code, logCount, maxPerPage); while (resp.Status.StatusCode == 0 && resp.Logs != null && resp.Logs.Count() > 0 && !done) { foreach (var lg in resp.Logs) { if (!lg.IsArchived) { Framework.Data.Log gcLog = Utils.API.Convert.Log(Core, lg); AddLog(gcLog); if (PluginSettings.Instance.UpdateLogsMaxLogCount == 0) { ids.Add(gcLog.ID); } } } logCount += resp.Logs.Count(); if (PluginSettings.Instance.UpdateLogsMaxLogCount > 0) { int left = PluginSettings.Instance.UpdateLogsMaxLogCount - logCount; if (left < maxPerPage) { maxPerPage = left; } } if (maxPerPage > 0) { Thread.Sleep(3000 + PluginSettings.Instance.AdditionalDelayBetweenLogImport); resp = client.Client.GetGeocacheLogsByCacheCode(client.Token, _gcList[0].Code, logCount, maxPerPage); } else { done = true; } } if (resp.Status.StatusCode != 0) { _errormessage = resp.Status.StatusMessage; break; } else { if (PluginSettings.Instance.DeselectGeocacheAfterUpdate) { _gcList[0].Selected = false; } if (PluginSettings.Instance.UpdateLogsMaxLogCount == 0) { List <Framework.Data.Log> allLogs = Utils.DataAccess.GetLogs(Core.Logs, _gcList[0].Code); foreach (Framework.Data.Log gim in allLogs) { if (!ids.Contains(gim.ID)) { Core.Logs.Remove(gim); } } } } index++; if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index)) { break; } _gcList.RemoveAt(0); } } } } catch (Exception e) { _errormessage = e.Message; } }
public override bool LoadLogs(List<Framework.Data.Log> logs) { bool result = false; MySqlConnection dbcon = GetMySqlConnection(Properties.Settings.Default.SqlServer, Properties.Settings.Default.Database, Properties.Settings.Default.SqlServerPwd, Properties.Settings.Default.SqlServerUsername, Properties.Settings.Default.SqlServerUseIS, Properties.Settings.Default.SqlServerPort); if (dbcon != null && InitDatabase(dbcon, Properties.Settings.Default.Database)) { int logCount = 0; using (MySqlCommand cmd = new MySqlCommand("select log from counter", dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) if (dr.Read()) { logCount = (int)dr["log"]; } UpdateLoadingInBackgroundProgress(STR_LOADING_LOGS_BG, logCount,0); int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select ID, gccode, Finder, DataFromDate, LogType, Date from log", dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Log lg = new Framework.Data.Log(); lg.ID = (string)dr["id"]; lg.GeocacheCode = (string)dr["gccode"]; lg.Date = DateTime.Parse((string)dr["date"]).ToLocalTime(); lg.Finder = (string)dr["finder"]; lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); lg.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, (int)dr["logtype"]); lg.Saved = true; lg.IsDataChanged = false; _logsInDB[lg.ID] = lg.ID; logs.Add(lg); index++; procStep++; if (procStep >= 20000) { UpdateLoadingInBackgroundProgress(STR_LOADING_LOGS_BG, logCount, index); procStep = 0; } } } dbcon.Dispose(); dbcon = null; } return result; }
protected override void ImportMethod() { System.Collections.Hashtable logTypes = new System.Collections.Hashtable(); using (Utils.ProgressBlock fixpr = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGDATA, 1, 0)) { String connect = String.Format("data source=file:{0}", _filename); using (SqliteConnection dbcon = new SqliteConnection(connect)) { //System.Diagnostics.Debugger.Break(); logTypes.Add("Found it", 2); logTypes.Add("Didn't find it", 3); logTypes.Add("Write note", 4); logTypes.Add("Archive", 5); logTypes.Add("Needs Archived", 7); logTypes.Add("Will Attend", 9); logTypes.Add("Attended", 10); logTypes.Add("Webcam Photo Taken", 11); logTypes.Add("Unarchive", 12); logTypes.Add("Temporarily Disable Listing", 22); logTypes.Add("Enable Listing", 23); logTypes.Add("Publish Listing", 24); logTypes.Add("Retract Listing", 25); logTypes.Add("Needs Maintenance", 45); logTypes.Add("Owner Maintenance", 46); logTypes.Add("Update Coordinates", 47); logTypes.Add("Post Reviewer Note", 68); logTypes.Add("Announcement", 74); int index = 0; int procStep = 0; dbcon.Open(); SqliteCommand lookup = new SqliteCommand("select aId, aInc from attributes where aCode = @Code", dbcon); lookup.CommandType = CommandType.Text; DbParameter par = lookup.CreateParameter(); par.Direction = ParameterDirection.Input; par.ParameterName = "@Code"; lookup.Parameters.Add(par); lookup.Prepare(); SqliteCommand import = new SqliteCommand("select count(1) from caches", dbcon); import.CommandType = CommandType.Text; int gcCount = (int)(long)import.ExecuteScalar(); if (gcCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGGEOCACHES, gcCount, 0)) { bool isPremiumAvailable = false; bool isFavPointAvailable = false; bool isGCNoteAvailable = false; try { import.CommandText = "select IsPremium from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isPremiumAvailable = true; } } catch { } try { import.CommandText = "select FavPoints from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isFavPointAvailable = true; } } catch { } try { import.CommandText = "select gcnote from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isGCNoteAvailable = true; } } catch { } import.CommandText = "select caches.Code, Name, LastGPXDate, PlacedDate, Latitude, Longitude, Status, " + "Archived, Country, State, CacheType, PlacedBy, OwnerName, OwnerId, Container, Terrain, Difficulty, ShortHTM" + ", LongHTM, " + string.Format("{0}", isPremiumAvailable? "IsPremium, ":"") + " HasCorrected, LatOriginal, LonOriginal, UserFlag, Found, " + string.Format("{0}", isFavPointAvailable? "FavPoints, ":"") + " ShortDescription, LongDescription, Hints, Url, UserNote" + string.Format("{0}", isGCNoteAvailable ? ", gcnote" : "") + " from caches" + " inner join cachememo on cachememo.code = caches.code"; SqliteDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); int cacheType; try { cacheType = getCacheType(((String)dr["CacheType"])[0]); } catch (ArgumentOutOfRangeException) { continue; } int container = getContainer(((String)dr["Container"])[0]); gc.Code = (string)dr["code"]; gc.Name = (string)dr["name"]; gc.DataFromDate = DateTime.Parse((string)dr["LastGPXDate"]); gc.Available = ((String)dr["Status"]).Equals("A"); gc.Archived = (int)dr["archived"] != 0; gc.Country = (string)dr["country"]; gc.State = (string)dr["state"]; gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, cacheType); gc.PlacedBy = (string)dr["placedby"]; gc.Owner = (string)dr["OwnerName"]; gc.OwnerId = dr["ownerid"].GetType() == typeof(DBNull) ? "" : dr["ownerid"].ToString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, container); gc.Terrain = (double)dr["terrain"]; gc.Difficulty = (double)dr["difficulty"]; gc.ShortDescription = (string)dr["ShortDescription"]; gc.ShortDescriptionInHtml = (int)dr["ShortHTM"] != 0; gc.LongDescription = (string)dr["LongDescription"]; gc.LongDescriptionInHtml = (int)dr["LongHTM"] != 0; gc.EncodedHints = (string)dr["Hints"]; gc.Url = (string)dr["url"]; if (isPremiumAvailable) { gc.MemberOnly = (int)dr["IsPremium"] != 0; } else { gc.MemberOnly = false; } gc.CustomCoords = (int)dr["HasCorrected"] != 0; if (gc.CustomCoords) { gc.CustomLat = Utils.Conversion.StringToDouble(dr["Latitude"] as String); gc.CustomLon = Utils.Conversion.StringToDouble(dr["Longitude"] as String); gc.Lat = Utils.Conversion.StringToDouble(dr["LatOriginal"] as string); gc.Lon = Utils.Conversion.StringToDouble(dr["LonOriginal"] as string); } else { gc.Lat = Utils.Conversion.StringToDouble(dr["Latitude"] as string); gc.Lon = Utils.Conversion.StringToDouble(dr["Longitude"] as string); } par.Value = gc.Code; DbDataReader attrs = lookup.ExecuteReader(); List<int> attrList = new List<int>(); while (attrs.Read()) { int attr = (int)(int)attrs["aId"]; if (attrs["aInc"].ToString() == "0") { attr *= -1; } attrList.Add(attr); } attrs.Close(); gc.AttributeIds = attrList; gc.Notes = (string)dr["UserNote"]; gc.PublishedTime = DateTime.Parse((string)dr["PlacedDate"]); if (isGCNoteAvailable) { gc.PersonaleNote = (string)dr["gcnote"]; } else { gc.PersonaleNote = ""; } gc.Flagged = (int)dr["UserFlag"] != 0; gc.Found = (int)dr["Found"] != 0; if (isFavPointAvailable) { gc.Favorites = (int)(int)dr["FavPoints"]; } else { gc.Favorites = 0; } gc.Selected = false; Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); AddGeocache(gc, null); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGGEOCACHES, gcCount, index); procStep = 0; } } dr.Close(); } import.CommandText = "select count(1) from logs"; int logCount = (int)(long)import.ExecuteScalar(); if (logCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGLOGS, logCount, 0)) { index = 0; procStep = 0; import.CommandText = "select l.lLogId, l.lParent, lDate, lTime, lBy, lownerid, lEncoded, lType, lText " + " from logs l" + " inner join logmemo m on m.lLogId = l.lLogId and m.lParent = l.lParent"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Log lg = new Framework.Data.Log(); String type = (String)dr["lType"]; int logType = (int)logTypes[type]; //id text, gccode text, tbcode text, date text, finder text, finderid text, logtext text, encoded integer, datafromdate text, logtype integer lg.ID = dr["lLogiD"].ToString(); lg.GeocacheCode = (string)dr["lParent"]; lg.TBCode = ""; lg.Date = (DateTime)dr["lDate"]; lg.Finder = (string)dr["lBy"]; lg.FinderId = dr["lownerid"].ToString(); lg.Text = (string)dr["lText"]; lg.Encoded = (long)dr["lEncoded"]!=0; lg.DataFromDate = DateTime.Now; lg.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, logType); AddLog(lg); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGLOGS, logCount, index); procStep = 0; } } dr.Close(); } } import.CommandText = "select count(1) from logimages"; int logimgCount = 0; try { logimgCount = (int)(long)import.ExecuteScalar(); } catch { //table does not exists } if (logimgCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGLOGIMAGES, logimgCount, 0)) { index = 0; procStep = 0; import.CommandText = "select iCode, iLogId, iImage, iName from logimages"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.LogImage lg = new Framework.Data.LogImage(); lg.ID = (string)dr["iCode"]; lg.LogID = dr["iLogID"].ToString(); lg.Url = (string)dr["iImage"]; lg.Name = (string)dr["iName"]; AddLogImage(lg); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGLOGIMAGES, logimgCount, index); procStep = 0; } } dr.Close(); } } //id text, code text, geocachecode text, name text, datafromdate text, comment text, description text, url text, urlname text, wptype integer, lat real, lon real, time text import.CommandText = "select count(1) from waypoints"; int wptCount = (int)(long)import.ExecuteScalar(); if (wptCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGWAYPOINTS, wptCount, 0)) { index = 0; procStep = 0; import.CommandText = "select w.cParent, w.cCode, cName, cDate, cType, cLat, cLon," + " cComment, cUrl" + " from waypoints w" + " inner join wayMemo m on w.cParent = m.cParent and w.cCode=m.cCode"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); int wpType = getWPType(((string)dr["cType"])[0]); wp.ID = (string)dr["cCode"]; wp.Code = (string)dr["cCode"]; wp.Url = (string)dr["cUrl"]; //wp.UrlName = (string)dr["urlname"]; wp.Name = (string)dr["cName"]; wp.DataFromDate = (DateTime)dr["cDate"]; wp.Comment = (string)dr["cComment"]; wp.GeocacheCode = (string)dr["cParent"]; //wp.Description = (string)dr["description"]; wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, wpType); double lat = Utils.Conversion.StringToDouble(dr["clat"] as string); double lon = Utils.Conversion.StringToDouble(dr["clon"] as string); if (Math.Abs(lat) < 0.00001) { wp.Lat = null; } else { wp.Lat = lat; } if (Math.Abs(lon) < 0.00001) { wp.Lon = null; } else { wp.Lon = lon; } wp.Time = (DateTime)dr["cDate"]; wp.Description = wp.WPType.Name; wp.UrlName = wp.WPType.Name; AddWaypoint(wp); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGWAYPOINTS, wptCount, index); procStep = 0; } } dr.Close(); } } try { //import corrected if table exists import.CommandText = "select kCode, kAfterLat, kAfterLon from Corrected"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { string gcCode = dr["kCode"] as string ?? ""; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, gcCode); if (gc != null) { object oLat = dr["kAfterLat"]; object oLon = dr["kAfterLon"]; if (oLat != null && oLat.GetType() != typeof(DBNull) && oLon != null && oLon.GetType() != typeof(DBNull)) { string sLat = oLat as string; string sLon = oLon as string; if (sLat.Length > 0 && sLon.Length > 0) { gc.CustomLat = Utils.Conversion.StringToDouble(sLat); gc.CustomLon = Utils.Conversion.StringToDouble(sLon); } } } } } catch { } } } } }
private void readLogData(RecordInfo ri, MemoryStream ms, BinaryReader br) { _logsInDB.Add(ri.ID, ri); Framework.Data.Log l = new Framework.Data.Log(); l.ID = ri.ID; //l.GeocacheCode = ri.SubID; l.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32()); l.Date = DateTimeFromLong(br.ReadInt64()); l.DataFromDate = DateTimeFromLong(br.ReadInt64()); //l.Encoded = br.ReadBoolean(); ms.Position = 180; l.GeocacheCode = br.ReadString(); ms.Position = 220; l.Finder = br.ReadString(); //ms.Position = 320; //l.FinderId = br.ReadString(); //ms.Position = 350; //l.TBCode = br.ReadString(); //ms.Position = 380; //l.Text = br.ReadString(); l.Saved = true; l.IsDataChanged = false; Core.Logs.Add(l); }
public override bool Load(bool geocachesOnly) { 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 geocacheimgCount = 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); if (root.SelectSingleNode("GeocacheImagesCount") != null) { geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").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; //int procStep = 0; List<Framework.Data.Geocache> gcList = new List<Framework.Data.Geocache>(); FileStream fs = _fileCollection._fsGeocaches; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); 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) { //lazy loading ri.FreeSlot = false; int readCount = Math.Min(32, (int)(ri.Length - lsize - 1)); fs.Read(memBuffer, 0, readCount); ms.Position = 0; ri.ID = br.ReadString(); fs.Position = ri.Offset + ri.Length; } 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(); Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); gc.Saved = true; gc.IsDataChanged = false; //gcList.Add(gc); Core.Geocaches.Add(gc); index++; //procStep++; //if (procStep >= 1000) if (DateTime.Now>=nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); //procStep = 0; } } _fileCollection._geocachesInDB.Add(ri.ID, ri); } //Core.Geocaches.Add(gcList); } if (!geocachesOnly) { using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; List<Framework.Data.Log> lgList = new List<Framework.Data.Log>(); FileStream fs = _fileCollection._fsLogs; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); 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) { //lazy loading ri.FreeSlot = false; int readCount = Math.Min(32, (int)(ri.Length - lsize - 1)); fs.Read(memBuffer, 0, readCount); ms.Position = 0; ri.ID = br.ReadString(); fs.Position = ri.Offset + ri.Length; } 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; lgList.Add(log); index++; //procStep++; //if (procStep >= 1000) if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); //procStep = 0; } } _fileCollection._logsInDB.Add(ri.ID, ri); } Core.Logs.Add(lgList); } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.Waypoint> wptList = new List<Framework.Data.Waypoint>(); using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); 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; wptList.Add(wp); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } _fileCollection._wptsInDB.Add(ri.ID, ri); } } Core.Waypoints.Add(wptList); } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.LogImage> lgiList = new List<Framework.Data.LogImage>(); using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); 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; lgiList.Add(li); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } _fileCollection._logimgsInDB.Add(ri.ID, ri); } } Core.LogImages.Add(lgiList); } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.GeocacheImage> lgiList = new List<Framework.Data.GeocacheImage>(); using (FileStream fs = File.Open(_fileCollection.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); 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.GeocacheImage li = new Framework.Data.GeocacheImage(); 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.GeocacheCode = br.ReadString(); li.Description = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); li.MobileUrl = br.ReadString(); li.ThumbUrl = br.ReadString(); li.Saved = true; li.IsDataChanged = false; lgiList.Add(li); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index); procStep = 0; } } _fileCollection._geocacheimgsInDB.Add(ri.ID, ri); } } Core.GeocacheImages.Add(lgiList); } //using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.UserWaypoint> uwplList = new List<Framework.Data.UserWaypoint>(); using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); 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; uwplList.Add(wp); index++; procStep++; if (procStep >= 1000) { //progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } _fileCollection._usrwptsInDB.Add(ri.ID, ri); } } Core.UserWaypoints.Add(uwplList); } } } } } return result; }
public void Import(Framework.Interfaces.ICore core, Utils.BasePlugin.Plugin owner, string fileName) { using (Utils.ProgressBlock upd = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT, 1, 0)) { using (FileStream fs = File.OpenRead(fileName)) using (BinaryReader br = new BinaryReader(fs)) { string tag = br.ReadString(); if (tag == "GAPP") { bool IsLittleEndian = br.ReadBoolean(); int version = br.ReadInt32(); if (IsLittleEndian == BitConverter.IsLittleEndian && version <= 3) { int count = br.ReadInt32(); using (Utils.ProgressBlock prog = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT_CACHES, count, 0)) { for (int index = 0; index < count; index++) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Code = 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(); string s = br.ReadString(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); 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.Selected = br.ReadBoolean(); gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); if (version > 1) { gc.Locked = br.ReadBoolean(); } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, core.CenterLocation); (owner as Import).AddImportedGeocache(gc); int logcount = br.ReadInt32(); for (int lc = 0; lc < logcount; lc++) { Framework.Data.Log log = new Framework.Data.Log(); log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Encoded = br.ReadBoolean(); log.Finder = br.ReadString(); log.FinderId = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(core.LogTypes, br.ReadInt32()); log.TBCode = br.ReadString(); log.Text = br.ReadString(); (owner as Import).AddImportedLog(log); int logimgcount = br.ReadInt32(); for (int lic = 0; lic < logimgcount; lic++) { Framework.Data.LogImage li = new Framework.Data.LogImage(); li.DataFromDate = DateTime.Parse(br.ReadString()); li.ID = br.ReadString(); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); (owner as Import).AddImportedLogImage(li); } } int wpcount = br.ReadInt32(); for (int wpc = 0; wpc < wpcount; wpc++) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.Code = br.ReadString(); 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()); (owner as Import).AddImportedWaypoint(wp); } if (version > 2) { int usrwpcount = br.ReadInt32(); for (int wpc = 0; wpc < usrwpcount; wpc++) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = br.ReadInt32(); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); (owner as Import).AddImportedUserWaypoint(wp); } } if (index % 200 == 0) { prog.UpdateProgress(STR_IMPORT, STR_IMPORT_CACHES, count, index); } } } } else { //message } } else { //message } } } }
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; }
public void ProcessGeocachingComGPXCaches(ResultData data, string gpxDoc) { bool isGeoSpy = false; try { string firstPart; if (gpxDoc.Length < 2000) { firstPart = gpxDoc; } else { firstPart = gpxDoc.Substring(0, 2000); } XmlDocument doc = new XmlDocument(); doc.LoadXml(gpxDoc); XmlElement root = doc.DocumentElement; XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); if (firstPart.IndexOf("http://www.topografix.com/GPX/1/1", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/1"); } else { nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/0"); } if (firstPart.IndexOf("http://geoget.ararat.cz/GpxExtensions/v2", StringComparison.OrdinalIgnoreCase) > 0) { //GeoSpy isGeoSpy = true; _cachesGpxVersion = new Version(1, 0, 0); nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/0/2", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0/2"); _cachesGpxVersion = new Version(1, 0, 2); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/0/1", StringComparison.OrdinalIgnoreCase) > 0) { if (firstPart.IndexOf("creator=\"Opencaching.de - http://www.opencaching.de\"") > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else if (firstPart.IndexOf("http://www.opencaching.com/xmlschemas/opencaching/1/0") > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0/1"); } _cachesGpxVersion = new Version(1, 0, 1); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/1", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/1"); _cachesGpxVersion = new Version(1, 1, 0); } else { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); _cachesGpxVersion = new Version(1, 0, 0); } if (isGeoSpy) { _gpxDataTime = DateTime.Parse(root.SelectSingleNode("x:metadata", nsmgr).SelectSingleNode("x:time", nsmgr).InnerText); } else { _gpxDataTime = DateTime.Parse(root.SelectSingleNode("x:time", nsmgr).InnerText); } XmlNodeList wps = root.SelectNodes("x:wpt", nsmgr); if (wps != null) { Version V102 = new Version(1, 0, 2); foreach (XmlNode wp in wps) { XmlNode n; if (isGeoSpy) { n = wp.SelectSingleNode("x:extensions", nsmgr).SelectSingleNode("y:cache", nsmgr); } else { n = wp.SelectSingleNode("y:cache", nsmgr); } if (n == null) { //assume Child waypoint //check if it is a child waypoint by checking the name Framework.Data.Geocache parentGeocache = null; string wpname = wp.SelectSingleNode("x:name", nsmgr).InnerText.Substring(2); parentGeocache = (from g in data.Geocaches where g.Code.Substring(2) == wpname select g).FirstOrDefault(); if (parentGeocache == null) { parentGeocache = (from Framework.Data.Geocache g in _core.Geocaches where g.Code.Substring(2) == wpname select g).FirstOrDefault(); if (parentGeocache == null) { //parent is not available //now what? continue; } } Framework.Data.Waypoint cwp = new Framework.Data.Waypoint(); cwp.Code = wp.SelectSingleNode("x:name", nsmgr).InnerText; cwp.GeocacheCode = string.Concat(parentGeocache.Code.Substring(0, 2), cwp.Code.Substring(2)); cwp.DataFromDate = _gpxDataTime; cwp.Comment = wp.SelectSingleNode("x:cmt", nsmgr).InnerText; if (SafeAttributeInnerText(wp, "lat", "").Length > 0) { cwp.Lat = Utils.Conversion.StringToDouble(wp.Attributes["lat"].InnerText); cwp.Lon = Utils.Conversion.StringToDouble(wp.Attributes["lon"].InnerText); if (Math.Abs((double)cwp.Lat) < 0.0001 && Math.Abs((double)cwp.Lon) < 0.0001) { cwp.Lat = null; cwp.Lon = null; } } else { cwp.Lat = null; cwp.Lon = null; } cwp.Description = wp.SelectSingleNode("x:desc", nsmgr).InnerText; cwp.ID = cwp.Code; cwp.Name = cwp.Code; cwp.Comment = wp.SelectSingleNode("x:cmt", nsmgr).InnerText; cwp.Time = DateTime.Parse(wp.SelectSingleNode("x:time", nsmgr).InnerText); cwp.Url = SafeInnerText(wp.SelectSingleNode("x:url", nsmgr), ""); cwp.UrlName = SafeInnerText(wp.SelectSingleNode("x:urlname", nsmgr), ""); cwp.WPType = DataAccess.GetWaypointType(_core.WaypointTypes, wp.SelectSingleNode("x:sym", nsmgr).InnerText); data.Waypoints.Add(cwp); continue; } Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Lat = Utils.Conversion.StringToDouble(SafeAttributeInnerText(wp, "lat", "0.0")); gc.Lon = Utils.Conversion.StringToDouble(SafeAttributeInnerText(wp, "lon", "0.0")); gc.Code = wp.SelectSingleNode("x:name", nsmgr).InnerText; gc.Title = n.SelectSingleNode("y:name", nsmgr).InnerText; gc.DataFromDate = _gpxDataTime; gc.PublishedTime = DateTime.Parse(wp.SelectSingleNode("x:time", nsmgr).InnerText); if (isGeoSpy) { gc.Url = wp.SelectSingleNode("x:link", nsmgr).Attributes["href"].Value; } else { gc.Url = SafeInnerText(wp.SelectSingleNode("x:url", nsmgr), ""); } if (SafeInnerText(wp.SelectSingleNode("x:sym", nsmgr), "").EndsWith(" Found")) { gc.Found = true; } gc.Available = bool.Parse(n.Attributes["available"].InnerText); gc.Archived = bool.Parse(SafeInnerText(n.Attributes["archived"], "False")); gc.Country = SafeInnerText(n.SelectSingleNode("y:country", nsmgr), ""); gc.State = SafeInnerText(n.SelectSingleNode("y:state", nsmgr), ""); gc.ID = SafeInnerText(n.Attributes["id"], ""); gc.OwnerId = SafeAttributeInnerText(n.SelectSingleNode("y:owner", nsmgr), "id", ""); if (_cachesGpxVersion >= V102) { gc.GeocacheType = DataAccess.GetGeocacheType(_core.GeocacheTypes, int.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:type", nsmgr), "id", "-1"))); gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, int.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:container", nsmgr), "id", "-1"))); gc.Favorites = int.Parse(SafeInnerText(n.SelectSingleNode("y:favorite_points", nsmgr), "0")); gc.MemberOnly = bool.Parse(SafeInnerText(n.Attributes["memberonly"], "False")); gc.CustomCoords = bool.Parse(SafeInnerText(n.Attributes["customcoords"], "False")); gc.PersonaleNote = SafeInnerText(n.Attributes["personal_note"], ""); } else { string srchTxt = SafeInnerText(n.SelectSingleNode("y:type", nsmgr), "Unknown"); if (!srchTxt.StartsWith("Groundspeak")) { if (srchTxt.Contains("Trash")) { srchTxt = "Trash"; } else { int pos = srchTxt.IndexOf(' '); if (pos > 0) { srchTxt = srchTxt.Substring(0, pos); } } } gc.GeocacheType = DataAccess.GetGeocacheType(_core.GeocacheTypes, srchTxt); if (isGeoSpy) { gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, "Virtual"); } else { gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, SafeInnerText(n.SelectSingleNode("y:container", nsmgr), "Unknown")); } } gc.PlacedBy = SafeInnerText(n.SelectSingleNode("y:placed_by", nsmgr), ""); gc.Owner = SafeInnerText(n.SelectSingleNode("y:owner", nsmgr), ""); gc.Terrain = Conversion.StringToDouble(SafeInnerText(n.SelectSingleNode("y:terrain", nsmgr), "1")); gc.Difficulty = Conversion.StringToDouble(SafeInnerText(n.SelectSingleNode("y:difficulty", nsmgr), "1")); gc.ShortDescription = SafeInnerText(n.SelectSingleNode("y:short_description", nsmgr), ""); gc.ShortDescriptionInHtml = bool.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:short_description", nsmgr), "html", "False")); gc.LongDescription = SafeInnerText(n.SelectSingleNode("y:long_description", nsmgr), ""); gc.LongDescriptionInHtml = bool.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:long_description", nsmgr), "html", "False")); gc.EncodedHints = SafeInnerText(n.SelectSingleNode("y:encoded_hints", nsmgr), ""); XmlNode attrs = n.SelectSingleNode("y:attributes", nsmgr); if (attrs != null && attrs.ChildNodes != null) { foreach (XmlNode attr in attrs.ChildNodes) { int attrId = int.Parse(attr.Attributes["id"].InnerText); int attrInc = int.Parse(SafeAttributeInnerText(attr, "inc", "1")); if (attrInc == 1) { gc.AttributeIds.Add(attrId); } else { gc.AttributeIds.Add(-1 * attrId); } } } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, _core.CenterLocation); data.Geocaches.Add(gc); //Logs XmlNode ln = n.SelectSingleNode("y:logs", nsmgr); if (ln != null) { XmlNodeList logs = ln.SelectNodes("y:log", nsmgr); if (logs != null) { foreach (XmlNode l in logs) { Framework.Data.Log lg = new Framework.Data.Log(); lg.GeocacheCode = gc.Code; string lid = SafeAttributeInnerText(l, "id", ""); if (lid.StartsWith("GL")) { lg.ID = lid; } else { if (string.IsNullOrEmpty(lid) || lid.StartsWith("-")) { continue; } try { lg.ID = string.Concat("GL", Utils.Conversion.GetCacheCodeFromCacheID(int.Parse(lid)).Substring(2)); } catch { continue; } } lg.DataFromDate = _gpxDataTime; lg.Date = DateTime.Parse(l.SelectSingleNode("y:date", nsmgr).InnerText); lg.Encoded = bool.Parse(l.SelectSingleNode("y:text", nsmgr).Attributes["encoded"].InnerText); if (isGeoSpy) { lg.Text = Conversion.StripHtmlTags(System.Web.HttpUtility.HtmlDecode(l.SelectSingleNode("y:text", nsmgr).InnerText).Replace("</p>", "\r\n\r\n")); } else { lg.Text = l.SelectSingleNode("y:text", nsmgr).InnerText; } lg.Finder = l.SelectSingleNode("y:finder", nsmgr).InnerText; if (l.SelectSingleNode("y:finder", nsmgr).Attributes["id"] != null) { lg.FinderId = l.SelectSingleNode("y:finder", nsmgr).Attributes["id"].InnerText; } else { //GCTour has no finder id lg.FinderId = "1"; } if (_cachesGpxVersion >= V102) { lg.LogType = DataAccess.GetLogType(_core.LogTypes, int.Parse(l.SelectSingleNode("y:type", nsmgr).Attributes["id"].InnerText)); } else { lg.LogType = DataAccess.GetLogType(_core.LogTypes, l.SelectSingleNode("y:type", nsmgr).InnerText); } data.Logs.Add(lg); //log images XmlNode lni = l.SelectSingleNode("y:images", nsmgr); if (lni != null) { XmlNodeList logis = lni.SelectNodes("y:image", nsmgr); if (logis != null) { foreach (XmlNode li in logis) { Framework.Data.LogImage lgi = new Framework.Data.LogImage(); lgi.Url = li.SelectSingleNode("y:url", nsmgr).InnerText; lgi.ID = lgi.Url; lgi.LogID = lg.ID; lgi.Name = li.SelectSingleNode("y:name", nsmgr).InnerText; lgi.DataFromDate = _gpxDataTime; data.LogImages.Add(lgi); } } } } } } } } } catch { } }
public bool AddImportedLog(Framework.Data.Log l) { return(base.AddLog(l)); }
protected override void ImportMethod() { System.Collections.Hashtable logTypes = new System.Collections.Hashtable(); using (Utils.ProgressBlock fixpr = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGDATA, 1, 0)) { String connect = String.Format("data source=file:{0}", _filename); using (SqliteConnection dbcon = new SqliteConnection(connect)) { //System.Diagnostics.Debugger.Break(); logTypes.Add("Found it", 2); logTypes.Add("Didn't find it", 3); logTypes.Add("Write note", 4); logTypes.Add("Archive", 5); logTypes.Add("Needs Archived", 7); logTypes.Add("Will Attend", 9); logTypes.Add("Attended", 10); logTypes.Add("Webcam Photo Taken", 11); logTypes.Add("Unarchive", 12); logTypes.Add("Temporarily Disable Listing", 22); logTypes.Add("Temporarily Disable", 22); logTypes.Add("Enable Listing", 23); logTypes.Add("Enable", 23); logTypes.Add("Publish Listing", 24); logTypes.Add("Publish", 24); logTypes.Add("Retract Listing", 25); logTypes.Add("Retract", 25); logTypes.Add("Needs Maintenance", 45); logTypes.Add("Owner Maintenance", 46); logTypes.Add("Update Coordinates", 47); logTypes.Add("Post Reviewer Note", 68); logTypes.Add("Announcement", 74); int index = 0; int procStep = 0; dbcon.Open(); SqliteCommand lookup = new SqliteCommand("select aId, aInc from attributes where aCode = @Code", dbcon); lookup.CommandType = CommandType.Text; DbParameter par = lookup.CreateParameter(); par.Direction = ParameterDirection.Input; par.ParameterName = "@Code"; lookup.Parameters.Add(par); lookup.Prepare(); SqliteCommand import = new SqliteCommand("select count(1) from caches", dbcon); import.CommandType = CommandType.Text; int gcCount = (int)(long)import.ExecuteScalar(); if (gcCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGGEOCACHES, gcCount, 0)) { bool isPremiumAvailable = false; bool isFavPointAvailable = false; bool isGCNoteAvailable = false; try { import.CommandText = "select IsPremium from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isPremiumAvailable = true; } } catch { } try { import.CommandText = "select FavPoints from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isFavPointAvailable = true; } } catch { } try { import.CommandText = "select gcnote from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isGCNoteAvailable = true; } } catch { } import.CommandText = "select caches.Code, Name, LastGPXDate, PlacedDate, Latitude, Longitude, Status, " + "Archived, Country, State, County, CacheType, PlacedBy, OwnerName, OwnerId, Container, Terrain, Difficulty, ShortHTM" + ", LongHTM, " + string.Format("{0}", isPremiumAvailable? "IsPremium, ":"") + " HasCorrected, LatOriginal, LonOriginal, UserFlag, Found, " + string.Format("{0}", isFavPointAvailable? "FavPoints, ":"") + " ShortDescription, LongDescription, Hints, Url, UserNote" + string.Format("{0}", isGCNoteAvailable ? ", gcnote" : "") + " from caches" + " inner join cachememo on cachememo.code = caches.code"; SqliteDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); int cacheType; try { cacheType = getCacheType(((String)dr["CacheType"])[0]); } catch (ArgumentOutOfRangeException) { continue; } int container = getContainer(((String)dr["Container"])[0]); gc.Code = (string)dr["code"]; gc.Name = (string)dr["name"]; if (string.IsNullOrEmpty((string)dr["LastGPXDate"])) { gc.DataFromDate = DateTime.Now.Date; } else { gc.DataFromDate = DateTime.Parse((string)dr["LastGPXDate"]); } gc.Available = ((String)dr["Status"]).Equals("A"); gc.Archived = (int)dr["archived"] != 0; gc.Country = (string)dr["country"]; gc.State = (string)dr["state"]; gc.Municipality = (string)dr["county"]; gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, cacheType); gc.PlacedBy = (string)dr["placedby"]; gc.Owner = (string)dr["OwnerName"]; gc.OwnerId = dr["ownerid"].GetType() == typeof(DBNull) ? "" : dr["ownerid"].ToString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, container); gc.Terrain = (double)dr["terrain"]; gc.Difficulty = (double)dr["difficulty"]; gc.ShortDescription = (string)dr["ShortDescription"]; gc.ShortDescriptionInHtml = (int)dr["ShortHTM"] != 0; gc.LongDescription = (string)dr["LongDescription"]; gc.LongDescriptionInHtml = (int)dr["LongHTM"] != 0; gc.EncodedHints = (string)dr["Hints"]; gc.Url = (string)dr["url"]; if (isPremiumAvailable) { gc.MemberOnly = (int)dr["IsPremium"] != 0; } else { gc.MemberOnly = false; } gc.CustomCoords = (int)dr["HasCorrected"] != 0; if (gc.CustomCoords) { gc.CustomLat = Utils.Conversion.StringToDouble(dr["Latitude"] as String); gc.CustomLon = Utils.Conversion.StringToDouble(dr["Longitude"] as String); gc.Lat = Utils.Conversion.StringToDouble(dr["LatOriginal"] as string); gc.Lon = Utils.Conversion.StringToDouble(dr["LonOriginal"] as string); } else { gc.Lat = Utils.Conversion.StringToDouble(dr["Latitude"] as string); gc.Lon = Utils.Conversion.StringToDouble(dr["Longitude"] as string); } par.Value = gc.Code; DbDataReader attrs = lookup.ExecuteReader(); List <int> attrList = new List <int>(); while (attrs.Read()) { int attr = (int)(int)attrs["aId"]; if (attrs["aInc"].ToString() == "0") { attr *= -1; } attrList.Add(attr); } attrs.Close(); gc.AttributeIds = attrList; gc.Notes = (string)dr["UserNote"]; gc.PublishedTime = DateTime.Parse((string)dr["PlacedDate"]); if (isGCNoteAvailable) { gc.PersonaleNote = (string)dr["gcnote"]; } else { gc.PersonaleNote = ""; } gc.Flagged = (int)dr["UserFlag"] != 0; gc.Found = (int)dr["Found"] != 0; if (isFavPointAvailable) { gc.Favorites = (int)(int)dr["FavPoints"]; } else { gc.Favorites = 0; } gc.Selected = false; Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); AddGeocache(gc, null); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGGEOCACHES, gcCount, index); procStep = 0; } } dr.Close(); } import.CommandText = "select count(1) from logs"; int logCount = (int)(long)import.ExecuteScalar(); if (logCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGLOGS, logCount, 0)) { index = 0; procStep = 0; import.CommandText = "select l.lLogId, l.lParent, lDate, lTime, lBy, lownerid, lEncoded, lType, lText " + " from logs l" + " inner join logmemo m on m.lLogId = l.lLogId and m.lParent = l.lParent"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Log lg = new Framework.Data.Log(); String type = (String)dr["lType"]; int logType = (int)logTypes[type]; //id text, gccode text, tbcode text, date text, finder text, finderid text, logtext text, encoded integer, datafromdate text, logtype integer lg.ID = dr["lLogiD"].ToString(); lg.GeocacheCode = (string)dr["lParent"]; lg.TBCode = ""; lg.Date = (DateTime)dr["lDate"]; lg.Finder = (string)dr["lBy"]; lg.FinderId = dr["lownerid"].ToString(); lg.Text = (string)dr["lText"]; lg.Encoded = (long)dr["lEncoded"] != 0; lg.DataFromDate = DateTime.Now; lg.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, logType); AddLog(lg); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGLOGS, logCount, index); procStep = 0; } } dr.Close(); } } import.CommandText = "select count(1) from logimages"; int logimgCount = 0; try { logimgCount = (int)(long)import.ExecuteScalar(); } catch { //table does not exists } if (logimgCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGLOGIMAGES, logimgCount, 0)) { index = 0; procStep = 0; import.CommandText = "select iCode, iLogId, iImage, iName from logimages"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.LogImage lg = new Framework.Data.LogImage(); lg.ID = (string)dr["iCode"]; lg.LogID = dr["iLogID"].ToString(); lg.Url = (string)dr["iImage"]; lg.Name = (string)dr["iName"]; AddLogImage(lg); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGLOGIMAGES, logimgCount, index); procStep = 0; } } dr.Close(); } } //id text, code text, geocachecode text, name text, datafromdate text, comment text, description text, url text, urlname text, wptype integer, lat real, lon real, time text import.CommandText = "select count(1) from waypoints"; int wptCount = (int)(long)import.ExecuteScalar(); if (wptCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGWAYPOINTS, wptCount, 0)) { index = 0; procStep = 0; import.CommandText = "select w.cParent, w.cCode, cName, cDate, cType, cLat, cLon," + " cComment, cUrl" + " from waypoints w" + " inner join wayMemo m on w.cParent = m.cParent and w.cCode=m.cCode"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); int wpType = getWPType(((string)dr["cType"])[0]); wp.ID = (string)dr["cCode"]; wp.Code = (string)dr["cCode"]; wp.Url = (string)dr["cUrl"]; //wp.UrlName = (string)dr["urlname"]; wp.Name = (string)dr["cName"]; wp.DataFromDate = (DateTime)dr["cDate"]; wp.Comment = (string)dr["cComment"]; wp.GeocacheCode = (string)dr["cParent"]; //wp.Description = (string)dr["description"]; wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, wpType); double lat = Utils.Conversion.StringToDouble(dr["clat"] as string); double lon = Utils.Conversion.StringToDouble(dr["clon"] as string); if (Math.Abs(lat) < 0.00001) { wp.Lat = null; } else { wp.Lat = lat; } if (Math.Abs(lon) < 0.00001) { wp.Lon = null; } else { wp.Lon = lon; } wp.Time = (DateTime)dr["cDate"]; wp.Description = wp.WPType.Name; wp.UrlName = wp.WPType.Name; AddWaypoint(wp); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGWAYPOINTS, wptCount, index); procStep = 0; } } dr.Close(); } } try { //import corrected if table exists import.CommandText = "select kCode, kAfterLat, kAfterLon from Corrected"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { string gcCode = dr["kCode"] as string ?? ""; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, gcCode); if (gc != null) { object oLat = dr["kAfterLat"]; object oLon = dr["kAfterLon"]; if (oLat != null && oLat.GetType() != typeof(DBNull) && oLon != null && oLon.GetType() != typeof(DBNull)) { string sLat = oLat as string; string sLon = oLon as string; if (sLat.Length > 0 && sLon.Length > 0) { gc.CustomLat = Utils.Conversion.StringToDouble(sLat); gc.CustomLon = Utils.Conversion.StringToDouble(sLon); } } } } } catch { } } } } }
private void checkImageToLoad(object sender, EventArgs e) { string targetImageUrl = null; if (listView1.SelectedItems.Count > 0) { Framework.Data.LogImage li = listView1.SelectedItems[0].Tag as Framework.Data.LogImage; if (li != null) { Framework.Data.Log l = Core.Logs.GetLog(li.LogID); if (l != null) { linkLabel1.Links.Clear(); linkLabel1.Text = l.ID; label4.Text = l.Finder; textBox1.Text = l.Text; } else { linkLabel1.Links.Clear(); linkLabel1.Text = "-"; label4.Text = "-"; textBox1.Text = ""; } if (!PluginSettings.Instance.CacheImages && _cacheFolder != null) { targetImageUrl = li.Url; } else { string fn = System.IO.Path.Combine(_cacheFolder, System.IO.Path.GetFileName(li.Url)); if (System.IO.File.Exists(fn)) { _currentActiveImageUrl = li.Url; LoadCompleted(System.IO.File.ReadAllBytes(fn), li.Url, false); return; } else { targetImageUrl = li.Url; } } } else { linkLabel1.Links.Clear(); linkLabel1.Text = "-"; label4.Text = "-"; textBox1.Text = ""; } } if (targetImageUrl == _currentActiveImageUrl) { //ignore } else { _imageDownloader.Stop(); if (targetImageUrl == null) { Image prevImage = pictureBox1.Image; pictureBox1.Image = null; if (prevImage != null) { prevImage.Dispose(); } } else { _imageDownloader.LoadAsync(targetImageUrl); toolStripProgressBar1.Value = 0; toolStripProgressBar1.Visible = true; } _currentActiveImageUrl = targetImageUrl; } }
public static List <Framework.Data.Geocache> AddGeocaches(Framework.Interfaces.ICore core, LiveV6.Geocache[] gcList) { List <Framework.Data.Geocache> result = new List <Framework.Data.Geocache>(); if (gcList != null) { foreach (var gcApi in gcList) { Framework.Data.Geocache activeGC = Utils.API.Convert.Geocache(core, gcApi); if (AddGeocache(core, activeGC)) { if (gcApi.GeocacheLogs != null) { foreach (var l in gcApi.GeocacheLogs) { Framework.Data.Log lg = Convert.Log(core, l); AddLog(core, lg); if (l.Images != null) { foreach (var li in l.Images) { AddLogImage(core, Convert.LogImage(core, li, lg.ID)); } } } } if (gcApi.AdditionalWaypoints != null) { foreach (var wp in gcApi.AdditionalWaypoints) { AddWaypoint(core, Convert.Waypoint(core, wp)); } } List <int> ids = new List <int>(); if (gcApi.UserWaypoints != null) { foreach (var wp in gcApi.UserWaypoints) { AddUserWaypoint(core, Convert.UserWaypoint(core, wp)); ids.Add((int)wp.ID); //copy user waypoint to corrected as assumed it is if (wp.IsCorrectedCoordinate) { Framework.Data.Geocache thisGC = Utils.DataAccess.GetGeocache(core.Geocaches, activeGC.Code); if (thisGC != null) { thisGC.CustomLat = wp.Latitude; thisGC.CustomLon = wp.Longitude; } } } } DataAccess.CheckUserWaypointsForGeocache(core.UserWaypoints, gcApi.Code, ids); if (gcApi.Images != null) { foreach (var imgd in gcApi.Images) { AddGeocacheImage(core, Convert.GeocacheImage(core, imgd, activeGC.Code)); } } } } } return(result); }
private void pickRandomGeocacheMethod() { Random rnd = new Random(); Framework.Data.Geocache gc = null; while (true) { if (_checkTrigger.WaitOne()) { try { string loggerAvatar = null; gc = null; if (Properties.Settings.Default.SelectedGeocachesOnly) { List <Framework.Data.Geocache> gcList = Utils.DataAccess.GetSelectedGeocaches(Core.Geocaches); if (gcList.Count > 2) { //just pick a random one int index = rnd.Next(gcList.Count - 1); gc = gcList[index]; } } else if (Core.Geocaches.Count > 2) { //just pick a random one int index = rnd.Next(Core.Geocaches.Count - 1); gc = (Framework.Data.Geocache)Core.Geocaches[index]; } if (gc != null) { Framework.Data.Log log = Utils.DataAccess.GetLogs(Core.Logs, gc.Code).FirstOrDefault(); if (Properties.Settings.Default.GetLoggerAvatar && log != null && !string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken)) { try { using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken))) { var req = new Utils.API.LiveV6.GetAnotherUsersProfileRequest(); req.AccessToken = client.Token; req.ProfileOptions = new Utils.API.LiveV6.UserProfileOptions(); req.ProfileOptions.PublicProfileData = true; if (log != null) { if (log.FinderId.StartsWith("G")) { req.UserID = Utils.Conversion.GetCacheIDFromCacheCode(log.FinderId); } else { req.UserID = int.Parse(log.FinderId); } } var resp = client.Client.GetAnotherUsersProfile(req); if (resp != null && resp.Status.StatusCode == 0) { loggerAvatar = resp.Profile.User.AvatarUrl; } } } catch { } } _context.Send(new SendOrPostCallback(delegate(object state) { try { if (!this.IsDisposed && this.Visible) { Core.ActiveGeocache = gc; label1.Text = DateTime.Now.ToString(); linkLabelGC.Links.Clear(); pictureBoxGC.ImageLocation = Utils.ImageSupport.Instance.GetImagePath(Core, Framework.Data.ImageSize.Default, gc.GeocacheType); linkLabelGC.Text = string.Format("{0}, {1}", gc.Code, gc.Name); linkLabelGC.Links.Add(0, gc.Code.Length, gc.Url); if (!string.IsNullOrEmpty(loggerAvatar)) { pictureBox1.Visible = true; pictureBox1.ImageLocation = loggerAvatar; } else { pictureBox1.Visible = false; } if (log != null) { label1.Text = log.Date.ToLongDateString(); label3.Text = log.Finder ?? ""; label5.Text = log.Text ?? ""; } else { label3.Text = ""; label5.Text = ""; } } } catch { } }), null); } } catch { } } } }
public override bool Load(bool geocachesOnly) { bool result = true; if (_dbcon != null) { List<string> activeAttr = new List<string>(); using (MySqlCommand cmd = new MySqlCommand("select field_name from geocache_cfields", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { string s = string.Format("{0}", dr["field_name"]); activeAttr.Add(s); Core.Geocaches.AddCustomAttribute(s); } int gcCount = 0; int logCount = 0; int logimgCount = 0; int wptCount = 0; using (MySqlCommand cmd = new MySqlCommand("select geocache, log, waypoint, logimage from counter", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) if (dr.Read()) { gcCount = (int)dr["geocache"]; logCount = (int)dr["log"]; logimgCount = (int)dr["waypoint"]; wptCount = (int)dr["logimage"]; } using (Utils.ProgressBlock fixscr = new ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select id, code, name, datafromdate, lat, lon, disttocent, angletocent, available, archived, country, state, cachetype, placedby, owner, ownerid, container, terrain, difficulty, encodedhints, url, memberonly, customcoords, attrids, favorites, selected, municipality, city, customlat, customlon, notes, publiceddate, personalnote, flagged, found, locked from geocache", _dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.ID = (string)dr["id"]; gc.Code = (string)dr["code"]; if (string.IsNullOrEmpty(gc.ID) && !string.IsNullOrEmpty(gc.Code) && gc.Code.ToUpper().StartsWith("GC")) { gc.ID = Utils.Conversion.GetCacheIDFromCacheCode(gc.Code).ToString(); } gc.Name = (string)dr["name"]; gc.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); gc.Lat = (double)(float)dr["lat"]; gc.Lon = (double)(float)dr["lon"]; //gc.DistanceToCenter = (int)dr["disttocent"]; //gc.AngleToCenter = (int)dr["angletocent"]; gc.Available = (int)dr["available"] != 0; gc.Archived = (int)dr["archived"] != 0; gc.Country = (string)dr["country"]; gc.State = (string)dr["state"]; gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, (int)dr["cachetype"]); gc.PlacedBy = (string)dr["placedby"]; gc.Owner = (string)dr["owner"]; gc.OwnerId = (string)dr["ownerid"]; gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, (int)dr["container"]); gc.Terrain = (double)(float)dr["terrain"]; gc.Difficulty = (double)(float)dr["difficulty"]; gc.EncodedHints = (string)dr["encodedhints"]; gc.Url = (string)dr["url"]; gc.MemberOnly = (int)dr["memberonly"] != 0; gc.CustomCoords = (int)dr["customcoords"] != 0; string s = (string)dr["attrids"]; string[] parts = s.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); List<int> attrList = new List<int>(); if (parts != null) { foreach (string si in parts) { attrList.Add(int.Parse(si)); } } gc.AttributeIds = attrList; gc.Municipality = (string)dr["municipality"]; gc.City = (string)dr["city"]; object o = dr["customlat"]; if (o == null || o.GetType() == typeof(DBNull)) { gc.CustomLat = null; } else { gc.CustomLat = (double?)(float)o; } o = dr["customlon"]; if (o == null || o.GetType() == typeof(DBNull)) { gc.CustomLon = null; } else { gc.CustomLon = (double?)(float)o; } gc.Notes = (string)dr["notes"]; gc.PublishedTime = DateTime.Parse((string)dr["publiceddate"]).ToLocalTime(); gc.PersonaleNote = (string)dr["personalnote"]; gc.Flagged = (int)dr["flagged"] != 0; gc.Locked = (int)dr["locked"] != 0; gc.Found = (int)dr["found"] != 0; gc.Favorites = (int)dr["favorites"]; gc.Selected = (int)dr["selected"] != 0; foreach (string attrField in activeAttr) { object objValue = null; try { objValue = dr[string.Format("_{0}", attrField)]; } catch { } gc.SetCustomAttribute(attrField, objValue); } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); gc.Saved = true; gc.IsDataChanged = false; _geocachesInDB[gc.Code] = gc.Code; Core.Geocaches.Add(gc); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); procStep = 0; } } } } if (!geocachesOnly) { using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select ID, gccode, Finder, DataFromDate, LogType, Date from log", _dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Log lg = new Framework.Data.Log(); //id text, gccode text, tbcode text, date text, finder text, finderid text, logtext text, encoded integer, datafromdate text, logtype integer lg.ID = (string)dr["id"]; lg.GeocacheCode = (string)dr["gccode"]; lg.Date = DateTime.Parse((string)dr["date"]).ToLocalTime(); lg.Finder = (string)dr["finder"]; lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); lg.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, (int)dr["logtype"]); lg.Saved = true; lg.IsDataChanged = false; _logsInDB[lg.ID] = lg.ID; Core.Logs.Add(lg); index++; procStep++; if (procStep >= 20000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); procStep = 0; } } } } //(id text, logid text, url text, name text, datafromdate text) using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select * from logimage", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.LogImage lg = new Framework.Data.LogImage(); lg.ID = (string)dr["id"]; lg.LogID = (string)dr["logid"]; lg.Url = (string)dr["url"]; lg.Name = (string)dr["name"]; lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); lg.Saved = true; lg.IsDataChanged = false; _logimgsInDB[lg.ID] = lg.ID; Core.LogImages.Add(lg); index++; procStep++; if (procStep >= 2000) { progress.UpdateProgress("Loading...", "Loading log images...", logimgCount, index); procStep = 0; } } } //id text, code text, geocachecode text, name text, datafromdate text, comment text, description text, url text, urlname text, wptype integer, lat real, lon real, time text using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select * from waypoint", _dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.ID = (string)dr["id"]; wp.Code = (string)dr["code"]; wp.Url = (string)dr["url"]; wp.UrlName = (string)dr["urlname"]; wp.Name = (string)dr["name"]; wp.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); wp.Comment = (string)dr["comment"]; wp.GeocacheCode = (string)dr["geocachecode"]; wp.Description = (string)dr["description"]; wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, (int)dr["wptype"]); object o = dr["lat"]; if (o == null || o.GetType() == typeof(DBNull)) { wp.Lat = null; } else { wp.Lat = (double?)(float)o; } o = dr["lon"]; if (o == null || o.GetType() == typeof(DBNull)) { wp.Lon = null; } else { wp.Lon = (double?)(float)o; } wp.Time = DateTime.Parse((string)dr["time"]).ToLocalTime(); wp.Saved = true; wp.IsDataChanged = false; _wptsInDB[wp.Code] = wp.Code; Core.Waypoints.Add(wp); index++; procStep++; if (procStep >= 20000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } } } using (MySqlCommand cmd = new MySqlCommand("select * from userwaypoint", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = (int)dr["id"]; wp.GeocacheCode = (string)dr["geocachecode"]; wp.Description = (string)dr["description"]; wp.Lat = (double)(float)dr["lat"]; wp.Lon = (double)(float)dr["lon"]; wp.Date = DateTime.Parse((string)dr["time"]).ToLocalTime(); wp.Saved = true; wp.IsDataChanged = false; _usrwptsInDB[wp.ID] = wp.ID; Core.UserWaypoints.Add(wp); } } } } return result; }
public static Framework.Data.Log Log(Framework.Interfaces.ICore core, LiveV6.GeocacheLog lg) { Framework.Data.Log result = null; if (lg != null) { Framework.Data.Log tmp = DataAccess.GetLog(core.Logs, lg.Code); result = new Framework.Data.Log(); if (tmp != null) { result.UpdateFrom(tmp); } result.DataFromDate = DateTime.Now; result.Date = lg.VisitDate; result.Encoded = lg.LogIsEncoded; result.Finder = lg.Finder.UserName; result.FinderId = lg.Finder.Id.ToString(); result.GeocacheCode = lg.CacheCode; result.ID = lg.Code; result.LogType = DataAccess.GetLogType(core.LogTypes, (int)lg.LogType.WptLogTypeId); result.Text = lg.LogText; } return result; }
public override bool LoadLogs(List<Framework.Data.Log> logs) { bool result = true; int index = 0; if (File.Exists(_fileCollection.DatabaseInfoFilename)) { //int procStep = 0; DateTime nextUpdateTime = DateTime.MinValue; int lsize = sizeof(long); byte[] memBuffer = new byte[50 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) { int logCount = 0; XmlDocument doc = new XmlDocument(); doc.Load(_fileCollection.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText); UpdateLoadingInBackgroundProgress(STR_LOADING_LOGS_BG, logCount, 0); FileStream fs = _fileCollection._fsLogs; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); 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) { //lazy loading ri.FreeSlot = false; int readCount = Math.Min(42, (int)(ri.Length - lsize - 1)); fs.Read(memBuffer, 0, readCount); ms.Position = 0; ri.ID = br.ReadString(); fs.Position = ri.Offset + ri.Length; } 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; logs.Add(log); index++; //procStep++; //if (procStep >= 20000) if (DateTime.Now >= nextUpdateTime) { UpdateLoadingInBackgroundProgress(STR_LOADING_LOGS_BG, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); //procStep = 0; } } _fileCollection._logsInDB.Add(ri.ID, ri); } } } return result; }
public void Import(Framework.Interfaces.ICore core, Utils.BasePlugin.Plugin owner, string fileName) { using (Utils.ProgressBlock upd = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT, 1, 0)) { using (FileStream fs = File.OpenRead(fileName)) using (BinaryReader br = new BinaryReader(fs)) { string tag = br.ReadString(); if (tag == "GAPP") { bool IsLittleEndian = br.ReadBoolean(); int version = br.ReadInt32(); if (IsLittleEndian == BitConverter.IsLittleEndian && version<=3) { int count = br.ReadInt32(); using (Utils.ProgressBlock prog = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT_CACHES, count, 0)) { for (int index = 0; index < count; index++) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Code = 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(); string s = br.ReadString(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); 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.Selected = br.ReadBoolean(); gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); if (version > 1) { gc.Locked = br.ReadBoolean(); } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, core.CenterLocation); (owner as Import).AddImportedGeocache(gc); int logcount = br.ReadInt32(); for (int lc = 0; lc < logcount; lc++) { Framework.Data.Log log = new Framework.Data.Log(); log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Encoded = br.ReadBoolean(); log.Finder = br.ReadString(); log.FinderId = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(core.LogTypes, br.ReadInt32()); log.TBCode = br.ReadString(); log.Text = br.ReadString(); (owner as Import).AddImportedLog(log); int logimgcount = br.ReadInt32(); for (int lic = 0; lic < logimgcount; lic++) { Framework.Data.LogImage li = new Framework.Data.LogImage(); li.DataFromDate = DateTime.Parse(br.ReadString()); li.ID = br.ReadString(); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); (owner as Import).AddImportedLogImage(li); } } int wpcount = br.ReadInt32(); for (int wpc = 0; wpc < wpcount; wpc++) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.Code = br.ReadString(); 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()); (owner as Import).AddImportedWaypoint(wp); } if (version > 2) { int usrwpcount = br.ReadInt32(); for (int wpc = 0; wpc < usrwpcount; wpc++) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = br.ReadInt32(); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); (owner as Import).AddImportedUserWaypoint(wp); } } if (index % 200 == 0) { prog.UpdateProgress(STR_IMPORT, STR_IMPORT_CACHES, count, index); } } } } else { //message } } else { //message } } } }
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); }
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); }