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 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; }