public override object GetValue(Framework.Data.Geocache gc) { StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(gc.ShortDescription)) { if (!gc.ShortDescriptionInHtml) { string s = gc.ShortDescription.Replace("\r\n", "cvcvcvcvcvc"); s = System.Web.HttpUtility.HtmlEncode(s); s = s.Replace("cvcvcvcvcvc", "<br />"); sb.AppendLine(s); } else { sb.AppendLine(gc.ShortDescription); } sb.AppendLine("<br />"); } if (!string.IsNullOrEmpty(gc.LongDescription)) { if (!gc.LongDescriptionInHtml) { string s = gc.LongDescription.Replace("\r\n", "cvcvcvcvcvc"); s = System.Web.HttpUtility.HtmlEncode(s); s = s.Replace("cvcvcvcvcvc", "<br />"); sb.AppendLine(s); } else { sb.AppendLine(gc.LongDescription); } } return(sb.ToString()); }
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); }
////////////////////////////////////////////////////////////// //defines the filename based on wpt attribute & opens the file // if new ////////////////////////////////////////////////////////////// private System.IO.StreamWriter WptCsv(Framework.Data.Geocache gc, Framework.Data.Waypoint wpt) { string csvName = null; string postFix = ""; switch (wpt.WPType.ID) { case 217: csvName = "Parking_Area"; break; case 218: csvName = "Question_to_Answer"; break; case 219: csvName = "Stages_of_a_Multicache"; break; case 220: csvName = "Final_Location"; break; case 221: csvName = "Trailhead"; break; case 452: csvName = "Reference_Point"; break; default: csvName = wpt.WPType.Name.Replace(" ", "_"); break; } if (gc.Found) { postFix = "_Found"; } if (!gc.Available || gc.Archived) { postFix = "_Disabled"; } csvName = csvName + postFix; if (!sd.ContainsKey(csvName)) { //new -> open File System.IO.StreamWriter cs = null; string csvPath = PluginSettings.Instance.POIExportPath + Path.DirectorySeparatorChar + csvName + ".csv"; cs = new System.IO.StreamWriter(csvPath, false, Encoding.GetEncoding(1250), 32768); sd.Add(csvName, cs); //create wpt icon try { using (Stream input = Assembly.GetExecutingAssembly().GetManifestResourceStream("GlobalcachingApplication.Plugins.ExportGarminPOI.Resources." + csvName + ".bmp")) using (Stream output = File.Create(PluginSettings.Instance.POIExportPath + Path.DirectorySeparatorChar + csvName + ".bmp")) { input.CopyTo(output); } } catch { } //ignore invalid resource or write errors here } return(sd[csvName]); }
private Framework.Data.Geocache getGeocache(string code) { Cursor = Cursors.WaitCursor; Framework.Data.Geocache result = null; try { Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest(); req.IsLite = _core.GeocachingComAccount.MemberTypeId == 1; req.AccessToken = _client.Token; req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter(); req.CacheCode.CacheCodes = new string[] { code }; req.MaxPerPage = 1; req.GeocacheLogCount = 5; var resp = _client.Client.SearchForGeocaches(req); if (resp.Status.StatusCode == 0 && resp.Geocaches != null) { Utils.API.Import.AddGeocaches(_core, resp.Geocaches); } else { System.Windows.Forms.MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } catch { } Cursor = Cursors.Default; return(result); }
private void button1_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { using (Utils.DBCon dbcon = initDatabase()) { Framework.Data.Location l = Utils.Conversion.StringToLocation(textBox1.Text); if (l != null && listView1.SelectedItems.Count > 0) { Framework.Data.Geocache gc = listView1.SelectedItems[0].Tag as Framework.Data.Geocache; if (dbcon.ExecuteNonQuery(string.Format("update coord set lat={0}, lon={1} where code='{2}'", l.SLat, l.SLon, gc.Code.Replace("'", "''"))) == 0) { dbcon.ExecuteNonQuery(string.Format("insert into coord (lat, lon, code) values ({0}, {1}, '{2}')", l.SLat, l.SLon, gc.Code.Replace("'", "''"))); } gc.BeginUpdate(); gc.Lat = l.Lat; gc.Lon = l.Lon; gc.EndUpdate(); listView1.Items.Remove(listView1.SelectedItems[0]); } } } catch { } this.Cursor = Cursors.Default; }
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); }
private void button2_Click(object sender, EventArgs e) { List <OfflineLogInfo> processed = new List <OfflineLogInfo>(); foreach (OfflineLogInfo oi in listBox1.Items) { Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(_core.Geocaches, oi.GeocacheCode); if (gc == null) { gc = getGeocache(oi.GeocacheCode); } if (gc != null) { using (GeocacheLogForm dlg = new GeocacheLogForm(_core, _client, gc, oi)) { if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { processed.Add(oi); } else { break; } } } } foreach (OfflineLogInfo oi in processed) { listBox1.Items.Remove(oi); } }
public bool IgnoreGeocache(Framework.Data.Geocache gc) { bool result = false; if ((_filterFields[FilterField.GeocacheCode.ToString()] as Hashtable)[gc.Code] != null) { result = true; } else { if (!string.IsNullOrEmpty(gc.Name)) { foreach (string s in (_filterFields[FilterField.GeocacheName.ToString()] as Hashtable).Keys) { if (gc.Name.IndexOf(s, StringComparison.InvariantCultureIgnoreCase) >= 0) { result = true; break; } } } if (!result && !string.IsNullOrEmpty(gc.Owner)) { foreach (string s in (_filterFields[FilterField.GeocacheOwner.ToString()] as Hashtable).Keys) { if (string.Compare(gc.Owner, s, true) == 0) { result = true; break; } } } } return(result); }
public string Start() { _index = 0; _activeGcg = null; StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); if (_gpxVersion == V100) { sb.AppendLine("<gpx xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" version=\"1.0\" creator=\"Globalcaching Pocket Query\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0 http://www.groundspeak.com/cache/1/0/cache.xsd\" xmlns=\"http://www.topografix.com/GPX/1/0\">"); } else if (_gpxVersion == V101) { sb.AppendLine("<gpx xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" version=\"1.0\" creator=\"Globalcaching Pocket Query\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0/1 http://www.groundspeak.com/cache/1/0/1/cache.xsd\" xmlns=\"http://www.topografix.com/GPX/1/0\">"); } else { sb.AppendLine("<gpx xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" version=\"1.0\" creator=\"Globalcaching Pocket Query\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0/2 http://www.groundspeak.com/cache/1/0/2/cache.xsd\" xmlns=\"http://www.topografix.com/GPX/1/0\">"); } sb.AppendLine(" <name>Pocket Query</name>"); sb.AppendLine(" <desc>Geocache file generated by Globalcaching App</desc>"); sb.AppendLine(" <author>Globalcaching</author>"); sb.AppendLine(" <email>[email protected]</email>"); sb.AppendLine(" <url>http://www.globalcaching.eu</url>"); sb.AppendLine(" <urlname>Geocaching - High Tech Treasure Hunting</urlname>"); sb.AppendLine(string.Format(" <time>{0}Z</time>", DateTime.Now.ToUniversalTime().ToString("s"))); sb.AppendLine(" <keywords>cache, geocache, globalcaching</keywords>"); sb.AppendLine(string.Format(" <bounds minlat=\"{0}\" minlon=\"{1}\" maxlat=\"{2}\" maxlon=\"{3}\" />", _gcList.Min(x => x.Lat).ToString().Replace(',', '.'), _gcList.Min(x => x.Lon).ToString().Replace(',', '.'), _gcList.Max(x => x.Lat).ToString().Replace(',', '.'), _gcList.Max(x => x.Lon).ToString().Replace(',', '.'))); return(sb.ToString()); }
protected virtual bool AddGeocache(Framework.Data.Geocache gc) { bool result = false; if (_cachesEmpty) { Core.Geocaches.Add(gc); result = true; } else { Framework.Data.Geocache oldgc = Utils.DataAccess.GetGeocache(Core.Geocaches, gc.Code); if (oldgc == null) { Core.Geocaches.Add(gc); result = true; } else { if (gc.DataFromDate >= oldgc.DataFromDate) { Utils.DataAccess.UpdateGeocacheData(oldgc, gc, null); } } } return(result); }
public override object GetValue(Framework.Data.Geocache gc) { StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(gc.ShortDescription)) { if (gc.ShortDescriptionInHtml) { sb.AppendLine(Utils.Conversion.StripHtmlTags(gc.ShortDescription)); } else { sb.AppendLine(gc.ShortDescription); } } if (!string.IsNullOrEmpty(gc.LongDescription)) { if (gc.LongDescriptionInHtml) { sb.AppendLine(Utils.Conversion.StripHtmlTags(gc.LongDescription)); } else { sb.AppendLine(gc.LongDescription); } } return(sb.ToString()); }
private async void button4_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0 && await addGeocachesToDatabase((from ListViewItem a in listView1.SelectedItems select a).ToList())) { //right order List <ListViewItem> lvil = new List <ListViewItem>(); foreach (ListViewItem lvi in listView1.Items) { if (lvi.Selected) { lvil.Add(lvi); } } foreach (ListViewItem lvi in lvil) { Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(_core.Geocaches, (lvi.Tag as GeocacheVisitsItem).Code); if (gc != null) { using (GeocacheLogForm dlg = new GeocacheLogForm(_core, _client, gc, lvil[0].Tag as GeocacheVisitsItem)) { dlg.AskForNext = false; if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK) { break; } } } } } }
public void UpdateView() { if (Visible) { listBox1.Items.Clear(); if (Core.ActiveGeocache == null) { button1.Enabled = false; } else { button1.Enabled = true; Framework.Data.Geocache gc = Core.ActiveGeocache; List <Framework.Data.Waypoint> wpList = Utils.DataAccess.GetWaypointsFromGeocache(Core.Waypoints, gc.Code); foreach (Framework.Data.Waypoint wp in wpList) { WaypointListItem wpi = new WaypointListItem(); wpi.WP = wp; listBox1.Items.Add(wpi); } } listBox1_SelectedIndexChanged(this, EventArgs.Empty); } }
public static void SetDistanceAndAngleGeocacheFromLocation(Framework.Data.Geocache gc, Framework.Data.Location loc) { GeodeticMeasurement gm = CalculateDistance(loc.Lat, loc.Lon, gc.Lat, gc.Lon); gc.DistanceToCenter = (long)gm.EllipsoidalDistance; gc.AngleToCenter = (int)gm.Azimuth.Degrees; }
public void OnCacheAdded(Framework.Data.Geocache gc) { if (!_updating && GeocacheAdded != null) { GeocacheAdded(this, new Framework.EventArguments.GeocacheEventArgs(gc)); } OnListDataChanged(); }
public override ActionImplementation.Operator Process(Framework.Data.Geocache gc) { if (!_hasBeenExecuted) { _hasBeenExecuted = Execute(); } return(Operator.Equal); }
public override void Remove(object value) { Framework.Data.Geocache gc = value as Framework.Data.Geocache; if (gc != null) { RemoveAt(IndexOf(gc)); } }
void Geocaches_DataChanged(object sender, Framework.EventArguments.GeocacheEventArgs e) { if (this.Visible) { _activeGeocache = null; clusterGeocaches(true); UpdateView(true); } }
public void OnSelectedChanged(Framework.Data.Geocache gc) { _selectedChanged = true; if (!_updating && SelectedChanged != null) { SelectedChanged(this, new Framework.EventArguments.GeocacheEventArgs(gc)); _selectedChanged = false; } }
public void OnDataChanged(Framework.Data.Geocache gc) { _dataChanged = true; if (!_updating && DataChanged != null) { DataChanged(this, new Framework.EventArguments.GeocacheEventArgs(gc)); _dataChanged = false; gc.IsDataChanged = false; } }
public override bool ExpressionResult(Framework.Data.Geocache gc, QueryExpression.Operator op, string condition) { int con = 0; if (!string.IsNullOrEmpty(condition)) { int.TryParse(condition, out con); } return(intExpresionResult(op, gc.Favorites, con)); }
private void addGeocacheToList(Framework.Data.Geocache gc) { if ((from ListViewItem l in listView1.Items where (l.Tag as Framework.Data.Geocache).Code == gc.Code select l).FirstOrDefault() == null) { ListViewItem lvi = new ListViewItem(new string[] { gc.Code, gc.Name ?? "" }); lvi.Tag = gc; lvi.Checked = true; listView1.Items.Add(lvi); checkSubmitButton(); } }
private void button2_Click(object sender, EventArgs e) { Framework.Data.Geocache gc = Core.ActiveGeocache; Framework.Data.Location l; gc.BeginUpdate(); try { gc.Name = textBox1.Text; //gc.ID = textBox2.Text; //gc.Code = textBox3.Text; l = Utils.Conversion.StringToLocation(textBox4.Text); if (l != null) { gc.Lat = l.Lat; gc.Lon = l.Lon; } gc.Owner = textBox5.Text; gc.PlacedBy = textBox6.Text; gc.OwnerId = textBox7.Text; gc.EncodedHints = textBox8.Text; gc.Url = textBox9.Text; l = Utils.Conversion.StringToLocation(textBox10.Text); if (l != null) { gc.CustomLat = l.Lat; gc.CustomLon = l.Lon; } else { gc.CustomLat = null; gc.CustomLon = null; } gc.PersonaleNote = textBox11.Text; gc.Available = checkBox1.Checked; gc.Archived = checkBox2.Checked; gc.MemberOnly = checkBox3.Checked; gc.Found = checkBox4.Checked; gc.Locked = checkBox5.Checked; gc.PublishedTime = dateTimePicker1.Value; gc.Country = comboBox1.Text; gc.State = comboBox2.Text; gc.Municipality = comboBox3.Text; gc.City = comboBox4.Text; gc.GeocacheType = comboBoxCacheType1.SelectedItem as Framework.Data.GeocacheType; gc.Container = comboBoxContainerType1.SelectedItem as Framework.Data.GeocacheContainer; gc.Terrain = Utils.Conversion.StringToDouble(comboBox5.SelectedItem.ToString()); gc.Difficulty = Utils.Conversion.StringToDouble(comboBox6.SelectedItem.ToString()); gc.Favorites = (int)numericUpDown1.Value; } catch { } gc.EndUpdate(); }
public static bool UpdateGeocacheData(Framework.Data.Geocache gc, Framework.Data.Geocache newData, Version gpxDataVersion) { bool result = false; if (gc.Code == newData.Code) { gc.UpdateFrom(newData, gpxDataVersion); result = true; } return(result); }
private void saveOfflineLogs() { _core.Geocaches.BeginUpdate(); try { XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("logs"); doc.AppendChild(root); foreach (OfflineLogInfo oi in listBox1.Items) { XmlElement log = doc.CreateElement("log"); root.AppendChild(log); XmlElement el = doc.CreateElement("Code"); XmlText txt = doc.CreateTextNode(oi.GeocacheCode); el.AppendChild(txt); log.AppendChild(el); el = doc.CreateElement("Name"); txt = doc.CreateTextNode(oi.GeocacheName ?? ""); el.AppendChild(txt); log.AppendChild(el); el = doc.CreateElement("Date"); txt = doc.CreateTextNode(oi.LogDate.ToString("s")); el.AppendChild(txt); log.AppendChild(el); el = doc.CreateElement("Text"); txt = doc.CreateTextNode(oi.LogText); el.AppendChild(txt); log.AppendChild(el); el = doc.CreateElement("Type"); txt = doc.CreateTextNode(oi.LogType.ID.ToString()); el.AppendChild(txt); log.AppendChild(el); if (oi.LogType.AsFound) { Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(_core.Geocaches, oi.GeocacheCode); if (gc != null) { gc.Found = true; } } } doc.Save(_offlineLogsFile); } catch { } _core.Geocaches.EndUpdate(); }
public override object GetValue(Framework.Data.Geocache gc) { StringBuilder result = new StringBuilder(); List <Framework.Data.AreaInfo> al = Utils.GeometrySupport.Instance.GetAreasOfLocation(new Framework.Data.Location(gc.Lat, gc.Lon), Utils.GeometrySupport.Instance.GetAreasByLevel(Framework.Data.AreaType.Other)); foreach (Framework.Data.AreaInfo a in al) { result.AppendLine(a.Name); } return(result.ToString()); }
private void buttonAdd_Click(object sender, EventArgs e) { Framework.Data.Geocache gc = null; if (textBox1.Text.Length > 0) { gc = Utils.DataAccess.GetGeocache(_core.Geocaches, textBox1.Text.ToUpper()); if (gc == null) { //not in our system, try geocaching.com if (textBox1.Text.ToUpper().StartsWith("GC")) { Cursor = Cursors.WaitCursor; try { var req = new Utils.API.LiveV6.SearchForGeocachesRequest(); req.AccessToken = _client.Token; req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter() { CacheCodes = new string[] { textBox1.Text.ToUpper() } }; req.IsLite = _core.GeocachingComAccount.MemberTypeId == 1; req.MaxPerPage = 1; req.GeocacheLogCount = 0; var resp = _client.Client.SearchForGeocaches(req); if (resp.Status.StatusCode == 0) { if (resp.Geocaches != null && resp.Geocaches.Length > 0) { gc = Utils.API.Convert.Geocache(_core, resp.Geocaches[0]); } } else { if (!string.IsNullOrEmpty(resp.Status.StatusMessage)) { MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILUNKNOWN), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } Cursor = Cursors.Default; } } if (gc != null) { addGeocacheToList(gc); checkSubmitButton(); } } }
public void OnCacheRemoved(Framework.Data.Geocache gc) { if (!_updating && GeocacheRemoved != null) { GeocacheRemoved(this, new Framework.EventArguments.GeocacheEventArgs(gc)); } if (gc.Selected) { OnListSelectionChanged(); } OnListDataChanged(); }
private void button5_Click(object sender, EventArgs e) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); int maxId = int.MaxValue - 411120 - 100; bool found = true; string gcCode = ""; while (found) { maxId--; gcCode = Utils.Conversion.GetCacheCodeFromCacheID(maxId); found = Utils.DataAccess.GetGeocache(Core.Geocaches, gcCode) != null; } gc.Code = gcCode; gc.ID = maxId.ToString(); gc.Archived = false; gc.Available = true; gc.City = ""; gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, 3); gc.Country = ""; gc.Difficulty = 1.0; gc.EncodedHints = ""; gc.Favorites = 0; gc.Flagged = false; gc.Found = false; gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 2); gc.Lat = Core.CenterLocation.Lat; gc.Locked = false; gc.Lon = Core.CenterLocation.Lon; gc.LongDescription = ""; gc.LongDescriptionInHtml = false; gc.MemberOnly = false; gc.Municipality = ""; gc.Name = Utils.LanguageSupport.Instance.GetTranslation(STR_NONAME); gc.Notes = ""; gc.Owner = Core.GeocachingComAccount.AccountName; gc.OwnerId = "0"; gc.PersonaleNote = ""; gc.PlacedBy = Core.GeocachingComAccount.AccountName; gc.PublishedTime = DateTime.Now; gc.Saved = false; gc.Selected = false; gc.ShortDescription = ""; gc.ShortDescriptionInHtml = false; gc.State = ""; gc.Terrain = 1.0; gc.Title = gc.Name; gc.Url = ""; Core.Geocaches.Add(gc); Core.ActiveGeocache = gc; }
public override bool ExpressionResult(Framework.Data.Geocache gc, QueryExpression.Operator op, string condition) { QueryBuilderForm.FreeQuery fq = (from q in QueryBuilderForm.AvailableQueries where q.Name == condition select q).FirstOrDefault(); if (fq == null) { return(false); } else { return(QueryBuilderForm.GetQueryResult(fq, gc)); } }
public void SetGeocacheList(List<Framework.Data.Geocache> gcList) { _gcList = gcList; _index = 0; _activeGcg = null; }
public string Start() { _index = 0; _activeGcg = null; StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); if (_gpxVersion == V100) { sb.AppendLine("<gpx xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" version=\"1.0\" creator=\"Globalcaching Pocket Query\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0 http://www.groundspeak.com/cache/1/0/cache.xsd\" xmlns=\"http://www.topografix.com/GPX/1/0\">"); } else if (_gpxVersion == V101) { sb.AppendLine("<gpx xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" version=\"1.0\" creator=\"Globalcaching Pocket Query\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0/1 http://www.groundspeak.com/cache/1/0/1/cache.xsd\" xmlns=\"http://www.topografix.com/GPX/1/0\">"); } else { sb.AppendLine("<gpx xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" version=\"1.0\" creator=\"Globalcaching Pocket Query\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.groundspeak.com/cache/1/0/2 http://www.groundspeak.com/cache/1/0/2/cache.xsd\" xmlns=\"http://www.topografix.com/GPX/1/0\">"); } sb.AppendLine(" <name>Pocket Query</name>"); sb.AppendLine(" <desc>Geocache file generated by Globalcaching App</desc>"); sb.AppendLine(" <author>Globalcaching</author>"); sb.AppendLine(" <email>[email protected]</email>"); sb.AppendLine(" <url>http://www.globalcaching.eu</url>"); sb.AppendLine(" <urlname>Geocaching - High Tech Treasure Hunting</urlname>"); sb.AppendLine(string.Format(" <time>{0}Z</time>", DateTime.Now.ToUniversalTime().ToString("s"))); sb.AppendLine(" <keywords>cache, geocache, globalcaching</keywords>"); sb.AppendLine(string.Format(" <bounds minlat=\"{0}\" minlon=\"{1}\" maxlat=\"{2}\" maxlon=\"{3}\" />", _gcList.Min(x => x.Lat).ToString().Replace(',','.'), _gcList.Min(x => x.Lon).ToString().Replace(',', '.'), _gcList.Max(x => x.Lat).ToString().Replace(',', '.'), _gcList.Max(x => x.Lon).ToString().Replace(',', '.'))); return sb.ToString(); }
private void buttonSelect_Click(object sender, EventArgs e) { _gc = null; if (textBoxGC.Text.Length > 0) { _gc = Utils.DataAccess.GetGeocache(_core.Geocaches, textBoxGC.Text.ToUpper()); if (_gc == null) { //not in our system, try geocaching.com if (textBoxGC.Text.ToUpper().StartsWith("GC")) { Cursor = Cursors.WaitCursor; try { var req = new Utils.API.LiveV6.SearchForGeocachesRequest(); req.AccessToken = _client.Token; req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter() { CacheCodes = new string[] { textBoxGC.Text.ToUpper() } }; req.IsLite = _core.GeocachingComAccount.MemberTypeId == 1; req.MaxPerPage = 1; req.GeocacheLogCount = 0; var resp = _client.Client.SearchForGeocaches(req); if (resp.Status.StatusCode == 0) { if (resp.Geocaches != null && resp.Geocaches.Length > 0) { _gc = Utils.API.Convert.Geocache(_core, resp.Geocaches[0]); } } else { if (!string.IsNullOrEmpty(resp.Status.StatusMessage)) { MessageBox.Show(resp.Status.StatusMessage, Utils.LanguageSupport.Instance.GetTranslation(Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)), MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { System.Windows.Forms.MessageBox.Show(Utils.LanguageSupport.Instance.GetTranslation(STR_FAILUNKNOWN), Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } Cursor = Cursors.Default; } } } updateGCInfo(); }
public string Next() { string result = ""; XmlDocument doc = new XmlDocument(); if (_index < _gcList.Count) { Framework.Data.Geocache gc = _gcList[_index]; _activeGcg = gc; XmlElement wpt = doc.CreateElement("wpt"); XmlAttribute attr = doc.CreateAttribute("lat"); XmlText txt = doc.CreateTextNode(gc.CustomLat == null ? gc.Lat.ToString().Replace(',', '.') : gc.CustomLat.ToString().Replace(',', '.')); attr.AppendChild(txt); wpt.Attributes.Append(attr); attr = doc.CreateAttribute("lon"); txt = doc.CreateTextNode(gc.CustomLon == null ? gc.Lon.ToString().Replace(',', '.') : gc.CustomLon.ToString().Replace(',', '.')); attr.AppendChild(txt); wpt.Attributes.Append(attr); doc.AppendChild(wpt); XmlElement el = doc.CreateElement("time"); txt = doc.CreateTextNode(string.Format("{0}Z",gc.PublishedTime.ToString("s"))); el.AppendChild(txt); wpt.AppendChild(el); string nameValue; if (_useNameForGCCode) { nameValue = transformedGeocacheName(gc.Name ?? ""); } else { nameValue = gc.Code; } el = doc.CreateElement("name"); if (gc.ContainsCustomLatLon) { txt = doc.CreateTextNode(string.Format("{0}{1}", _extraCoordPrefix ?? "", nameValue)); } else { txt = doc.CreateTextNode(nameValue); } el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("desc"); if (_useHintsForDescription) { txt = doc.CreateTextNode(gc.EncodedHints ?? ""); } else { txt = doc.CreateTextNode(string.Format("{0} by {1}, {2} ({3}/{4})", transformedGeocacheName(gc.Name), gc.Owner, gc.GeocacheType.GPXTag, gc.Difficulty.ToString("0.#").Replace(',', '.'), gc.Terrain.ToString("0.#").Replace(',', '.'))); } el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("url"); txt = doc.CreateTextNode(gc.Url); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("urlname"); txt = doc.CreateTextNode(transformedGeocacheName(gc.Name)); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("sym"); if (gc.Found) { txt = doc.CreateTextNode("Geocache Found"); } else { txt = doc.CreateTextNode("Geocache"); } el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("type"); txt = doc.CreateTextNode(string.Format("Geocache|{0}", gc.GeocacheType.GPXTag)); el.AppendChild(txt); wpt.AppendChild(el); XmlElement cache = doc.CreateElement("groundspeak_cache"); wpt.AppendChild(cache); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(gc.ID); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("available"); txt = doc.CreateTextNode(gc.Available.ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("archived"); txt = doc.CreateTextNode(gc.Archived.ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); if (_gpxVersion >= V102) { attr = doc.CreateAttribute("memberonly"); txt = doc.CreateTextNode(gc.MemberOnly.ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("customcoords"); txt = doc.CreateTextNode(gc.CustomCoords.ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("_xmlns_groundspeak"); txt = doc.CreateTextNode("http://www.groundspeak.com/cache/1/0/2"); attr.AppendChild(txt); cache.Attributes.Append(attr); } else if (_gpxVersion == V101) { attr = doc.CreateAttribute("_xmlns_groundspeak"); txt = doc.CreateTextNode("http://www.groundspeak.com/cache/1/0/1"); attr.AppendChild(txt); cache.Attributes.Append(attr); } else { attr = doc.CreateAttribute("_xmlns_groundspeak"); txt = doc.CreateTextNode("http://www.groundspeak.com/cache/1/0"); attr.AppendChild(txt); cache.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_name"); txt = doc.CreateTextNode(transformedGeocacheName(gc.Name)); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_placed_by"); txt = doc.CreateTextNode(gc.PlacedBy); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_owner"); txt = doc.CreateTextNode(gc.Owner); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(gc.OwnerId); attr.AppendChild(txt); el.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_type"); txt = doc.CreateTextNode(gc.GeocacheType.GPXTag); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(gc.GeocacheType.ID.ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_container"); txt = doc.CreateTextNode(gc.Container.Name); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(gc.Container.ID.ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); } if (_gpxVersion >= V101) { if (gc.AttributeIds.Count > 0) { XmlElement attrs = doc.CreateElement("groundspeak_attributes"); cache.AppendChild(attrs); foreach (int attrId in gc.AttributeIds) { int id = (int)Math.Abs(attrId); el = doc.CreateElement("groundspeak_attribute"); txt = doc.CreateTextNode(Utils.DataAccess.GetGeocacheAttribute(_core.GeocacheAttributes, id).Name); el.AppendChild(txt); attrs.AppendChild(el); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(id.ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); attr = doc.CreateAttribute("inc"); if (attrId < 0) { txt = doc.CreateTextNode("0"); } else { txt = doc.CreateTextNode("1"); } attr.AppendChild(txt); el.Attributes.Append(attr); } } } el = doc.CreateElement("groundspeak_difficulty"); txt = doc.CreateTextNode(gc.Difficulty.ToString("0.#").Replace(',', '.')); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_terrain"); txt = doc.CreateTextNode(gc.Terrain.ToString("0.#").Replace(',', '.')); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_country"); txt = doc.CreateTextNode(gc.Country ?? ""); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_state"); txt = doc.CreateTextNode(gc.State ?? ""); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_short_description"); if (_addFieldnotesToDescription && gc.ContainsNote) { StringBuilder sb = new StringBuilder(); if (gc.ShortDescriptionInHtml) { if (!string.IsNullOrEmpty(gc.PersonaleNote)) { sb.AppendFormat("<p>{0}</p><br />", System.Web.HttpUtility.HtmlEncode(gc.PersonaleNote)); } if (!string.IsNullOrEmpty(gc.Notes)) { if (gc.Notes.StartsWith("<p>", StringComparison.OrdinalIgnoreCase)) { sb.AppendFormat("{0}<br />", gc.Notes); } else { sb.AppendFormat("<p>{0}</p><br />", gc.Notes); } } } else { if (!string.IsNullOrEmpty(gc.PersonaleNote)) { sb.AppendFormat("{0}\r\n\r\n", gc.PersonaleNote); } if (!string.IsNullOrEmpty(gc.Notes)) { sb.AppendFormat("{0}\r\n\r\n", gc.Notes); } } sb.Append(gc.ShortDescription ?? ""); txt = doc.CreateTextNode(sb.ToString()); } else { txt = doc.CreateTextNode(gc.ShortDescription ?? ""); } el.AppendChild(txt); cache.AppendChild(el); attr = doc.CreateAttribute("html"); txt = doc.CreateTextNode(gc.ShortDescriptionInHtml.ToString().ToLower()); attr.AppendChild(txt); el.Attributes.Append(attr); el = doc.CreateElement("groundspeak_long_description"); if (_addAdditionWaypointsToDescription) { List<Framework.Data.Waypoint> wpts = Utils.DataAccess.GetWaypointsFromGeocache(_core.Waypoints, gc.Code); if (wpts != null && wpts.Count > 0) { StringBuilder awp = new StringBuilder(); if (gc.LongDescriptionInHtml) { awp.AppendFormat("{0}<br /><br /><h2>Additiona Hidden Waypoints</h2>", gc.LongDescription ?? ""); awp.Append("<p>"); foreach (Framework.Data.Waypoint wp in wpts) { awp.AppendFormat("{0} - {1} ({2})<br />", HttpUtility.HtmlEncode(wp.ID ?? ""), HttpUtility.HtmlEncode(wp.Description ?? ""), HttpUtility.HtmlEncode(Utils.LanguageSupport.Instance.GetTranslation(wp.WPType.Name))); if (wp.Lat != null && wp.Lon != null) { awp.AppendFormat("{0}<br />", HttpUtility.HtmlEncode(Utils.Conversion.GetCoordinatesPresentation((double)wp.Lat, (double)wp.Lon))); } else { awp.Append("???<br />"); } awp.AppendFormat("{0}<br /><br />", HttpUtility.HtmlEncode(wp.Comment ?? "")); } awp.Append("</p>"); } else { awp.AppendFormat("{0}\r\n\r\nAdditiona Hidden Waypoints", gc.LongDescription ?? ""); foreach (Framework.Data.Waypoint wp in wpts) { awp.AppendFormat("{0} - {1} ({2})\r\n", wp.ID ?? "", wp.Description ?? "", Utils.LanguageSupport.Instance.GetTranslation(wp.WPType.Name)); if (wp.Lat != null && wp.Lon != null) { awp.AppendFormat("{0}\r\n", Utils.Conversion.GetCoordinatesPresentation((double)wp.Lat, (double)wp.Lon)); } else { awp.Append("???\r\n"); } awp.AppendFormat("{0}\r\n\r\n", wp.Comment ?? ""); } } txt = doc.CreateTextNode(awp.ToString()); } else { txt = doc.CreateTextNode(gc.LongDescription ?? ""); } } else { txt = doc.CreateTextNode(gc.LongDescription ?? ""); } el.AppendChild(txt); cache.AppendChild(el); attr = doc.CreateAttribute("html"); txt = doc.CreateTextNode(gc.LongDescriptionInHtml.ToString().ToLower()); attr.AppendChild(txt); el.Attributes.Append(attr); el = doc.CreateElement("groundspeak_encoded_hints"); txt = doc.CreateTextNode(gc.EncodedHints ?? ""); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { el = doc.CreateElement("groundspeak_personal_note"); txt = doc.CreateTextNode(gc.PersonaleNote ?? ""); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_favorite_points"); txt = doc.CreateTextNode(gc.Favorites.ToString()); el.AppendChild(txt); cache.AppendChild(el); } List<Framework.Data.Log> logs = Utils.DataAccess.GetLogs(_core.Logs, gc.Code).Take(_maxLogCount).ToList(); if (logs.Count > 0) { XmlElement logsel = doc.CreateElement("groundspeak_logs"); cache.AppendChild(logsel); foreach (var l in logs) { XmlElement lel = doc.CreateElement("groundspeak_log"); logsel.AppendChild(lel); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(l.ID); attr.AppendChild(txt); lel.Attributes.Append(attr); el = doc.CreateElement("groundspeak_date"); txt = doc.CreateTextNode(string.Format("{0}Z",l.Date.ToString("s"))); el.AppendChild(txt); lel.AppendChild(el); el = doc.CreateElement("groundspeak_type"); txt = doc.CreateTextNode(l.LogType.Name); el.AppendChild(txt); lel.AppendChild(el); if (_gpxVersion >= V102) { attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(l.LogType.ID.ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_finder"); txt = doc.CreateTextNode(l.Finder); el.AppendChild(txt); lel.AppendChild(el); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(l.FinderId); attr.AppendChild(txt); el.Attributes.Append(attr); el = doc.CreateElement("groundspeak_text"); txt = doc.CreateTextNode(l.Text); el.AppendChild(txt); lel.AppendChild(el); attr = doc.CreateAttribute("encoded"); txt = doc.CreateTextNode(l.Encoded.ToString().ToLower()); attr.AppendChild(txt); el.Attributes.Append(attr); } } //todo, geocache images / trackables _index++; } using (System.IO.TemporaryFile tmp = new System.IO.TemporaryFile(true)) { doc.Save(tmp.Path); result = System.IO.File.ReadAllText(tmp.Path); result = result.Replace("<groundspeak_", "<groundspeak:"); result = result.Replace("</groundspeak_", "</groundspeak:"); result = result.Replace("_xmlns_groundspeak", "xmlns:groundspeak"); } return validateXml(result); }
private void readGeocacheData(RecordInfo ri, MemoryStream ms, BinaryReader br) { _geocachesInDB.Add(ri.ID, ri); Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Code = ri.ID; //read data gc.Archived = br.ReadBoolean(); gc.Available = br.ReadBoolean(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32()); gc.DataFromDate = DateTimeFromLong(br.ReadInt64()); gc.PublishedTime = DateTimeFromLong(br.ReadInt64()); gc.Difficulty = br.ReadDouble(); gc.Terrain = br.ReadDouble(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32()); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.Locked = br.ReadBoolean(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } else { gc.CustomLat = null; gc.CustomLon = null; br.ReadDouble(); br.ReadDouble(); } gc.MemberOnly = br.ReadBoolean(); List<int> attrList = new List<int>(); int cnt = br.ReadByte(); for (int i = 0; i < cnt; i++) { attrList.Add(br.ReadInt32()); } gc.AttributeIds = attrList; ms.Position = 300; gc.City = br.ReadString(); ms.Position = 400; gc.Country = br.ReadString(); ms.Position = 500; gc.EncodedHints = br.ReadString(); ms.Position = 1000; gc.Municipality = br.ReadString(); ms.Position = 1100; gc.Name = br.ReadString(); ms.Position = 1200; //spare now gc.Notes = br.ReadString(); ms.Position = 2000; gc.Owner = br.ReadString(); ms.Position = 2100; gc.OwnerId = br.ReadString(); ms.Position = 2150; gc.PersonaleNote = br.ReadString(); ms.Position = 2400; gc.PlacedBy = br.ReadString(); ms.Position = 2500; gc.State = br.ReadString(); ms.Position = 2600; gc.Url = br.ReadString(); //ms.Position = 3000; //gc.LongDescriptionInHtml = br.ReadBoolean(); //gc.ShortDescriptionInHtml = br.ReadBoolean(); //gc.ShortDescription = br.ReadString(); //gc.LongDescription = br.ReadString(); Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); gc.Saved = true; gc.IsDataChanged = false; Core.Geocaches.Add(gc); }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { linkLabel1.Links.Clear(); if (listView1.SelectedItems.Count == 0) { linkLabel1.Text = ""; pictureBox1.Image = null; textBox1.Text = ""; textBox1.Enabled = false; } else { _gc = listView1.SelectedItems[0].Tag as Framework.Data.Geocache; pictureBox1.ImageLocation = Utils.ImageSupport.Instance.GetImagePath(_core, Framework.Data.ImageSize.Default, _gc.GeocacheType); linkLabel1.Text = string.Format("{0}, {1}", _gc.Code, _gc.Name); linkLabel1.Links.Add(0, _gc.Code.Length, _gc.Url); textBox1.Text = Utils.Conversion.GetCoordinatesPresentation(_gc.Lat, _gc.Lon); textBox1.Enabled = true; } }
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; }
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 { } } } } }
public List<Framework.Data.Geocache> ProcessWaymarkComGPXCaches(string gpxDoc) { List<Framework.Data.Geocache> result = new List<Framework.Data.Geocache>(); 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); nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/0"); DateTime 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) { 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 = wp.SelectSingleNode("x:urlname", nsmgr).InnerText; gc.DataFromDate = gpxDataTime; gc.PublishedTime = DateTime.MinValue; gc.Url = SafeInnerText(wp.SelectSingleNode("x:url", nsmgr), ""); gc.Available = true; gc.Archived = false; gc.Country = ""; gc.State = ""; gc.ID = gc.Code; gc.OwnerId = ""; gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, 63542); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, -1); gc.Favorites = 0; gc.MemberOnly = false; gc.CustomCoords = false; gc.PersonaleNote = ""; gc.PlacedBy = ""; gc.Owner = ""; gc.Terrain = 1; gc.Difficulty = 1; gc.ShortDescription = SafeInnerText(wp.SelectSingleNode("x:desc", nsmgr), ""); gc.ShortDescriptionInHtml = false; gc.LongDescription = ""; gc.LongDescriptionInHtml = false; gc.EncodedHints = ""; Utils.Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); result.Add(gc); } } } catch { } 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 { } }
void mapContainerControl1_GeocacheClick(object sender, Framework.EventArguments.GeocacheEventArgs e) { _activeGeocache = e.Geocache; _core.ActiveGeocache = e.Geocache; }
public static Framework.Data.Geocache Geocache(Framework.Interfaces.ICore core, OKAPIService.Geocache gc) { Framework.Data.Geocache result = null; if (gc != null) { Framework.Data.Geocache tmp = Utils.DataAccess.GetGeocache(core.Geocaches, gc.code); result = new Framework.Data.Geocache(); if (tmp != null) { result.UpdateFrom(tmp, null); } result.DataFromDate = DateTime.Now; result.Code = gc.code; result.ID = gc.code; result.Archived = gc.status == "Archived"; result.Available = gc.status == "Available"; List<int> attris = new List<int>(); foreach (string at in gc.attr_acodes) { int code = OKAPIService.MapAttributeACodeToAttributeID(at); if (code > 0) { attris.Add(code); } } result.AttributeIds = attris; // 'none', 'nano', 'micro', 'small', 'regular', 'large', 'xlarge', 'other' // we chose to map the containers if (gc.size2 == "none") { result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 5); } else if (gc.size2 == "micro" || gc.size2 == "nano") { result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 2); } else if (gc.size2 == "small") { result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 8); } else if (gc.size2 == "regular") { result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 3); } else if (gc.size2 == "large" || gc.size2 == "xlarge") { result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 4); } else { result.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, 6); } result.Country = gc.country ?? ""; result.Difficulty = gc.difficulty; result.EncodedHints = gc.hint2; result.Found = gc.is_found; if (gc.type.ToLower().Contains("traditional")) { result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96001); } else if (gc.type.ToLower().Contains("multi")) { result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96002); } else if (gc.type.ToLower().Contains("quiz") || gc.type.ToLower().Contains("puzzle")) { result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96008); } else if (gc.type.ToLower().Contains("virtual")) { result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96003); } else if (gc.type.ToLower().Contains("event")) { result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96004); } else if (gc.type.ToLower().Contains("webcam")) { result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96006); } else if (gc.type.ToLower().Contains("location") || gc.type.Contains("moving")) { result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96007); } else { result.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, 96005); } result.Lat = Utils.Conversion.StringToDouble(gc.location.Substring(0, gc.location.IndexOf('|'))); result.Lon = Utils.Conversion.StringToDouble(gc.location.Substring(gc.location.IndexOf('|') + 1)); result.LongDescription = gc.description; result.LongDescriptionInHtml = true; result.Name = gc.name; result.Owner = gc.owner.username; result.OwnerId = gc.owner.uuid; result.PlacedBy = gc.owner.username; result.PublishedTime = DateTime.Parse(gc.date_hidden); result.ShortDescription = ""; result.ShortDescriptionInHtml = true; result.State = gc.state ?? ""; result.Terrain = gc.terrain; result.Url = gc.url ?? ""; Calculus.SetDistanceAndAngleGeocacheFromLocation(result, core.CenterLocation); } return result; }
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 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 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 static Framework.Data.Geocache Geocache(Framework.Interfaces.ICore core, LiveV6.Geocache gc) { Framework.Data.Geocache result = null; if (gc != null) { Framework.Data.Geocache tmp = DataAccess.GetGeocache(core.Geocaches, gc.Code); result = new Framework.Data.Geocache(); if (tmp != null) { result.UpdateFrom(tmp, null); } result.Code = gc.Code; result.ID = gc.ID.ToString(); result.Archived = gc.Archived ?? false; result.Available = gc.Available ?? true; result.Container = DataAccess.GetGeocacheContainer(core.GeocacheContainers, (int)gc.ContainerType.ContainerTypeId); if (gc.Attributes!=null) { List<int> attr = new List<int>(); foreach (LiveV6.Attribute a in gc.Attributes) { attr.Add(a.IsOn ? a.AttributeTypeID : -1 * a.AttributeTypeID); } result.AttributeIds = attr; } if (gc.Latitude != null) result.Lat = (double)gc.Latitude; if (gc.Longitude != null) result.Lon = (double)gc.Longitude; if (gc.Country != null) result.Country = gc.Country; result.DataFromDate = DateTime.Now; result.Difficulty = gc.Difficulty; result.Terrain = gc.Terrain; result.Title = gc.Name; if (gc.FavoritePoints != null) { result.Favorites = (int)gc.FavoritePoints; } result.GeocacheType = DataAccess.GetGeocacheType(core.GeocacheTypes, (int)gc.CacheType.GeocacheTypeId); if (gc.LongDescription != null) { result.LongDescription = gc.LongDescription; result.LongDescriptionInHtml = gc.LongDescriptionIsHtml; } if (gc.EncodedHints != null) { result.EncodedHints = gc.EncodedHints; } result.MemberOnly = gc.IsPremium ?? false; result.Owner = gc.Owner.UserName; if (gc.Owner.Id != null) { result.OwnerId = gc.Owner.Id.ToString(); } result.PlacedBy = gc.PlacedBy; result.PublishedTime = gc.UTCPlaceDate; if (result.ShortDescription != null) { result.ShortDescription = gc.ShortDescription; result.ShortDescriptionInHtml = gc.ShortDescriptionIsHtml; } if (gc.State == "None") { result.State = ""; } else { result.State = gc.State; } result.PersonaleNote = gc.GeocacheNote; if (gc.HasbeenFoundbyUser!=null) { result.Found = (bool)gc.HasbeenFoundbyUser; } result.Url = gc.Url; result.PersonaleNote = gc.GeocacheNote ?? ""; Calculus.SetDistanceAndAngleGeocacheFromLocation(result, core.CenterLocation); } return result; }
public GeocacheLogForm(Framework.Interfaces.ICore core, Utils.API.GeocachingLiveV6 client, Framework.Data.Geocache gc) { InitializeComponent(); this.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_TITLE); this.label4.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_GEOCACHECODE); this.buttonSelect.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECT); this.label1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTYPE); this.label2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_DATE); this.label3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_LOGTEXT); this.buttonSubmit.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SUBMIT); this.button1.Text = string.Format("{0} >>", Utils.LanguageSupport.Instance.GetTranslation(STR_TRACKABLES)); this.button2.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTALL); this.button5.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_SELECTALL); this.button3.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CLEARTALL); this.button4.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_CLEARTALL); this.button6.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_ADD); this.removeToolStripMenuItem.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_REMOVE); this.checkBox1.Text = Utils.LanguageSupport.Instance.GetTranslation(STR_ADDTOFAVORITES); _context = SynchronizationContext.Current; if (_context == null) { _context = new SynchronizationContext(); } _core = core; _client = client; _gc = gc; AskForNext = true; int[] ids = new int[] { 2, 3, 4, 7, 45, 9, 10 }; comboBoxLogType1.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList()); ids = new int[] { 14 }; comboBoxLogType2.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList()); comboBoxLogType2.SelectedIndex = 0; ids = new int[] { 75 }; comboBoxLogType3.SetLogTypes(core, (from Framework.Data.LogType l in core.LogTypes join a in ids on l.ID equals a select l).ToList()); comboBoxLogType3.SelectedIndex = 0; updateGCInfo(); }
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; }
public void ExecuteQuery(FreeQuery fq) { if (Core.Geocaches.Count > 0) { _refgc = Core.Geocaches[0] as Framework.Data.Geocache; _processedfq.Clear(); Core.Geocaches.BeginUpdate(); try { foreach (Framework.Data.Geocache gc in Core.Geocaches) { gc.Selected = GetQueryResult(fq, gc); } } catch (Exception e) { MessageBox.Show(e.Message, Utils.LanguageSupport.Instance.GetTranslation(STR_ERROR)); } Core.Geocaches.EndUpdate(); } }