public async Task SelectWithinRadiusAsync() { try { Core.Data.Location center = null; double radius = 0; string filter = null; object o = executeScript("getCenterPosition", null); if (o != null && o.GetType() != typeof(DBNull)) { string s = o.ToString().Replace("(", "").Replace(")", ""); center = Utils.Conversion.StringToLocation(s); } o = executeScript("getRadius", null); if (o != null && o.GetType() != typeof(DBNull)) { string s = o.ToString(); radius = Utils.Conversion.StringToDouble(s) * 1000.0; } using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(new Action(() => { try { //first get a list of geocache codes List <string> gcList = OKAPIService.GetGeocachesWithinRadius(SiteManager.Instance.ActiveSite, center, radius, filter); using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingOpencachingGeocaches", "ImportingOpencachingGeocaches", gcList.Count, 0, true)) { int gcupdatecount = 1; int max = gcList.Count; while (gcList.Count > 0) { List <string> lcs = gcList.Take(gcupdatecount).ToList(); gcList.RemoveRange(0, lcs.Count); List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs); Import.AddGeocaches(Core.ApplicationData.Instance.ActiveDatabase, caches); if (!progress.Update("ImportingOpencachingGeocaches", max, max - gcList.Count)) { break; } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } })); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }
public async Task SelectWithinBoundsAsync() { try { double minLat = 0.0; double minLon = 0.0; double maxLat = 0.0; double maxLon = 0.0; object o = executeScript("getBounds", null); if (o != null && o.GetType() != typeof(DBNull)) { string s = o.ToString().Replace("(", "").Replace(")", ""); string[] parts = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); minLat = Utils.Conversion.StringToDouble(parts[0]); minLon = Utils.Conversion.StringToDouble(parts[1]); maxLat = Utils.Conversion.StringToDouble(parts[2]); maxLon = Utils.Conversion.StringToDouble(parts[3]); } using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(new Action(() => { try { //first get a list of geocache codes List <string> gcList = OKAPIService.GetGeocachesInBBox(SiteManager.Instance.ActiveSite, minLat, minLon, maxLat, maxLon); using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportGeocaches", "ImportGeocaches", gcList.Count, 0, true)) { int gcupdatecount = 1; int max = gcList.Count; while (gcList.Count > 0) { List <string> lcs = gcList.Take(gcupdatecount).ToList(); gcList.RemoveRange(0, lcs.Count); List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(SiteManager.Instance.ActiveSite, lcs); Import.AddGeocaches(Core.ApplicationData.Instance.ActiveDatabase, caches); if (!progress.Update("ImportGeocaches", max, max - gcList.Count)) { break; } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } })); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }
public void ImportMyLogsWithCaches(Core.Storage.Database db, SiteInfo activeSite) { using (Utils.ProgressBlock blockprogress = new Utils.ProgressBlock("ImportingOpencachingLogs", "ImportingOpencachingLogs", 2, 0, true)) { bool cancelled = false; try { int stepSize = 100; List <OKAPIService.Log> logs = new List <OKAPIService.Log>(); using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingOpencachingLogs", "ImportingOpencachingLogs", 100, 0, true)) { List <OKAPIService.Log> pageLogs = OKAPIService.GetLogsOfUserID(activeSite, activeSite.UserID, stepSize, 0); while (pageLogs.Count() > 0) { logs.AddRange(pageLogs); if (!progress.Update("ImportingOpencachingLogs", logs.Count + stepSize, logs.Count)) { cancelled = true; break; } else if (pageLogs.Count() < stepSize) { break; } pageLogs = OKAPIService.GetLogsOfUserID(activeSite, activeSite.UserID, stepSize, logs.Count); } } if (!cancelled) { blockprogress.Update("ImportingOpencachingLogs", 2, 1); //we download the geocaches that are not present. But for the ones we have, we need to add the log and mark it as found List <string> gcList = (from a in logs where db.GeocacheCollection.GetGeocache(a.cache_code) != null select a.cache_code).ToList(); foreach (string s in gcList) { db.GeocacheCollection.GetGeocache(s).Found = true; var ls = (from a in logs where a.cache_code == s select a).ToList(); foreach (var l in ls) { Convert.AddLog(db, l, activeSite.Username, activeSite.UserID); } } gcList = (from a in logs where db.GeocacheCollection.GetGeocache(a.cache_code) == null select a.cache_code).ToList(); using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingOpencachingLogs", "ImportingOpencachingGeocaches", gcList.Count, 0, true)) { int gcupdatecount = 1; while (gcList.Count > 0) { List <string> lcs = gcList.Take(gcupdatecount).ToList(); gcList.RemoveRange(0, lcs.Count); List <OKAPIService.Geocache> caches = OKAPIService.GetGeocaches(activeSite, lcs); Import.AddGeocaches(db, caches); foreach (var g in caches) { var ls = (from a in logs where a.cache_code == g.code select a).ToList(); foreach (var l in ls) { Convert.AddLog(db, l, activeSite.Username, activeSite.UserID); } } if (!progress.Update("ImportingOpencachingGeocaches", logs.Count, logs.Count - gcList.Count)) { cancelled = true; break; } } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } } }