public static bool Authorize(bool syncAll, bool testSite) { bool result = false; try { AuthorizationWindow dlg = new AuthorizationWindow(testSite); if (dlg.ShowDialog() == true) { if (testSite) { Core.Settings.Default.LiveAPITokenStaging = dlg.Token; } else { Core.Settings.Default.LiveAPIToken = dlg.Token; } using (GeocachingLiveV6 client = new GeocachingLiveV6(testSite)) { var resp = client.Client.GetYourUserProfile(new LiveV6.GetYourUserProfileRequest() { AccessToken = client.Token, DeviceInfo = new LiveV6.DeviceData() { DeviceName = "GlobalcachingApplication", DeviceUniqueId = "internal", ApplicationSoftwareVersion = "V1.0.0.0" } }); if (resp.Status.StatusCode == 0) { result = true; Core.Data.AccountInfo ai = new Core.Data.AccountInfo("GC", resp.Profile.User.UserName); Core.ApplicationData.Instance.AccountInfos.Add(ai); Core.Settings.Default.LiveAPIMemberType = resp.Profile.User.MemberType.MemberTypeName; Core.Settings.Default.LiveAPIMemberTypeId = (int)resp.Profile.User.MemberType.MemberTypeId; if (syncAll) { if (resp.Profile.User.HomeCoordinates != null) { Core.Settings.Default.HomeLocationLat = resp.Profile.User.HomeCoordinates.Latitude; Core.Settings.Default.HomeLocationLon = resp.Profile.User.HomeCoordinates.Longitude; } } } else { } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(null, e); } return(result); }
public static void ImportGeocaches(Core.Storage.Database db, List <string> gcCodes) { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingGeocaches", "ImportingGeocaches", gcCodes.Count, 0, true)) { int totalcount = gcCodes.Count; using (var client = new GeocachingLiveV6()) { int index = 0; while (gcCodes.Count > 0) { LiveV6.SearchForGeocachesRequest req = new LiveV6.SearchForGeocachesRequest(); req.IsLite = Core.Settings.Default.LiveAPIMemberTypeId == 1; req.AccessToken = client.Token; req.CacheCode = new LiveV6.CacheCodeFilter(); req.CacheCode.CacheCodes = (from a in gcCodes select a).Take(Core.Settings.Default.LiveAPIImportGeocachesBatchSize).ToArray(); req.MaxPerPage = Core.Settings.Default.LiveAPIImportGeocachesBatchSize; req.GeocacheLogCount = 5; index += req.CacheCode.CacheCodes.Length; gcCodes.RemoveRange(0, req.CacheCode.CacheCodes.Length); var resp = client.Client.SearchForGeocaches(req); if (resp.Status.StatusCode == 0 && resp.Geocaches != null) { List <Core.Data.Geocache> upList = ImportGeocaches(db, resp.Geocaches); if (Core.Settings.Default.LiveAPIDeselectAfterUpdate) { foreach (var g in upList) { g.Selected = false; } } } else { Core.ApplicationData.Instance.Logger.AddLog(new Import(), new Exception(resp.Status.StatusMessage)); break; } if (!progress.Update("ImportingGeocaches", totalcount, index)) { break; } if (gcCodes.Count > 0) { System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelaySearchForGeocaches); } } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(new Import(), e); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { using (GeocachingLiveV6 client = new GeocachingLiveV6()) { var resp = client.Client.GetYourUserProfile(new LiveV6.GetYourUserProfileRequest() { AccessToken = Token, DeviceInfo = new LiveV6.DeviceData() { DeviceName = "GlobalcachingApplication", DeviceUniqueId = "internal", ApplicationSoftwareVersion = "V1.0.0.0" } }); if (resp.Status.StatusCode == 0) { Core.Settings.Default.LiveAPIToken = Token; Core.Data.AccountInfo ai = new Core.Data.AccountInfo("GC", resp.Profile.User.UserName); Core.ApplicationData.Instance.AccountInfos.Add(ai); Core.Settings.Default.LiveAPIMemberType = resp.Profile.User.MemberType.MemberTypeName; Core.Settings.Default.LiveAPIMemberTypeId = (int)resp.Profile.User.MemberType.MemberTypeId; if (resp.Profile.User.HomeCoordinates != null) { Core.Settings.Default.HomeLocationLat = resp.Profile.User.HomeCoordinates.Latitude; Core.Settings.Default.HomeLocationLon = resp.Profile.User.HomeCoordinates.Longitude; } Close(); } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); } } } catch (Exception ex) { Core.ApplicationData.Instance.Logger.AddLog(this, ex); } }
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 ImportGeocaches(Core.Storage.Database db, LiveV6.SearchForGeocachesRequest req, int max) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingGeocaches", "ImportingGeocaches", max, 0, true)) { try { using (GeocachingLiveV6 client = new GeocachingLiveV6()) { req.AccessToken = client.Token; var resp = client.Client.SearchForGeocaches(req); if (resp.Status.StatusCode == 0 && resp.Geocaches != null) { ImportGeocaches(db, resp.Geocaches); if (resp.Geocaches.Count() >= req.MaxPerPage && req.MaxPerPage < max) { if (progress.Update("ImportingGeocaches", max, resp.Geocaches.Count())) { var mreq = new LiveV6.GetMoreGeocachesRequest(); mreq.AccessToken = req.AccessToken; mreq.GeocacheLogCount = req.GeocacheLogCount; mreq.MaxPerPage = (int)Math.Min(req.MaxPerPage, max - resp.Geocaches.Count()); mreq.StartIndex = resp.Geocaches.Count(); mreq.TrackableLogCount = req.TrackableLogCount; mreq.IsLite = req.IsLite; mreq.GeocacheLogCount = req.GeocacheLogCount; while (resp.Status.StatusCode == 0 && resp.Geocaches != null && resp.Geocaches.Count() >= req.MaxPerPage) { resp = client.Client.GetMoreGeocaches(mreq); if (resp.Status.StatusCode == 0 && resp.Geocaches != null) { ImportGeocaches(db, resp.Geocaches); if (!progress.Update("ImportingGeocaches", max, mreq.StartIndex + resp.Geocaches.Count())) { break; } mreq.StartIndex += resp.Geocaches.Count(); mreq.MaxPerPage = (int)Math.Min(req.MaxPerPage, max - mreq.StartIndex); if (mreq.StartIndex >= max - 1) { break; } } else { Core.ApplicationData.Instance.Logger.AddLog(new Import(), Core.Logger.Level.Error, resp.Status.StatusMessage); } } } } } else { Core.ApplicationData.Instance.Logger.AddLog(new Import(), Core.Logger.Level.Error, resp.Status.StatusMessage); } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(new Import(), e); } } }
public static void ImportGeocaches(Core.Storage.Database db, List<string> gcCodes) { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingGeocaches", "ImportingGeocaches", gcCodes.Count, 0, true)) { int totalcount = gcCodes.Count; using (var client = new GeocachingLiveV6()) { int index = 0; while (gcCodes.Count > 0) { LiveV6.SearchForGeocachesRequest req = new LiveV6.SearchForGeocachesRequest(); req.IsLite = Core.Settings.Default.LiveAPIMemberTypeId == 1; req.AccessToken = client.Token; req.CacheCode = new LiveV6.CacheCodeFilter(); req.CacheCode.CacheCodes = (from a in gcCodes select a).Take(Core.Settings.Default.LiveAPIImportGeocachesBatchSize).ToArray(); req.MaxPerPage = Core.Settings.Default.LiveAPIImportGeocachesBatchSize; req.GeocacheLogCount = 5; index += req.CacheCode.CacheCodes.Length; gcCodes.RemoveRange(0, req.CacheCode.CacheCodes.Length); var resp = client.Client.SearchForGeocaches(req); if (resp.Status.StatusCode == 0 && resp.Geocaches != null) { List<Core.Data.Geocache> upList = ImportGeocaches(db, resp.Geocaches); if (Core.Settings.Default.LiveAPIDeselectAfterUpdate) { foreach (var g in upList) { g.Selected = false; } } } else { Core.ApplicationData.Instance.Logger.AddLog(new Import(), new Exception(resp.Status.StatusMessage)); break; } if (!progress.Update("ImportingGeocaches", totalcount, index)) { break; } if (gcCodes.Count>0) { System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelaySearchForGeocaches); } } } } } 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); } }
public static bool Authorize(bool syncAll, bool testSite) { bool result = false; try { AuthorizationWindow dlg = new AuthorizationWindow(testSite); if (dlg.ShowDialog()==true) { if (testSite) { Core.Settings.Default.LiveAPITokenStaging = dlg.Token; } else { Core.Settings.Default.LiveAPIToken = dlg.Token; } using (GeocachingLiveV6 client = new GeocachingLiveV6(testSite)) { LiveV6.GetUserProfileResponse resp = client.Client.GetYourUserProfile(new LiveV6.GetYourUserProfileRequest() { AccessToken = client.Token, DeviceInfo = new LiveV6.DeviceData() { DeviceName = "GlobalcachingApplication", DeviceUniqueId = "internal", ApplicationSoftwareVersion = "V1.0.0.0" } }); if (resp.Status.StatusCode == 0) { result = true; Core.Data.AccountInfo ai = new Core.Data.AccountInfo("GC", resp.Profile.User.UserName); Core.ApplicationData.Instance.AccountInfos.Add(ai); Core.Settings.Default.LiveAPIMemberType = resp.Profile.User.MemberType.MemberTypeName; Core.Settings.Default.LiveAPIMemberTypeId = (int)resp.Profile.User.MemberType.MemberTypeId; if (syncAll) { if (resp.Profile.User.HomeCoordinates != null) { Core.Settings.Default.HomeLocationLat = resp.Profile.User.HomeCoordinates.Latitude; Core.Settings.Default.HomeLocationLon = resp.Profile.User.HomeCoordinates.Longitude; } } } else { } } } } catch(Exception e) { Core.ApplicationData.Instance.Logger.AddLog(null, e); } return result; }