private void ShowRouteOnMap(TrackableItem tb) { if (tb != null) { try { string htmlcontent = Utils.ResourceHelper.GetEmbeddedTextFile("/UIControls/Trackables/trackablesmap.html"); StringBuilder sb = new StringBuilder(); List <TravelItem> til = Core.Settings.Default.GetTrackableTravels(tb); for (int i = 0; i < til.Count; i++) { StringBuilder bln = new StringBuilder(); bln.AppendFormat("{0}: {1}", Localization.TranslationManager.Instance.Translate("Step"), i + 1); bln.AppendFormat("<br />{0}: {1}", Localization.TranslationManager.Instance.Translate("Date"), til[i].DateLogged.ToLongDateString()); bln.AppendFormat("<br />{0}: <a href=\"http://coord.info/{1}\" target=\"_blank\">{1}</a>", Localization.TranslationManager.Instance.Translate("Geocache"), til[i].GeocacheCode); string iconColor; if (i == 0) { iconColor = "yellowIcon"; } else if (i == til.Count - 1) { iconColor = "redIcon"; } else { iconColor = "blueIcon"; } sb.AppendFormat("createMarker('{5}-{0}', new google.maps.LatLng({1}, {2}), {3}, '{4}');", til[i].GeocacheCode, til[i].Lat.ToString().Replace(',', '.'), til[i].Lon.ToString().Replace(',', '.'), iconColor, bln.ToString().Replace("'", ""), i + 1); } if (til.Count > 1) { sb.AppendLine(); sb.Append("var polylineA = new google.maps.Polyline({map: map, path: ["); for (int i = 0; i < til.Count; i++) { if (i > 0) { sb.Append(","); } sb.AppendFormat("new google.maps.LatLng({0}, {1})", til[i].Lat.ToString().Replace(',', '.'), til[i].Lon.ToString().Replace(',', '.')); } sb.Append("], strokeColor: '#8A2BE2', strokeWeight: 4, strokeOpacity: .9});"); } string html = htmlcontent.Replace("//patchwork", sb.ToString()); string fn = System.IO.Path.Combine(Core.Settings.Default.SettingsFolder, "trackablesmap.html"); System.IO.File.WriteAllText(fn, html); System.Diagnostics.Process.Start(fn); } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } } }
private TrackableItem GetTrackableItemFromLiveAPI(LiveAPI.LiveV6.Trackable t) { TrackableItem trk = new TrackableItem(); trk.Code = t.Code; trk.AllowedToBeCollected = t.AllowedToBeCollected; trk.Archived = t.Archived; trk.BugTypeID = t.BugTypeID; trk.CurrentGeocacheCode = t.CurrentGeocacheCode; trk.CurrentGoal = t.CurrentGoal; trk.DateCreated = t.DateCreated; trk.Description = t.Description; trk.IconUrl = t.IconUrl; trk.IconData = Core.Settings.Default.GetTrackableIconData(trk.IconUrl); if (trk.IconData == null && !string.IsNullOrEmpty(t.IconUrl)) { try { using (System.Net.WebClient wc = new System.Net.WebClient()) { trk.IconData = wc.DownloadData(t.IconUrl); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } } trk.Id = t.Id; trk.InCollection = t.InCollection; trk.Name = t.Name; trk.TBTypeName = t.TBTypeName; trk.Url = t.Url; trk.WptTypeID = t.WptTypeID; if (t.OriginalOwner != null) { trk.Owner = t.OriginalOwner.UserName; } else { trk.Owner = ""; } return(trk); }
private bool AddUpdateTrackable(LiveAPI.GeocachingLiveV6 api, TrackableGroup grp, string trkCode) { bool result = true; if (trkCode.ToUpper().StartsWith("TB")) { try { var resp = api.Client.GetTrackablesByTBCode(api.Token, trkCode.ToUpper(), 0); if (resp.Status.StatusCode == 0) { if (resp.Trackables != null) { foreach (var t in resp.Trackables) { TrackableItem trk = GetTrackableItemFromLiveAPI(t); Core.Settings.Default.AddUpdateTrackable(grp, trk); var resp2 = api.Client.GetTrackableTravelList(api.Token, trk.Code); if (resp2.Status.StatusCode == 0) { if (resp2.TrackableTravels != null) { List <TravelItem> travelList = new List <TravelItem>(); foreach (var tt in resp2.TrackableTravels) { if (tt.Latitude != null && tt.Longitude != null) { TravelItem ti = new TravelItem(); ti.TrackableCode = trk.Code; if (tt.CacheID != null) { ti.GeocacheCode = Utils.Conversion.GetCacheCodeFromCacheID((int)tt.CacheID); } else { ti.GeocacheCode = ""; } ti.DateLogged = tt.DateLogged; ti.Lat = (double)tt.Latitude; ti.Lon = (double)tt.Longitude; travelList.Add(ti); } } Core.Settings.Default.UpdateTrackableTravels(trk, travelList); } //get all logs List <LogItem> logs = new List <LogItem>(); int maxPageSize = Core.Settings.Default.LiveAPIGetTrackableLogsByTBCodeBatchSize; while (true) { var resp3 = api.Client.GetTrackableLogsByTBCode(api.Token, trk.Code, logs.Count, maxPageSize); if (resp3.Status.StatusCode == 0) { if (resp3.TrackableLogs != null) { foreach (var tl in resp3.TrackableLogs) { LogItem li = new LogItem(); li.TrackableCode = trk.Code; if (tl.CacheID != null) { li.GeocacheCode = Utils.Conversion.GetCacheCodeFromCacheID((int)tl.CacheID); } else { li.GeocacheCode = ""; } li.LogCode = tl.Code; li.ID = tl.ID; li.IsArchived = tl.IsArchived; li.LoggedBy = tl.LoggedBy == null ? "" : tl.LoggedBy.UserName; li.LogGuid = tl.LogGuid.ToString(); li.LogIsEncoded = tl.LogIsEncoded; li.LogText = tl.LogText; li.WptLogTypeId = tl.LogType == null ? -1 : (int)tl.LogType.WptLogTypeId; li.Url = tl.Url; li.UTCCreateDate = tl.UTCCreateDate; li.VisitDate = tl.VisitDate; logs.Add(li); } if (resp3.TrackableLogs.Count() < maxPageSize) { break; } System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetTrackableLogsByTBCode); } else { break; } } else { logs = null; result = false; Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp3.Status.StatusMessage); break; } } if (logs != null) { Core.Settings.Default.UpdateTrackableLogs(trk, logs); } } else { result = false; Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp2.Status.StatusMessage); } } } } else { result = false; Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); } } catch (Exception e) { result = false; Core.ApplicationData.Instance.Logger.AddLog(this, e); } } return(result); }
private TrackableItem GetTrackableItemFromLiveAPI(LiveAPI.LiveV6.Trackable t) { TrackableItem trk = new TrackableItem(); trk.Code = t.Code; trk.AllowedToBeCollected = t.AllowedToBeCollected; trk.Archived = t.Archived; trk.BugTypeID = t.BugTypeID; trk.CurrentGeocacheCode = t.CurrentGeocacheCode; trk.CurrentGoal = t.CurrentGoal; trk.DateCreated = t.DateCreated; trk.Description = t.Description; trk.IconUrl = t.IconUrl; trk.IconData = Core.Settings.Default.GetTrackableIconData(trk.IconUrl); if (trk.IconData==null && !string.IsNullOrEmpty(t.IconUrl)) { try { using (System.Net.WebClient wc = new System.Net.WebClient()) { trk.IconData = wc.DownloadData(t.IconUrl); } } catch(Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } } trk.Id = t.Id; trk.InCollection = t.InCollection; trk.Name = t.Name; trk.TBTypeName = t.TBTypeName; trk.Url = t.Url; trk.WptTypeID = t.WptTypeID; if (t.OriginalOwner != null) { trk.Owner = t.OriginalOwner.UserName; } else { trk.Owner = ""; } return trk; }