public void AddOwnTrackables(TrackableGroup grp) { bool canceled = false; using (Utils.ProgressBlock progr = new Utils.ProgressBlock("GetTrackableData", "GetTrackableData", 1, 0, true)) using (var api = new LiveAPI.GeocachingLiveV6()) { List <string> trkCodes = new List <string>(); var req = new LiveAPI.LiveV6.GetTrackablesByOwnerRequest(); req.AccessToken = api.Token; req.TrackableLogsCount = 0; req.StartIndex = 0; req.MaxPerPage = Core.Settings.Default.LiveAPIGetOwnedTrackablesBatchSize; int total = 0; while (true) { var resp = api.Client.GetOwnedTrackables(req); if (resp.Status.StatusCode == 0) { if (resp.Trackables != null) { foreach (var t in resp.Trackables) { trkCodes.Add(t.Code); Core.Settings.Default.AddUpdateTrackable(grp, GetTrackableItemFromLiveAPI(t)); total++; } if (!progr.Update("GetTrackableData", total, 2 * total)) { canceled = true; break; } } if (resp.Trackables.Count() < req.MaxPerPage) { break; } else { req.StartIndex = total; System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetOwnedTrackables); } } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); break; } } if (!canceled) { progr.Update("GetTrackableData", total, total); AddUpdateTrackables(grp, trkCodes); } } }
public void AddOwnTrackables(TrackableGroup grp) { bool canceled = false; using (Utils.ProgressBlock progr = new Utils.ProgressBlock("GetTrackableData", "GetTrackableData", 1, 0, true)) using (var api = new LiveAPI.GeocachingLiveV6()) { List<string> trkCodes = new List<string>(); var req = new LiveAPI.LiveV6.GetTrackablesByOwnerRequest(); req.AccessToken = api.Token; req.TrackableLogsCount = 0; req.StartIndex = 0; req.MaxPerPage = Core.Settings.Default.LiveAPIGetOwnedTrackablesBatchSize; int total = 0; while (true) { var resp = api.Client.GetOwnedTrackables(req); if (resp.Status.StatusCode == 0) { if (resp.Trackables != null) { foreach (var t in resp.Trackables) { trkCodes.Add(t.Code); Core.Settings.Default.AddUpdateTrackable(grp, GetTrackableItemFromLiveAPI(t)); total++; } if (!progr.Update("GetTrackableData", total, 2 * total)) { canceled = true; break; } } if (resp.Trackables.Count() < req.MaxPerPage) { break; } else { req.StartIndex = total; System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetOwnedTrackables); } } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); break; } } if (!canceled) { progr.Update("GetTrackableData", total, total); AddUpdateTrackables(grp, trkCodes); } } }