public static void ImportGeocacheStatus(Core.Storage.Database db, List <string> gcCodes) { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock("UpdatingGeocaches", "UpdatingGeocaches", gcCodes.Count, 0, true)) { int totalcount = gcCodes.Count; using (var client = new GeocachingLiveV6()) { int index = 0; while (gcCodes.Count > 0) { var req = new LiveV6.GetGeocacheStatusRequest(); req.AccessToken = client.Token; req.CacheCodes = (from a in gcCodes select a).Take(Core.Settings.Default.LiveAPIGetGeocacheStatusBatchSize).ToArray(); index += req.CacheCodes.Length; gcCodes.RemoveRange(0, req.CacheCodes.Length); var resp = client.Client.GetGeocacheStatus(req); if (resp.Status.StatusCode == 0 && resp.GeocacheStatuses != null) { foreach (var gs in resp.GeocacheStatuses) { Core.Data.Geocache gc = db.GeocacheCollection.GetGeocache(gs.CacheCode); if (gc != null) { gc.DataFromDate = DateTime.Now; gc.Archived = gs.Archived; gc.Available = gs.Available; if (!gc.Locked) { gc.Name = gs.CacheName; } gc.MemberOnly = gs.Premium; if (Core.Settings.Default.LiveAPIDeselectAfterUpdate) { gc.Selected = false; } } } } else { Core.ApplicationData.Instance.Logger.AddLog(new Import(), new Exception(resp.Status.StatusMessage)); break; } if (!progress.Update("UpdatingGeocaches", totalcount, index)) { break; } if (gcCodes.Count > 0) { System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetGeocacheStatus); } } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(new Import(), e); } }
public static void ImportGeocacheStatus(Core.Storage.Database db, List<string> gcCodes) { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock("UpdatingGeocaches", "UpdatingGeocaches", gcCodes.Count, 0, true)) { int totalcount = gcCodes.Count; using (var client = new GeocachingLiveV6()) { int index = 0; while (gcCodes.Count > 0) { var req = new LiveV6.GetGeocacheStatusRequest(); req.AccessToken = client.Token; req.CacheCodes = (from a in gcCodes select a).Take(Core.Settings.Default.LiveAPIGetGeocacheStatusBatchSize).ToArray(); index += req.CacheCodes.Length; gcCodes.RemoveRange(0, req.CacheCodes.Length); var resp = client.Client.GetGeocacheStatus(req); if (resp.Status.StatusCode == 0 && resp.GeocacheStatuses != null) { foreach (var gs in resp.GeocacheStatuses) { Core.Data.Geocache gc = db.GeocacheCollection.GetGeocache(gs.CacheCode); if (gc != null) { gc.DataFromDate = DateTime.Now; gc.Archived = gs.Archived; gc.Available = gs.Available; if (!gc.Locked) { gc.Name = gs.CacheName; } gc.MemberOnly = gs.Premium; if (Core.Settings.Default.LiveAPIDeselectAfterUpdate) { gc.Selected = false; } } } } else { Core.ApplicationData.Instance.Logger.AddLog(new Import(), new Exception(resp.Status.StatusMessage)); break; } if (!progress.Update("UpdatingGeocaches", totalcount, index)) { break; } if (gcCodes.Count > 0) { System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetGeocacheStatus); } } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(new Import(), e); } }