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}\" />", _minLat.ToString(CultureInfo.InvariantCulture), _minLon.ToString(CultureInfo.InvariantCulture), _maxLat.ToString(CultureInfo.InvariantCulture), _maxLon.ToString(CultureInfo.InvariantCulture) )); return(sb.ToString()); }
public void SetGeocacheList(List <string> gcList, double minLat, double maxLat, double minLon, double maxLon) { _gcList = gcList; _index = 0; _activeGcg = null; _minLat = minLat; _maxLat = maxLat; _minLon = minLon; _maxLon = maxLon; }
public string Next() { string result = ""; XmlDocument doc = new XmlDocument(); if (_index < _gcList.Count) { var gc = _db.Fetch<DataTypes.GSAKCaches, DataTypes.GSAKCacheMemo, DataTypes.GSAKCorrected, GeocachePoco>((a, b, c) => { return new GeocachePoco() { Caches = a, CacheMemo = b, Corrected = c }; }, "select Caches.*, CacheMemo.*, Corrected.* from Caches left join CacheMemo on Caches.Code = CacheMemo.Code left join Corrected on Caches.Code = Corrected.kCode where Caches.Code=@0", _gcList[_index]).FirstOrDefault(); _activeGcg = gc; string GPXTag = (from a in ApplicationData.Instance.GeocacheTypes where a.GSAK == gc.Caches.CacheType select a.GPXTag).FirstOrDefault() ?? ""; XmlElement wpt = doc.CreateElement("wpt"); XmlAttribute attr = doc.CreateAttribute("lat"); XmlText txt = doc.CreateTextNode(gc.Corrected == null ? gc.Caches.Latitude : gc.Corrected.kAfterLat); attr.AppendChild(txt); wpt.Attributes.Append(attr); attr = doc.CreateAttribute("lon"); txt = doc.CreateTextNode(gc.Corrected == null ? gc.Caches.Longitude : gc.Corrected.kAfterLon); attr.AppendChild(txt); wpt.Attributes.Append(attr); doc.AppendChild(wpt); XmlElement el = doc.CreateElement("time"); txt = doc.CreateTextNode(string.Format("{0}Z",DateTime.ParseExact(gc.Caches.PlacedDate, "yyyy-MM-dd", CultureInfo.InvariantCulture).AddHours(12).ToString("s"))); el.AppendChild(txt); wpt.AppendChild(el); string nameValue = gc.Caches.Code; el = doc.CreateElement("name"); txt = doc.CreateTextNode(gc.Caches.Code); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("desc"); txt = doc.CreateTextNode(string.Format("{0} by {1}, {2} ({3}/{4})", gc.Caches.Name, gc.Caches.OwnerName, GPXTag, gc.Caches.Difficulty, gc.Caches.Terrain)); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("url"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.Url); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("urlname"); txt = doc.CreateTextNode(gc.Caches.Name); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("sym"); if (gc.Caches.Found!=0) { 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}", GPXTag)); el.AppendChild(txt); wpt.AppendChild(el); XmlElement cache = doc.CreateElement("groundspeak_cache"); wpt.AppendChild(cache); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(gc.Caches.CacheId); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("available"); txt = doc.CreateTextNode((gc.Caches.TempDisabled==0).ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("archived"); txt = doc.CreateTextNode((gc.Caches.Archived != 0).ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); if (_gpxVersion >= V102) { attr = doc.CreateAttribute("memberonly"); txt = doc.CreateTextNode((gc.Caches.IsPremium !=0).ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("customcoords"); txt = doc.CreateTextNode((gc.Corrected!=null).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(gc.Caches.Name); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_placed_by"); txt = doc.CreateTextNode(gc.Caches.PlacedBy); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_owner"); txt = doc.CreateTextNode(gc.Caches.OwnerName); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(gc.Caches.OwnerId); attr.AppendChild(txt); el.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_type"); txt = doc.CreateTextNode(GPXTag); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { string GeocacheTypeID = (from a in ApplicationData.Instance.GeocacheTypes where a.GSAK == gc.Caches.CacheType select a.ID.ToString()).FirstOrDefault() ?? ""; attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(GeocacheTypeID); attr.AppendChild(txt); el.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_container"); txt = doc.CreateTextNode(gc.Caches.Container); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { string containerID = (from a in ApplicationData.Instance.GeocacheContainers where a.Name == gc.Caches.Container select a.ID.ToString()).FirstOrDefault() ?? ""; attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(containerID); attr.AppendChild(txt); el.Attributes.Append(attr); } if (_gpxVersion >= V101) { var attributes = _db.Fetch<DataTypes.GSAKAttributes>("select * from Attributes where aCode=@0", gc.Caches.Code); if (attributes.Count > 0) { XmlElement attrs = doc.CreateElement("groundspeak_attributes"); cache.AppendChild(attrs); foreach (var att in attributes) { var attrName = (from a in ApplicationData.Instance.GeocacheAttributes where a.ID == att.aId select a.Name).FirstOrDefault() ?? ""; el = doc.CreateElement("groundspeak_attribute"); txt = doc.CreateTextNode(attrName); el.AppendChild(txt); attrs.AppendChild(el); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(att.aId.ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); attr = doc.CreateAttribute("inc"); txt = doc.CreateTextNode(att.aInc.ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); } } } el = doc.CreateElement("groundspeak_difficulty"); txt = doc.CreateTextNode(gc.Caches.Difficulty.ToString(CultureInfo.InvariantCulture)); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_terrain"); txt = doc.CreateTextNode(gc.Caches.Terrain.ToString(CultureInfo.InvariantCulture)); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_country"); txt = doc.CreateTextNode(gc.Caches.Country ?? ""); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_state"); txt = doc.CreateTextNode(gc.Caches.State ?? ""); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_short_description"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.ShortDescription); el.AppendChild(txt); cache.AppendChild(el); attr = doc.CreateAttribute("html"); txt = doc.CreateTextNode((gc.Caches.ShortHtm != 0).ToString().ToLower()); attr.AppendChild(txt); el.Attributes.Append(attr); el = doc.CreateElement("groundspeak_long_description"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.LongDescription); el.AppendChild(txt); cache.AppendChild(el); attr = doc.CreateAttribute("html"); txt = doc.CreateTextNode((gc.Caches.LongHtm != 0).ToString().ToLower()); attr.AppendChild(txt); el.Attributes.Append(attr); el = doc.CreateElement("groundspeak_encoded_hints"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.Hints); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { el = doc.CreateElement("groundspeak_personal_note"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.UserNote ?? ""); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_favorite_points"); txt = doc.CreateTextNode(gc.Caches.FavPoints.ToString()); el.AppendChild(txt); cache.AppendChild(el); } var logs = _db.Fetch<DataTypes.GSAKLogs, DataTypes.GSAKLogMemo, GeocacheLogPoco>((a, b) => { return new GeocacheLogPoco() { Logs = a, LogMemo = b }; }, "select Logs.*, LogMemo.* from Logs left join LogMemo on Logs.lLogId=LogMemo.lLogId where Logs.lParent=@0", gc.Caches.Code); 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.Logs.lLogId.ToString()); attr.AppendChild(txt); lel.Attributes.Append(attr); el = doc.CreateElement("groundspeak_date"); txt = doc.CreateTextNode(string.Format("{0}Z",(l.Logs.lDate ?? DateTime.Now).Date.ToString("s"))); el.AppendChild(txt); lel.AppendChild(el); el = doc.CreateElement("groundspeak_type"); txt = doc.CreateTextNode(l.Logs.lType); el.AppendChild(txt); lel.AppendChild(el); if (_gpxVersion >= V102) { var logtypeid = (from a in ApplicationData.Instance.LogTypes where a.Name == l.Logs.lType select a.ID.ToString()).FirstOrDefault() ?? ""; attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(logtypeid); attr.AppendChild(txt); el.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_finder"); txt = doc.CreateTextNode(l.Logs.lBy ?? ""); el.AppendChild(txt); lel.AppendChild(el); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode((l.Logs.lownerid ?? 1).ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); el = doc.CreateElement("groundspeak_text"); txt = doc.CreateTextNode(l.LogMemo == null ? "" : l.LogMemo.lText ?? ""); el.AppendChild(txt); lel.AppendChild(el); attr = doc.CreateAttribute("encoded"); txt = doc.CreateTextNode((l.Logs.lEncoded ?? 0).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); }
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}\" />", _minLat.ToString(CultureInfo.InvariantCulture), _minLon.ToString(CultureInfo.InvariantCulture), _maxLat.ToString(CultureInfo.InvariantCulture), _maxLon.ToString(CultureInfo.InvariantCulture) )); return sb.ToString(); }
public void SetGeocacheList(List<string> gcList, double minLat, double maxLat, double minLon, double maxLon) { _gcList = gcList; _index = 0; _activeGcg = null; _minLat = minLat; _maxLat = maxLat; _minLon = minLon; _maxLon = maxLon; }
public string Next() { string result = ""; XmlDocument doc = new XmlDocument(); if (_index < _gcList.Count) { var gc = _db.Fetch <DataTypes.GSAKCaches, DataTypes.GSAKCacheMemo, DataTypes.GSAKCorrected, GeocachePoco>((a, b, c) => { return(new GeocachePoco() { Caches = a, CacheMemo = b, Corrected = c }); }, "select Caches.*, CacheMemo.*, Corrected.* from Caches left join CacheMemo on Caches.Code = CacheMemo.Code left join Corrected on Caches.Code = Corrected.kCode where Caches.Code=@0", _gcList[_index]).FirstOrDefault(); _activeGcg = gc; string GPXTag = (from a in ApplicationData.Instance.GeocacheTypes where a.GSAK == gc.Caches.CacheType select a.GPXTag).FirstOrDefault() ?? ""; XmlElement wpt = doc.CreateElement("wpt"); XmlAttribute attr = doc.CreateAttribute("lat"); XmlText txt = doc.CreateTextNode(gc.Corrected == null ? gc.Caches.Latitude : gc.Corrected.kAfterLat); attr.AppendChild(txt); wpt.Attributes.Append(attr); attr = doc.CreateAttribute("lon"); txt = doc.CreateTextNode(gc.Corrected == null ? gc.Caches.Longitude : gc.Corrected.kAfterLon); attr.AppendChild(txt); wpt.Attributes.Append(attr); doc.AppendChild(wpt); XmlElement el = doc.CreateElement("time"); txt = doc.CreateTextNode(string.Format("{0}Z", DateTime.ParseExact(gc.Caches.PlacedDate, "yyyy-MM-dd", CultureInfo.InvariantCulture).AddHours(12).ToString("s"))); el.AppendChild(txt); wpt.AppendChild(el); string nameValue = gc.Caches.Code; el = doc.CreateElement("name"); txt = doc.CreateTextNode(gc.Caches.Code); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("desc"); txt = doc.CreateTextNode(string.Format("{0} by {1}, {2} ({3}/{4})", gc.Caches.Name, gc.Caches.OwnerName, GPXTag, gc.Caches.Difficulty, gc.Caches.Terrain)); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("url"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.Url); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("urlname"); txt = doc.CreateTextNode(gc.Caches.Name); el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("sym"); if (gc.Caches.Found != 0) { 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}", GPXTag)); el.AppendChild(txt); wpt.AppendChild(el); XmlElement cache = doc.CreateElement("groundspeak_cache"); wpt.AppendChild(cache); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(gc.Caches.CacheId); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("available"); txt = doc.CreateTextNode((gc.Caches.TempDisabled == 0).ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("archived"); txt = doc.CreateTextNode((gc.Caches.Archived != 0).ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); if (_gpxVersion >= V102) { attr = doc.CreateAttribute("memberonly"); txt = doc.CreateTextNode((gc.Caches.IsPremium != 0).ToString().ToLower()); attr.AppendChild(txt); cache.Attributes.Append(attr); attr = doc.CreateAttribute("customcoords"); txt = doc.CreateTextNode((gc.Corrected != null).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(gc.Caches.Name); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_placed_by"); txt = doc.CreateTextNode(gc.Caches.PlacedBy); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_owner"); txt = doc.CreateTextNode(gc.Caches.OwnerName); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(gc.Caches.OwnerId); attr.AppendChild(txt); el.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_type"); txt = doc.CreateTextNode(GPXTag); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { string GeocacheTypeID = (from a in ApplicationData.Instance.GeocacheTypes where a.GSAK == gc.Caches.CacheType select a.ID.ToString()).FirstOrDefault() ?? ""; attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(GeocacheTypeID); attr.AppendChild(txt); el.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_container"); txt = doc.CreateTextNode(gc.Caches.Container); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { string containerID = (from a in ApplicationData.Instance.GeocacheContainers where a.Name == gc.Caches.Container select a.ID.ToString()).FirstOrDefault() ?? ""; attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(containerID); attr.AppendChild(txt); el.Attributes.Append(attr); } if (_gpxVersion >= V101) { var attributes = _db.Fetch <DataTypes.GSAKAttributes>("select * from Attributes where aCode=@0", gc.Caches.Code); if (attributes.Count > 0) { XmlElement attrs = doc.CreateElement("groundspeak_attributes"); cache.AppendChild(attrs); foreach (var att in attributes) { var attrName = (from a in ApplicationData.Instance.GeocacheAttributes where a.ID == att.aId select a.Name).FirstOrDefault() ?? ""; el = doc.CreateElement("groundspeak_attribute"); txt = doc.CreateTextNode(attrName); el.AppendChild(txt); attrs.AppendChild(el); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(att.aId.ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); attr = doc.CreateAttribute("inc"); txt = doc.CreateTextNode(att.aInc.ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); } } } el = doc.CreateElement("groundspeak_difficulty"); txt = doc.CreateTextNode(gc.Caches.Difficulty.ToString(CultureInfo.InvariantCulture)); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_terrain"); txt = doc.CreateTextNode(gc.Caches.Terrain.ToString(CultureInfo.InvariantCulture)); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_country"); txt = doc.CreateTextNode(gc.Caches.Country ?? ""); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_state"); txt = doc.CreateTextNode(gc.Caches.State ?? ""); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_short_description"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.ShortDescription); el.AppendChild(txt); cache.AppendChild(el); attr = doc.CreateAttribute("html"); txt = doc.CreateTextNode((gc.Caches.ShortHtm != 0).ToString().ToLower()); attr.AppendChild(txt); el.Attributes.Append(attr); el = doc.CreateElement("groundspeak_long_description"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.LongDescription); el.AppendChild(txt); cache.AppendChild(el); attr = doc.CreateAttribute("html"); txt = doc.CreateTextNode((gc.Caches.LongHtm != 0).ToString().ToLower()); attr.AppendChild(txt); el.Attributes.Append(attr); el = doc.CreateElement("groundspeak_encoded_hints"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.Hints); el.AppendChild(txt); cache.AppendChild(el); if (_gpxVersion >= V102) { el = doc.CreateElement("groundspeak_personal_note"); txt = doc.CreateTextNode(gc.CacheMemo == null ? "" : gc.CacheMemo.UserNote ?? ""); el.AppendChild(txt); cache.AppendChild(el); el = doc.CreateElement("groundspeak_favorite_points"); txt = doc.CreateTextNode(gc.Caches.FavPoints.ToString()); el.AppendChild(txt); cache.AppendChild(el); } var logs = _db.Fetch <DataTypes.GSAKLogs, DataTypes.GSAKLogMemo, GeocacheLogPoco>((a, b) => { return(new GeocacheLogPoco() { Logs = a, LogMemo = b }); }, "select Logs.*, LogMemo.* from Logs left join LogMemo on Logs.lLogId=LogMemo.lLogId where Logs.lParent=@0", gc.Caches.Code); 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.Logs.lLogId.ToString()); attr.AppendChild(txt); lel.Attributes.Append(attr); el = doc.CreateElement("groundspeak_date"); txt = doc.CreateTextNode(string.Format("{0}Z", (l.Logs.lDate ?? DateTime.Now).Date.ToString("s"))); el.AppendChild(txt); lel.AppendChild(el); el = doc.CreateElement("groundspeak_type"); txt = doc.CreateTextNode(l.Logs.lType); el.AppendChild(txt); lel.AppendChild(el); if (_gpxVersion >= V102) { var logtypeid = (from a in ApplicationData.Instance.LogTypes where a.Name == l.Logs.lType select a.ID.ToString()).FirstOrDefault() ?? ""; attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode(logtypeid); attr.AppendChild(txt); el.Attributes.Append(attr); } el = doc.CreateElement("groundspeak_finder"); txt = doc.CreateTextNode(l.Logs.lBy ?? ""); el.AppendChild(txt); lel.AppendChild(el); attr = doc.CreateAttribute("id"); txt = doc.CreateTextNode((l.Logs.lownerid ?? 1).ToString()); attr.AppendChild(txt); el.Attributes.Append(attr); el = doc.CreateElement("groundspeak_text"); txt = doc.CreateTextNode(l.LogMemo == null ? "" : l.LogMemo.lText ?? ""); el.AppendChild(txt); lel.AppendChild(el); attr = doc.CreateAttribute("encoded"); txt = doc.CreateTextNode((l.Logs.lEncoded ?? 0).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)); }