private void updateThreadMethod() { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(ActionBuilderForm.ActionBuilderFormInstance.OwnerPlugin as Utils.BasePlugin.Plugin, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, _gcList.Count, 0, true)) { int totalcount = _gcList.Count; using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken))) { int index = 0; int gcupdatecount; TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100); DateTime prevCall = DateTime.MinValue; bool dodelay; gcupdatecount = 100; dodelay = (_gcList.Count / gcupdatecount > 30); while (_gcList.Count > 0) { if (dodelay) { TimeSpan ts = DateTime.Now - prevCall; if (ts < interval) { Thread.Sleep(interval - ts); } } var req = new Utils.API.LiveV6.GetGeocacheStatusRequest(); req.AccessToken = client.Token; req.CacheCodes = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray(); _gcList.RemoveRange(0, req.CacheCodes.Length); index += req.CacheCodes.Length; prevCall = DateTime.Now; var resp = client.Client.GetGeocacheStatus(req); if (resp.Status.StatusCode == 0 && resp.GeocacheStatuses != null) { foreach (var gs in resp.GeocacheStatuses) { Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, gs.CacheCode); if (gc != null) { gc.DataFromDate = DateTime.Now; gc.Archived = gs.Archived; gc.Available = gs.Available; gc.Name = gs.CacheName; gc.Title = gs.CacheName; gc.MemberOnly = gs.Premium; } } } else if (resp.Status.StatusCode != 0) { _errormessage = resp.Status.StatusMessage; break; } if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index)) { break; } } } } } catch(Exception e) { _errormessage = e.Message; } _actionDone.Set(); }
protected override void ImportMethod() { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, _gcList.Count, 0, true)) { int totalcount = _gcList.Count; using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken))) { int index = 0; int gcupdatecount; if (_updateStatusOnly) { gcupdatecount = 109; } else { gcupdatecount = 20; } while (_gcList.Count > 0) { if (_updateStatusOnly) { var req = new Utils.API.LiveV6.GetGeocacheStatusRequest(); req.AccessToken = client.Token; req.CacheCodes = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray(); _gcList.RemoveRange(0, req.CacheCodes.Length); index += req.CacheCodes.Length; var resp = client.Client.GetGeocacheStatus(req); if (resp.Status.StatusCode == 0 && resp.GeocacheStatuses != null) { foreach (var gs in resp.GeocacheStatuses) { Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, gs.CacheCode); if (gc != null) { gc.DataFromDate = DateTime.Now; gc.Archived = gs.Archived; gc.Available = gs.Available; gc.Name = gs.CacheName; gc.Title = gs.CacheName; gc.MemberOnly = gs.Premium; if (PluginSettings.Instance.DeselectGeocacheAfterUpdate) { gc.Selected = false; } } } } else { if (resp.Status.StatusCode != 0) { _errormessage = resp.Status.StatusMessage; } break; } } else { Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest(); req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1; req.AccessToken = client.Token; req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter(); req.CacheCode.CacheCodes = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray(); req.MaxPerPage = gcupdatecount; req.GeocacheLogCount = 5; index += req.CacheCode.CacheCodes.Length; _gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length); var resp = client.Client.SearchForGeocaches(req); if (resp.Status.StatusCode == 0 && resp.Geocaches != null) { Utils.API.Import.AddGeocaches(Core, resp.Geocaches); if (PluginSettings.Instance.DeselectGeocacheAfterUpdate) { foreach (var g in resp.Geocaches) { Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, g.Code); if (gc != null) { gc.Selected = false; } } } } else { _errormessage = resp.Status.StatusMessage; break; } } if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index)) { break; } if (_gcList.Count > 0) { Thread.Sleep(3000); } } } } } catch (Exception e) { _errormessage = e.Message; } }
protected override void ImportMethod() { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, _gcList.Count, 0, true)) { int totalcount = _gcList.Count; using (Utils.API.GeocachingLiveV6 client = new Utils.API.GeocachingLiveV6(Core, string.IsNullOrEmpty(Core.GeocachingComAccount.APIToken))) { int index = 0; int gcupdatecount; TimeSpan interval = new TimeSpan(0, 0, 0, 2, 100); DateTime prevCall = DateTime.MinValue; bool dodelay; if (_updateStatusOnly) { gcupdatecount = 109; dodelay = (_gcList.Count / gcupdatecount > 30); } else { gcupdatecount = 30; dodelay = (_gcList.Count > 30); } while (_gcList.Count > 0) { if (dodelay) { TimeSpan ts = DateTime.Now - prevCall; if (ts < interval) { Thread.Sleep(interval - ts); } } if (_updateStatusOnly) { var req = new Utils.API.LiveV6.GetGeocacheStatusRequest(); req.AccessToken = client.Token; req.CacheCodes = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray(); _gcList.RemoveRange(0, req.CacheCodes.Length); index += req.CacheCodes.Length; prevCall = DateTime.Now; var resp = client.Client.GetGeocacheStatus(req); if (resp.Status.StatusCode == 0 && resp.GeocacheStatuses != null) { foreach (var gs in resp.GeocacheStatuses) { Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, gs.CacheCode); if (gc != null) { gc.DataFromDate = DateTime.Now; gc.Archived = gs.Archived; gc.Available = gs.Available; gc.Name = gs.CacheName; gc.Title = gs.CacheName; gc.MemberOnly = gs.Premium; if (Properties.Settings.Default.DeselectGeocacheAfterUpdate) { gc.Selected = false; } } } } else { if (resp.Status.StatusCode != 0) { _errormessage = resp.Status.StatusMessage; } break; } } else { Utils.API.LiveV6.SearchForGeocachesRequest req = new Utils.API.LiveV6.SearchForGeocachesRequest(); req.IsLite = Core.GeocachingComAccount.MemberTypeId == 1; req.AccessToken = client.Token; req.CacheCode = new Utils.API.LiveV6.CacheCodeFilter(); req.CacheCode.CacheCodes = (from a in _gcList select a.Code).Take(gcupdatecount).ToArray(); req.MaxPerPage = gcupdatecount; req.GeocacheLogCount = 5; index += req.CacheCode.CacheCodes.Length; _gcList.RemoveRange(0, req.CacheCode.CacheCodes.Length); prevCall = DateTime.Now; var resp = client.Client.SearchForGeocaches(req); if (resp.Status.StatusCode == 0 && resp.Geocaches != null) { Utils.API.Import.AddGeocaches(Core, resp.Geocaches); if (Properties.Settings.Default.DeselectGeocacheAfterUpdate) { foreach (var g in resp.Geocaches) { Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, g.Code); if (gc != null) { gc.Selected = false; } } } } else { _errormessage = resp.Status.StatusMessage; break; } } if (!progress.UpdateProgress(STR_UPDATINGGEOCACHES, STR_UPDATINGGEOCACHE, totalcount, index)) { break; } } } } } catch(Exception e) { _errormessage = e.Message; } }