void Instance_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "ActiveGeocache") { CurrentGeocache = Core.ApplicationData.Instance.ActiveGeocache; } }
public static void DeleteGeocache(Core.Data.Geocache gc) { List <Core.Data.Waypoint> wpl = GetWaypointsFromGeocache(gc.Database, gc.Code); foreach (var wp in wpl) { wp.DeleteRecord(); gc.Database.WaypointCollection.Remove(wp); } List <Core.Data.UserWaypoint> uwpl = GetUserWaypointsFromGeocache(gc.Database, gc.Code); foreach (var wp in uwpl) { wp.DeleteRecord(); gc.Database.UserWaypointCollection.Remove(wp); } List <Core.Data.GeocacheImage> gcil = GetGeocacheImages(gc.Database, gc.Code); foreach (var wp in gcil) { wp.DeleteRecord(); gc.Database.GeocacheImageCollection.Remove(wp); } List <Core.Data.Log> lgs = GetLogs(gc.Database, gc.Code); foreach (var wp in lgs) { DeleteLog(gc.Database, wp); } gc.DeleteRecord(); gc.Database.GeocacheCollection.Remove(gc); }
void Instance_UserInfoUpdate(object sender, GAPPSF.Chat.UserInRoomInfo usr) { if (usr.FollowThisUser) { if (!string.IsNullOrEmpty(usr.ActiveGeocache)) { if (Core.ApplicationData.Instance.ActiveDatabase != null) { Core.Data.Geocache gc = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection.GetGeocache(usr.ActiveGeocache); if (gc != null) { Core.ApplicationData.Instance.ActiveGeocache = gc; FollowActiveGeocacheText = gc.Code; } else if (usr.ActiveGeocache.StartsWith("GC") && Core.Settings.Default.LiveAPIMemberTypeId > 0) { //offer to download FollowActiveGeocacheText = string.Format("{0} ({1})", usr.ActiveGeocache, Localization.TranslationManager.Instance.Translate("Missing") as string); } else { FollowActiveGeocacheText = gc.Code; } } } else { FollowActiveGeocacheText = ""; } } }
public void SetGeocacheList(List <Core.Data.Geocache> gcList) { _gcList = gcList; _index = 0; _gpxVersion = Version.Parse(Core.Settings.Default.GPXVersion); _activeGcg = null; }
public async Task RemoveFavoriteGeocacheAsync(Core.Data.Geocache gc) { await Task.Run(() => { try { using (var api = new LiveAPI.GeocachingLiveV6()) { var resp = api.Client.RemoveFavoritePointFromCache(api.Token, gc.Code); if (resp.Status.StatusCode == 0) { Manager.Instance.RemoveFavoritedGeocache(gc.Code); } else { Core.ApplicationData.Instance.Logger.AddLog(this, new Exception(resp.Status.StatusMessage)); } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); }
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()); }
public string GetImagePath(Core.Data.Geocache gc, string orgUrl) { string result = null; if (gc == null) { result = GetImagePath(orgUrl); } else { try { object o = _dbcon.ExecuteScalar(string.Format("select local_file from images where org_url = '{0}' and gccode = '{1}' limit 1", orgUrl.Replace("'", "''"), gc.Code.Replace("'", "''"))); if (o != null && o.GetType() != typeof(DBNull)) { result = System.IO.Path.Combine(new string[] { _imageFolder, IMG_SUBFOLDER, o as string }); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } } return(result); }
public void SetGeocacheList(List<Core.Data.Geocache> gcList) { _gcList = gcList; _index = 0; _gpxVersion = Version.Parse(Core.Settings.Default.GPXVersion); _activeGcg = null; }
private bool attrFilterPass(List <int> attrFilter, Core.Data.Geocache gc) { bool result = false; List <int> gcAttr = gc.AttributeIds; switch (Core.Settings.Default.GeocacheFilterAttributeFilter) { case AttributeFilter.ContainsAll: result = (from a in gcAttr join b in attrFilter on a equals b select a).Count() == attrFilter.Count; break; case AttributeFilter.ContainsAtLeastOne: result = (from a in gcAttr join b in attrFilter on a equals b select a).Count() > 0; break; case AttributeFilter.ContainsNone: result = (from a in gcAttr join b in attrFilter on a equals b select a).Count() == 0; break; default: result = false; 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(); }
public override object GetValue(Core.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()); }
public override object GetValue(Core.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()); }
public override ActionImplementation.Operator Process(Core.Data.Geocache gc) { if (!_hasBeenExecuted) { _hasBeenExecuted = Execute(); } return(Operator.Equal); }
public override object GetValue(Core.Data.Geocache gc) { StringBuilder result = new StringBuilder(); List <Core.Data.AreaInfo> al = Shapefiles.ShapeFilesManager.Instance.GetAreasOfLocation(new Core.Data.Location(gc.Lat, gc.Lon), Shapefiles.ShapeFilesManager.Instance.GetAreasByLevel(Core.Data.AreaType.Other)); foreach (Core.Data.AreaInfo a in al) { result.AppendLine(a.Name); } return(result.ToString()); }
public override object GetValue(Core.Data.Geocache gc) { double x, y; if (Utils.Calculus.RDFromLatLong(gc.Lat, gc.Lon, out x, out y)) { return(y.ToString()); } else { return(""); } }
private void UpdateView() { saveNotes(); _currentGeocache = Core.ApplicationData.Instance.ActiveGeocache; if (_currentGeocache != null) { NotesText = _currentGeocache.Notes; } else { NotesText = null; } }
public Bucket(Core.Data.Geocache gc) { Geocache = gc; Count = 1; if (gc.ContainsCustomLatLon) { Latitude = (double)gc.CustomLat; Longitude = (double)gc.CustomLon; } else { Latitude = gc.Lat; Longitude = gc.Lon; } }
public string GetImageUri(Core.Data.Geocache gc, string orgUri) { string result; string filename = GetImagePath(gc, orgUri); if (!string.IsNullOrEmpty(filename)) { result = GetEmbeddedImage(filename); } else { result = orgUri; } return(result); }
public static List <Core.Data.LogImage> GetLogImages(Core.Data.Geocache gc) { Database db = gc.Database; List <Core.Data.LogImage> result = new List <LogImage>(); List <Core.Data.Log> lgs = GetLogs(db, gc.Code); if (lgs != null) { foreach (var l in lgs) { result.AddRange(db.LogImageCollection.GetLogImages(l.ID)); } } return(result); }
public void geocacheClick(string code) { Dispatcher.BeginInvoke((Action)(() => { if (!string.IsNullOrEmpty(code) && Core.ApplicationData.Instance.ActiveDatabase != null) { string[] parts = code.Split(new char[] { ',', ' ' }); Core.Data.Geocache gc = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection.GetGeocache(parts[0]); if (gc != null) { Core.ApplicationData.Instance.ActiveGeocache = gc; } } })); }
async private Task CenterLocationGeocache() { if (cacheList.SelectedItems.Count == 1) { Core.Data.Geocache gc = (cacheList.SelectedItems[0] as Core.Data.Geocache); if (gc != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(gc.Database)) { await Task.Run(() => { Utils.DataAccess.SetCenterLocation(gc.Lat, gc.Lon); }); } } } }
public static List <Core.Data.Geocache> ImportGeocaches(Core.Storage.Database db, LiveV6.Geocache[] gcList) { List <Core.Data.Geocache> result = new List <Core.Data.Geocache>(); if (gcList != null) { foreach (var gc in gcList) { Core.Data.Geocache g = ImportGeocache(db, gc); if (g != null) { result.Add(g); } } } return(result); }
public Control() { using (var strm = Assembly.GetExecutingAssembly().GetManifestResourceStream("GAPPSF.UIControls.FormulaSolver.Grammar.SingleLineFormula.egt")) using (System.IO.BinaryReader br = new System.IO.BinaryReader(strm)) { _interpreter = new FormulaInterpreter.FormulaInterpreter(br); } InitializeComponent(); DataContext = this; Core.ApplicationData.Instance.PropertyChanged += Instance_PropertyChanged; //prevent saving _currentGeocache = Core.ApplicationData.Instance.ActiveGeocache; UpdateView(); }
public Dictionary <string, string> GetImages(Core.Data.Geocache gc) { Dictionary <string, string> result = new Dictionary <string, string>(); try { DbDataReader dr = _dbcon.ExecuteReader(string.Format("select org_url, local_file from images where gccode = '{0}'", gc.Code.Replace("'", "''"))); while (dr.Read()) { result.Add(dr["org_url"] as string, System.IO.Path.Combine(new string[] { _imageFolder, IMG_SUBFOLDER, dr["local_file"] as string })); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } return(result); }
public static Core.Data.UserWaypoint ImportUserWaypoint(Core.Storage.Database db, LiveV6.UserWaypoint wp) { Core.Data.UserWaypoint result = null; if (wp != null) { result = db.UserWaypointCollection.GetUserWaypoint(wp.ID.ToString()); Core.Data.IUserWaypointData wpd; if (result == null) { wpd = new Core.Data.UserWaypointData(); wpd.ID = wp.ID.ToString(); } else { wpd = result; } wpd.Description = wp.Description; wpd.GeocacheCode = wp.CacheCode; wpd.Lat = wp.Latitude; wpd.Lon = wp.Longitude; wpd.Date = wp.UTCDate.ToLocalTime(); if (wpd is Core.Data.UserWaypointData) { if (Utils.DataAccess.AddUserWaypoint(db, wpd as Core.Data.UserWaypointData)) { result = db.UserWaypointCollection.GetUserWaypoint(wp.ID.ToString()); if (wp.IsCorrectedCoordinate) { Core.Data.Geocache thisGC = db.GeocacheCollection.GetGeocache(wp.CacheCode); if (thisGC != null) { thisGC.CustomLat = wp.Latitude; thisGC.CustomLon = wp.Longitude; } } } } } return(result); }
void GeocacheCollection_GeocacheDataChanged(object sender, EventArgs e) { Core.Data.Geocache gc = sender as Core.Data.Geocache; if (gc != null) { if (gc == Core.ApplicationData.Instance.ActiveGeocache) { UpdateView(true); } else if (TargetGeocaches == GeocachesOnMap.All || TargetGeocaches == GeocachesOnMap.Selected) { UpdateView(false); } } else { UpdateView(true); } }
private bool GeocacheViewFilter(object o) { Core.Data.Geocache gc = o as Core.Data.Geocache; bool result = !Core.Settings.Default.CacheListShowSelectedOnly || gc.Selected; result &= !Core.Settings.Default.CacheListShowFlaggedOnly || gc.Flagged; string ft = Core.Settings.Default.CacheListFilterText; if (!string.IsNullOrEmpty(ft)) { if (result) { string s = gc.Code; result = s.IndexOf(ft, StringComparison.CurrentCultureIgnoreCase) >= 0; s = gc.Name; result |= s != null && s.IndexOf(ft, StringComparison.CurrentCultureIgnoreCase) >= 0; } } return(result); }
public void Run(Core.Data.Geocache gc) { if (_geocachesAtInpuntConnector[gc.Code] == null) { _geocachesAtInpuntConnector.Add(gc.Code, gc); Operator op = Process(gc); foreach (Operator e in (Operator[])Enum.GetValues(typeof(Operator))) { if ((op & e) != 0) { var cons = from c in _outputConnectionInfo where c.OutputOperator == e select c; foreach (var c in cons) { c.PassCounter++; c.ConnectedAction.Run(gc); } } } } }
public static List <Core.Data.Geocache> AddGeocaches(Core.Storage.Database db, List <OKAPIService.Geocache> gcList) { List <Core.Data.Geocache> result = new List <Core.Data.Geocache>(); if (gcList != null) { foreach (var gcApi in gcList) { Core.Data.Geocache activeGC = Convert.AddGeocache(db, gcApi); if (activeGC != null) { if (gcApi.latest_logs != null) { foreach (var l in gcApi.latest_logs) { Convert.AddLog(db, l, "", ""); } } if (gcApi.alt_wpts != null) { foreach (var wp in gcApi.alt_wpts) { Convert.AddWaypoint(db, wp); } } if (gcApi.images != null) { foreach (var imgd in gcApi.images) { Convert.AddGeocacheImage(db, imgd, activeGC.Code); } } } } } return(result); }
private bool foundByAll(Core.Data.Geocache gc, string[] users) { bool result = true; List <Core.Data.Log> lgs = (from a in Utils.DataAccess.GetLogs(gc.Database, gc.Code) where a.LogType.AsFound select a).ToList(); //foreach (string usr in users) //{ // if ((from a in lgs where string.Compare(a.Finder, usr, true) == 0 select a).FirstOrDefault() == null) // { // result = false; // break; // } //} foreach (var l in lgs) { string f = l.Finder; if ((from a in users where string.Compare(a, f, true) == 0 select a).FirstOrDefault() != null) { result = false; break; } } return(result); }
public void AddMarker(Core.Data.Geocache m, bool enableCluster) { double lat; double lon; if (m.ContainsCustomLatLon) { lat = (double)m.CustomLat; lon = (double)m.CustomLon; } else { lat = m.Lat; lon = m.Lon; } if (enableCluster) { Bucket bucket = (from b in Buckets where lat >= (b.Latitude - _latDelta) && lat <= (b.Latitude + _latDelta) && lon >= (b.Longitude - _lonDelta) && lon <= (b.Longitude + _lonDelta) select b).FirstOrDefault(); if (bucket == null) { Buckets.Add(new Bucket(m)); } else { bucket.AddMarker(m); } } else { Buckets.Add(new Bucket(m)); } }
public override object GetValue(Core.Data.Geocache gc) { return(gc.FoundDate == null ? "" : ((DateTime)gc.FoundDate).ToString("d")); }
public string Next() { string result = ""; XmlDocument doc = new XmlDocument(); if (_index < _gcList.Count) { Core.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 (Core.Settings.Default.GPXUseNameForGCCode) { nameValue = transformedGeocacheName(gc.Name ?? ""); } else { nameValue = gc.Code; } el = doc.CreateElement("name"); if (gc.ContainsCustomLatLon) { txt = doc.CreateTextNode(string.Format("{0}{1}", Core.Settings.Default.GPXExtraCoordPrefix ?? "", nameValue)); } else { txt = doc.CreateTextNode(nameValue); } el.AppendChild(txt); wpt.AppendChild(el); el = doc.CreateElement("desc"); if (Core.Settings.Default.GPXUseHintsForDescription) { 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(Utils.Conversion.GetCacheIDFromCacheCode(gc.Code).ToString()); 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.ContainsCustomLatLon.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(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 (Core.Settings.Default.GPXAddFieldnotesToDescription && gc.ContainsNote) { StringBuilder sb = new StringBuilder(); if (gc.ShortDescriptionInHtml) { if (!string.IsNullOrEmpty(gc.PersonalNote)) { sb.AppendFormat("<p>{0}</p><br />", System.Web.HttpUtility.HtmlEncode(gc.PersonalNote)); } 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.PersonalNote)) { sb.AppendFormat("{0}\r\n\r\n", gc.PersonalNote); } 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 (Core.Settings.Default.GPXAddAdditionWaypointsToDescription) { List<Core.Data.Waypoint> wpts = Utils.DataAccess.GetWaypointsFromGeocache(gc.Database, 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 (Core.Data.Waypoint wp in wpts) { awp.AppendFormat("{0} - {1} ({2})<br />", HttpUtility.HtmlEncode(wp.ID ?? ""), HttpUtility.HtmlEncode(wp.Description ?? ""), HttpUtility.HtmlEncode(Localization.TranslationManager.Instance.Translate(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 (Core.Data.Waypoint wp in wpts) { awp.AppendFormat("{0} - {1} ({2})\r\n", wp.ID ?? "", wp.Description ?? "", Localization.TranslationManager.Instance.Translate(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.PersonalNote ?? ""); 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<Core.Data.Log> logs = Utils.DataAccess.GetLogs(gc.Database, gc.Code).Take(Core.Settings.Default.GPXMaxLogCount).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); }