private void getCopiedSelectionGeocacheInbackgroundMethod() { try { LiveAPI.Import.ImportGeocaches(_copySelectionDb, _importGeocaches); foreach (string s in _importGeocaches) { var gc = _copySelectionDb.GeocacheCollection.GetGeocache(s); if (gc != null) { gc.Selected = true; } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } _context.Post(new SendOrPostCallback(delegate(object state) { _dataUpdater.Dispose(); _dataUpdater = null; _importGeocaches.Clear(); _getGeocacheThread = null; _copySelectionDb = null; }), null); }
public async Task ImportMyLogsWithCachesAsync(Core.Storage.Database db, SiteInfo activeSite) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(new Action(() => ImportMyLogsWithCaches(db, activeSite))); } }
private async void TextBlock_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!string.IsNullOrEmpty(FollowActiveGeocacheText) && Core.ApplicationData.Instance.ActiveDatabase != null) { string gcCode = FollowActiveGeocacheText.Split(new char[] { ' ' })[0]; var agc = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection.GetGeocache(gcCode); if (agc == null) { if (gcCode.StartsWith("GC")) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { LiveAPI.Import.ImportGeocaches(Core.ApplicationData.Instance.ActiveDatabase, new string[] { gcCode }.ToList()); }); } var gc = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection.GetGeocache(gcCode); if (gc != null) { Core.ApplicationData.Instance.ActiveGeocache = gc; } } } else { Core.ApplicationData.Instance.ActiveGeocache = agc; } } }
public override async Task ExecuteAsync(object parameter) { Core.ApplicationData.Instance.BeginActiviy(); Core.Storage.Database db = Core.ApplicationData.Instance.ActiveDatabase; if (db != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { Utils.ProgressBlock prog = null; int max = Core.ApplicationData.Instance.MainWindow.GeocacheSelectionCount; DateTime nextUpdate = DateTime.Now.AddSeconds(1); if (_showProgress) { prog = new Utils.ProgressBlock("PerfomingAction", "PerfomingAction", max, 0, true); } try { int index = 0; foreach (Core.Data.Geocache gc in db.GeocacheCollection) { if (gc.Selected) { _geocacheAction(gc); if (prog != null) { index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("PerfomingAction", max, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } } if (prog != null) { prog.Dispose(); prog = null; } } catch(Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); if (prog!=null) { prog.Dispose(); prog = null; } } }); } }; Core.ApplicationData.Instance.EndActiviy(); }
public async Task UpdateGeocachesAsync(Core.Storage.Database db) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(new Action(() => UpdateGeocaches(db))); } }
public async Task ImportFilesAsync(string[] fileNames) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(new Action(() => ImportFiles(fileNames))); } }
public async Task ImportFavoritesAsync(Core.Storage.Database db) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(new Action(() => ImportFavorites(db))); } }
public async Task ImportGeocacheDistanceAsync(Core.Storage.Database db) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(new Action(() => ImportGeocacheDistance(db))); } }
public async Task GetAllYourFavoriteGeocachesAsync(Core.Storage.Database db, bool importMissing) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { try { List<string> gcList = null; using (var api = new LiveAPI.GeocachingLiveV6()) { var respC = api.Client.GetCacheIdsFavoritedByUser(api.Token); if (respC.Status.StatusCode == 0) { gcList = (from s in respC.CacheCodes select s).ToList(); Manager.Instance.AddFavoritedGeocaches(gcList); } else { Core.ApplicationData.Instance.Logger.AddLog(this, new Exception(respC.Status.StatusMessage)); } } if (gcList != null && gcList.Count > 0 && importMissing) { List<string> missingList = (from a in gcList where db.GeocacheCollection.GetGeocache(a) == null select a).ToList(); LiveAPI.Import.ImportGeocaches(db, gcList); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } }
private void Button_Click_8(object sender, RoutedEventArgs e) { try { if (Core.ApplicationData.Instance.ActiveDatabase != null) { List <string> gcList = GetAllGCCodes(); var gc = from a in gcList join b in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection on a equals b.Code select b; using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { foreach (var g in gc) { g.Selected = true; } } } } catch (Exception ex) { Core.ApplicationData.Instance.Logger.AddLog(this, ex); } }
public async Task ImportMunzeesFromDfxAtAsync(Core.Storage.Database db, string url) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(new Action(() => ImportMunzeesFromDfxAt(db, url))); } }
public async Task ImportBookmark(bool missingOnly) { if (ActiveBookmark != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { try { List <string> gcCodes = GCComBookmarks.Manager.Instance.UpdateBookmarkList(ActiveBookmark); if (missingOnly) { List <string> present = (from a in gcCodes join g in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection on a equals g.Code select a).ToList(); foreach (string s in present) { gcCodes.Remove(s); } } LiveAPI.Import.ImportGeocaches(Core.ApplicationData.Instance.ActiveDatabase, gcCodes); } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } } }
public async Task GetAllYourFavoriteGeocachesAsync(Core.Storage.Database db, bool importMissing) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { try { List <string> gcList = null; using (var api = new LiveAPI.GeocachingLiveV6()) { var respC = api.Client.GetCacheIdsFavoritedByUser(api.Token); if (respC.Status.StatusCode == 0) { gcList = (from s in respC.CacheCodes select s).ToList(); Manager.Instance.AddFavoritedGeocaches(gcList); } else { Core.ApplicationData.Instance.Logger.AddLog(this, new Exception(respC.Status.StatusMessage)); } } if (gcList != null && gcList.Count > 0 && importMissing) { List <string> missingList = (from a in gcList where db.GeocacheCollection.GetGeocache(a) == null select a).ToList(); LiveAPI.Import.ImportGeocaches(db, gcList); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } }
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 override async Task ExecuteAsync(object parameter) { Core.ApplicationData.Instance.BeginActiviy(); Core.Storage.Database db = Core.ApplicationData.Instance.ActiveDatabase; if (db != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { Utils.ProgressBlock prog = null; DateTime nextUpdate = DateTime.Now.AddSeconds(1); if (_showProgress) { prog = new Utils.ProgressBlock("PerfomingAction", "PerfomingAction", db.GeocacheCollection.Count, 0, true); } try { int index = 0; foreach (Core.Data.Geocache gc in db.GeocacheCollection) { _geocacheAction(gc); if (prog != null) { index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("PerfomingAction", db.GeocacheCollection.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } if (prog != null) { prog.Dispose(); prog = null; } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); if (prog != null) { prog.Dispose(); prog = null; } } }); } } ; Core.ApplicationData.Instance.EndActiviy(); }
public static async Task ImportGeocacheLogsAsync(Core.Storage.Database db, List<Core.Data.Geocache> gcList) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { ImportGeocacheLogs(db, gcList); }); } }
public async Task ImportNotesAsync(Core.Storage.Database db, bool importMissing) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { ImportNotes(db, importMissing); }); } }
public static async Task ImportGeocacheImagesAsync(Core.Storage.Database db, List <Core.Data.Geocache> gcList) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { ImportGeocacheImages(db, gcList); }); } }
public void invertSelection() { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { foreach (Core.Data.Geocache gc in cacheList.SelectedItems) { gc.Selected = !gc.Selected; } } }
public async Task<List<LogInfo>> LogGeocachesAsync(List<LogInfo> logInfos) { List<LogInfo> result = new List<LogInfo>(); Utils.DataUpdater upd = null; if (Core.ApplicationData.Instance.ActiveDatabase != null) { upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase); } using (Utils.ProgressBlock prog = new Utils.ProgressBlock("LogGeocache", "Logging", logInfos.Count, 0, true)) { using (var api = new LiveAPI.GeocachingLiveV6()) { foreach (LogInfo li in logInfos) { int index = 0; List<LiveAPI.LiveV6.Trackable> dropTbs = null; List<string> retrieveTbs = null; //todo: check if trackable dialog is needed //fetch in background bool ok = false; await Task.Run(() => { if (index > 0 && dropTbs == null && retrieveTbs == null) { System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayCreateFieldNoteAndPublish); } ok = LogGeocache(api, li, dropTbs, retrieveTbs); }); if (ok) { result.Add(li); index++; if (!prog.Update("Logging", logInfos.Count, index)) { break; } } else { break; } } } } if (upd!=null) { upd.Dispose(); upd = null; } return result; }
public async Task RunActionFow(ActionFlow af) { if (Core.ApplicationData.Instance.ActiveDatabase != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { runFlow(af); }); } } }
private async void Button_Click(object sender, RoutedEventArgs e) { if (Core.ApplicationData.Instance.ActiveDatabase != null && logList.SelectedItems.Count > 0) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { foreach (Core.Data.Log l in logList.SelectedItems) { Utils.DataAccess.DeleteLog(Core.ApplicationData.Instance.ActiveDatabase, l); } } await UpdateView(); } }
public async Task RemoveLogsOfSelectedUser() { if (Core.ApplicationData.Instance.ActiveDatabase != null && !string.IsNullOrEmpty(SelectedUser)) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { Import imp = new Import(); List <Core.Data.Log> lgs = await imp.GetLogsOfUser(Core.ApplicationData.Instance.ActiveDatabase, SelectedUser); foreach (var l in lgs) { Utils.DataAccess.DeleteLog(Core.ApplicationData.Instance.ActiveDatabase, l); } } } }
private void Button_Click_2(object sender, RoutedEventArgs e) { if (Core.ApplicationData.Instance.ActiveDatabase != null && SelectedCollection != null) { var gcList = from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection join b in GeocachesInCollections on a.Code equals b select a; using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { foreach (var gc in gcList) { gc.Selected = true; } } } }
public async Task ImportAll() { if (Core.ApplicationData.Instance.ActiveDatabase != null) { List <string> gcList = GetAllGCCodes(); if (gcList.Count > 0) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { LiveAPI.Import.ImportGeocaches(Core.ApplicationData.Instance.ActiveDatabase, gcList); }); } } } }
public async Task RunActionSequence(Bookmark af) { if (Core.ApplicationData.Instance.ActiveDatabase != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { List <string> gcCodes = Core.Settings.Default.LoadGCComBookmarkGeocaches(af); foreach (var gc in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection) { gc.Selected = gcCodes.Contains(gc.Code); } }); } } }
async private Task CenterLocationGeocache() { if (cacheList.SelectedItems.Count == 1) { Core.Data.Geocache gc = (cacheList.SelectedItems[0] as Core.Data.Geocache); if (gc != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(gc.Database)) { await Task.Run(() => { Utils.DataAccess.SetCenterLocation(gc.Lat, gc.Lon); }); } } } }
public async Task ImportNewBookmark(bool missingOnly) { if (newBookmarkValid) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { try { GCComBookmarks.Bookmark bm = new GCComBookmarks.Bookmark(); bm.Guid = getGuid().ToString(); Core.Settings.Default.GCComBookmarksID++; bm.ID = string.Format("gccombm{0}", Core.Settings.Default.GCComBookmarksID); bm.Name = BMName; Core.Settings.Default.AddGCComBookmark(bm); GCComBookmarks.Manager.Instance.Bookmarks.Add(bm); GCComBookmarks.Manager.Instance.AddBookmarkToMenu(bm); List <string> gcCodes = GCComBookmarks.Manager.Instance.UpdateBookmarkList(bm); if (missingOnly) { List <string> present = (from a in gcCodes join g in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection on a equals g.Code select a).ToList(); foreach (string s in present) { gcCodes.Remove(s); } } LiveAPI.Import.ImportGeocaches(Core.ApplicationData.Instance.ActiveDatabase, gcCodes); BMName = ""; BMUrl = ""; ActiveBookmark = bm; } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } } }
public async Task ImportMissing() { if (Core.ApplicationData.Instance.ActiveDatabase != null) { List <string> allList = GetAllGCCodes(); List <string> gcList = (from a in allList where Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection.GetGeocache(a) == null select a).ToList(); if (gcList.Count > 0) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { LiveAPI.Import.ImportGeocaches(Core.ApplicationData.Instance.ActiveDatabase, gcList); }); } } } }
protected override async Task ExecuteAsync(object parameter) { Core.ApplicationData.Instance.BeginActiviy(); Core.Storage.Database db = Core.ApplicationData.Instance.ActiveDatabase; if (db != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { foreach (Core.Data.Geocache gc in db.GeocacheCollection) { _geocacheAction(gc); } }); } }; Core.ApplicationData.Instance.EndActiviy(); }
public async Task ImportMyFindsAsync(Core.Storage.Database db) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { try { List<LiveAPI.LiveV6.GeocacheLog> logs = GetLogsOfUser(Core.ApplicationData.Instance.AccountInfos.GetAccountInfo("GC").AccountName, (from a in Core.ApplicationData.Instance.LogTypes where a.AsFound select a).ToList()); if (!_cancelled) { List<string> gcCodes = new List<string>(); foreach (var l in logs) { if (!l.IsArchived) { LiveAPI.Import.ImportLog(db, l); var gc = db.GeocacheCollection.GetGeocache(l.CacheCode); if (gc == null) { gcCodes.Add(l.CacheCode); } else { gc.Found = true; } } } if (gcCodes.Count > 0) { LiveAPI.Import.ImportGeocaches(db, gcCodes); } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } }
async private Task DeleteGeocache(bool ignore) { if (cacheList.SelectedItems.Count > 0) { List <Core.Data.Geocache> gcList = new List <Core.Data.Geocache>(); foreach (Core.Data.Geocache gc in cacheList.SelectedItems) { gcList.Add(gc); } Core.ApplicationData.Instance.ActiveGeocache = null; using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { int index = 0; DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("DeletingGeocaches", "DeletingGeocaches", gcList.Count, 0, true)) { foreach (var gc in gcList) { Utils.DataAccess.DeleteGeocache(gc); if (ignore) { Core.Settings.Default.AddIgnoreGeocacheCodes((new string[] { gc.Code }).ToList()); } index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("DeletingGeocaches", gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } }); } } }
public async Task ImportMyFindsAsync(Core.Storage.Database db) { using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { try { List <LiveAPI.LiveV6.GeocacheLog> logs = GetLogsOfUser(Core.ApplicationData.Instance.AccountInfos.GetAccountInfo("GC").AccountName, (from a in Core.ApplicationData.Instance.LogTypes where a.AsFound select a).ToList()); if (!_cancelled) { List <string> gcCodes = new List <string>(); foreach (var l in logs) { if (!l.IsArchived) { LiveAPI.Import.ImportLog(db, l); var gc = db.GeocacheCollection.GetGeocache(l.CacheCode); if (gc == null) { gcCodes.Add(l.CacheCode); } else { gc.Found = true; } } } if (gcCodes.Count > 0) { LiveAPI.Import.ImportGeocaches(db, gcCodes); } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } }
public async Task<List<LogInfo>> LogGeocachesAsync(List<LogInfo> logInfos) { List<LogInfo> result = new List<LogInfo>(); try { Utils.DataUpdater upd = null; if (Core.ApplicationData.Instance.ActiveDatabase != null) { upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase); } using (Utils.ProgressBlock prog = new Utils.ProgressBlock("LogGeocache", "Logging", logInfos.Count, 0, true)) { using (var api = new LiveAPI.GeocachingLiveV6()) { foreach (LogInfo li in logInfos) { int index = 0; List<LiveAPI.LiveV6.Trackable> dropTbs = null; List<string> retrieveTbs = (from a in li.TrackableRetrieve.Split(new char[]{' ',',','\t'}, StringSplitOptions.RemoveEmptyEntries) select a.ToUpper()).ToList(); //check if trackable dialog is needed if (li.TrackableDrop) { //fetch in background List<LiveAPI.LiveV6.Trackable> tbList = null; await Task.Run(() => { tbList = getOwnedTrackables(api); }); if (tbList==null || tbList.Count==0) { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, "NoTrackablesToDrop"); break; } Dialogs.SelectTrackablesWindow dlg = new Dialogs.SelectTrackablesWindow(tbList); if (dlg.ShowDialog() == true) { dropTbs = dlg.SelectedTrackables; if (dropTbs == null || dropTbs.Count == 0) { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, "NoTrackablesToDrop"); break; } } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, "NoTrackablesToDrop"); break; } } bool ok = false; await Task.Run(() => { if (index > 0 && dropTbs == null && retrieveTbs == null) { System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayCreateFieldNoteAndPublish); } ok = LogGeocache(api, li, dropTbs, retrieveTbs); }); if (ok) { result.Add(li); index++; if (!prog.Update("Logging", logInfos.Count, index)) { break; } } else { break; } } } } if (upd != null) { upd.Dispose(); upd = null; } } catch(Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } return result; }
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 ImportGCComments(Core.Storage.Database db, bool importMissing) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = ""; // Default file name dlg.DefaultExt = ".gcc"; // Default file extension dlg.Filter = "*.gcc|*.gcc|*.*|*.*"; // Filter files by extension // Show open file dialog box Nullable<bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { await Task.Run(() => { try { XmlDocument doc = new XmlDocument(); doc.Load(dlg.FileName); XmlNodeList nl = doc.SelectNodes("/gccomment/comment"); if (nl != null) { if (importMissing) { List<string> gcList = new List<string>(); foreach (XmlNode n in nl) { string gcCode = n.SelectSingleNode("gccode").InnerText; Core.Data.Geocache gc = db.GeocacheCollection.GetGeocache(gcCode); if (gc == null) { gcList.Add(gcCode); } } if (gcList.Count > 0) { Core.Settings.Default.filterIgnoredGeocacheCodes(gcList); } if (gcList.Count > 0) { LiveAPI.Import.ImportGeocaches(db, gcList); } } foreach (XmlNode n in nl) { string gcCode = n.SelectSingleNode("gccode").InnerText; Core.Data.Geocache gc = db.GeocacheCollection.GetGeocache(gcCode); if (gc != null) { gc.Notes = HttpUtility.HtmlEncode(n.SelectSingleNode("content").InnerText).Replace("\r", "").Replace("\n", "<br />"); } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } } }
public async Task RestoreDatabase(object database) { Core.Storage.Database db = database as Core.Storage.Database; if (db != null) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.InitialDirectory = System.IO.Path.GetDirectoryName(db.FileName); dlg.FileName = ""; // Default file name dlg.Filter = string.Format("GAPP SF backup ({0}.gsf.bak)|{0}.bak*", System.IO.Path.GetFileName(db.FileName)); // Filter files by extension // Show open file dialog box Nullable<bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { int pos = dlg.FileName.ToLower().LastIndexOf(".bak"); string orgFn = dlg.FileName.Substring(0, pos); //if database is open at the moment, close it. db = (from a in Core.ApplicationData.Instance.Databases where string.Compare(a.FileName, orgFn, true) == 0 select a).FirstOrDefault(); if (db != null) { if (Core.ApplicationData.Instance.ActiveDatabase == db) { Core.ApplicationData.Instance.ActiveDatabase = null; } Core.ApplicationData.Instance.Databases.Remove(db); } //now, delete index file string indexFile = string.Concat(orgFn, ".gsx"); if (System.IO.File.Exists(indexFile)) { System.IO.File.Delete(indexFile); } if (System.IO.File.Exists(orgFn)) { System.IO.File.Delete(orgFn); } System.IO.File.Move(dlg.FileName, orgFn); //load database bool success; db = new Core.Storage.Database(orgFn); using (Utils.DataUpdater upd = new Utils.DataUpdater(db, true)) { success = await db.InitializeAsync(); } if (success) { Core.ApplicationData.Instance.Databases.Add(db); Core.ApplicationData.Instance.ActiveDatabase = db; } else { db.Dispose(); } } } }
public async Task RunActionFow(ActionFlow af) { if (Core.ApplicationData.Instance.ActiveDatabase!=null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { runFlow(af); }); } } }
async public Task SelectGeocaches() { if (Core.ApplicationData.Instance.ActiveDatabase != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { List<Core.Data.Geocache> gcList; if (selectionContext.GeocacheSelectionContext == SelectionContext.Context.NewSelection) { gcList = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection; } else if (selectionContext.GeocacheSelectionContext == SelectionContext.Context.WithinSelection) { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList(); } else { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where !a.Selected select a).ToList(); } DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("Searching", "Searching", gcList.Count, 0, true)) { string[] foundByUsers = Core.Settings.Default.GeocacheFilterFoundBy == null ? new string[] { } : Core.Settings.Default.GeocacheFilterFoundBy.Split(','); for (int i = 0; i < foundByUsers.Length; i++) { foundByUsers[i] = foundByUsers[i].Trim(); } string[] notFoundByUsers = Core.Settings.Default.GeocacheFilterNotFoundBy == null ? new string[] { } : Core.Settings.Default.GeocacheFilterNotFoundBy.Split(','); for (int i = 0; i < notFoundByUsers.Length; i++) { notFoundByUsers[i] = notFoundByUsers[i].Trim(); } Core.Data.Location loc = null; double dist = 0; if (Core.Settings.Default.GeocacheFilterLocationExpanded) { loc = getLocation(); dist = Core.Settings.Default.GeocacheFilterLocationRadius * 1000; if (Core.Settings.Default.GeocacheFilterLocationKm== BooleanEnum.False) { dist /= 0.621371192237; } } List<int> cacheTypes = new List<int>(); if (Core.Settings.Default.GeocacheFilterGeocacheTypesExpanded) { if (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterGeocacheTypes)) { string[] parts = Core.Settings.Default.GeocacheFilterGeocacheTypes.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach(string s in parts) { cacheTypes.Add(int.Parse(s)); } } } List<int> cacheContainers = new List<int>(); if (Core.Settings.Default.GeocacheFilterGeocacheContainersExpanded) { if (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterGeocacheContainers)) { string[] parts = Core.Settings.Default.GeocacheFilterGeocacheContainers.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in parts) { cacheContainers.Add(int.Parse(s)); } } } List<int> cacheAttributes = new List<int>(); if (Core.Settings.Default.GeocacheFilterGeocacheAttributesExpanded) { if (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterGeocacheAttributes)) { string[] parts = Core.Settings.Default.GeocacheFilterGeocacheAttributes.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in parts) { cacheAttributes.Add(int.Parse(s)); } } } if (loc != null || !Core.Settings.Default.GeocacheFilterLocationExpanded) { //set selected within gcList int index = 0; foreach (var gc in gcList) { gc.Selected = ( (!Core.Settings.Default.GeocacheFilterStatusExpanded || ((Core.Settings.Default.GeocacheFilterGeocacheStatus == GeocacheStatus.Enabled && gc.Available) || (Core.Settings.Default.GeocacheFilterGeocacheStatus == GeocacheStatus.Disabled && !gc.Available && !gc.Archived) || (Core.Settings.Default.GeocacheFilterGeocacheStatus == GeocacheStatus.Archived && gc.Archived))) && (!Core.Settings.Default.GeocacheFilterOwnExpanded || ((Core.Settings.Default.GeocacheFilterOwn == BooleanEnum.True) == gc.IsOwn)) && (!Core.Settings.Default.GeocacheFilterFoundExpanded || ((Core.Settings.Default.GeocacheFilterFound == BooleanEnum.True) == gc.Found)) && (!Core.Settings.Default.GeocacheFilterFoundByExpanded || ((Core.Settings.Default.GeocacheFilterFoundByAll == BooleanEnum.True) && foundByAll(gc, foundByUsers)) || ((Core.Settings.Default.GeocacheFilterFoundByAll == BooleanEnum.False) && foundByAny(gc, foundByUsers))) && (!Core.Settings.Default.GeocacheFilterNotFoundByExpanded || ((Core.Settings.Default.GeocacheFilterNotFoundByAny == BooleanEnum.True) && !foundByAny(gc, foundByUsers)) || ((Core.Settings.Default.GeocacheFilterNotFoundByAny == BooleanEnum.False) && !foundByAll(gc, foundByUsers))) && (!Core.Settings.Default.GeocacheFilterLocationExpanded || (Utils.Calculus.CalculateDistance(gc, loc).EllipsoidalDistance<=dist)) && (!Core.Settings.Default.GeocacheFilterCountryStateExpanded || (string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterCountry) || (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterCountry) && string.Compare(gc.Country,Core.Settings.Default.GeocacheFilterCountry, true)==0)) && (string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterState) || (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterState) && string.Compare(gc.State, Core.Settings.Default.GeocacheFilterState, true) == 0))) && (!Core.Settings.Default.GeocacheFilterMunicipalityCityExpanded || (string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterMunicipality) || (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterMunicipality) && string.Compare(gc.Municipality, Core.Settings.Default.GeocacheFilterMunicipality, true) == 0)) && (string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterCity) || (!string.IsNullOrEmpty(Core.Settings.Default.GeocacheFilterCity) && string.Compare(gc.City, Core.Settings.Default.GeocacheFilterCity, true) == 0))) && (!Core.Settings.Default.GeocacheFilterGeocacheTypesExpanded || (cacheTypes.Contains(gc.GeocacheType.ID))) && (!Core.Settings.Default.GeocacheFilterGeocacheContainersExpanded || (cacheContainers.Contains(gc.Container.ID))) && (!Core.Settings.Default.GeocacheFilterFavExpanded || (gc.Favorites >= Core.Settings.Default.GeocacheFilterMinFav && gc.Favorites <= Core.Settings.Default.GeocacheFilterMaxFav)) && (!Core.Settings.Default.GeocacheFilterTerrainExpanded || ((gc.Terrain >= Core.Settings.Default.GeocacheFilterMinTerrain) && (gc.Terrain <= Core.Settings.Default.GeocacheFilterMaxTerrain))) && (!Core.Settings.Default.GeocacheFilterDifficultyExpanded || ((gc.Difficulty >= Core.Settings.Default.GeocacheFilterMinDifficulty) && (gc.Difficulty <= Core.Settings.Default.GeocacheFilterMaxDifficulty))) && (!Core.Settings.Default.GeocacheFilterHiddenDateExpanded || (gc.PublishedTime.Date >= Core.Settings.Default.GeocacheFilterMinHiddenDate.Date && gc.PublishedTime.Date <= Core.Settings.Default.GeocacheFilterMaxHiddenDate.Date)) && (!Core.Settings.Default.GeocacheFilterGeocacheAttributesExpanded || attrFilterPass(cacheAttributes, gc)) ); index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("Searching", gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } } }); } } }
public async Task AssignRegion() { if (Core.ApplicationData.Instance.ActiveDatabase!=null) { List<Core.Data.Geocache> gcList = new List<Core.Data.Geocache>(); using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { try { switch (SelectedAreaLevel) { case Core.Data.AreaType.Country: gcList = (from g in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where (!UnassignedOnly || string.IsNullOrEmpty(g.Country)) && (g.Selected || !SelectedOnly) select g).ToList(); break; case Core.Data.AreaType.State: gcList = (from g in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where (!UnassignedOnly || string.IsNullOrEmpty(g.State)) && (g.Selected || !SelectedOnly) select g).ToList(); break; case Core.Data.AreaType.Municipality: gcList = (from g in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where (!UnassignedOnly || string.IsNullOrEmpty(g.Municipality)) && (g.Selected || !SelectedOnly) select g).ToList(); break; case Core.Data.AreaType.City: gcList = (from g in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where (!UnassignedOnly || string.IsNullOrEmpty(g.City)) && (g.Selected || !SelectedOnly) select g).ToList(); break; } DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("AssignRegionsToGeocaches", "AssignRegionsToGeocaches", gcList.Count, 0, true)) { List<Core.Data.AreaInfo> areasFilter = Shapefiles.ShapeFilesManager.Instance.GetAreasByLevel(SelectedAreaLevel); if (areasFilter != null && areasFilter.Count > 0) { int index = 0; foreach (var gc in gcList) { List<Core.Data.AreaInfo> areas = Shapefiles.ShapeFilesManager.Instance.GetAreasOfLocation(new Core.Data.Location(gc.Lat, gc.Lon), areasFilter); if (areas != null && areas.Count > 0) { Core.Data.AreaInfo ai = areas[0]; if (Prefix.Length > 0) { ai = (from g in areas where g.Name.StartsWith(Prefix) select g).FirstOrDefault(); } if (ai != null) { switch (SelectedAreaLevel) { case Core.Data.AreaType.Country: gc.Country = ai.Name; break; case Core.Data.AreaType.State: gc.State = ai.Name; break; case Core.Data.AreaType.Municipality: gc.Municipality = ai.Name; break; case Core.Data.AreaType.City: gc.City = ai.Name; break; } } } index++; if (DateTime.Now>=nextUpdate) { if (!prog.Update("AssignRegionsToGeocaches", gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } } } catch(Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } } }
public async Task RunActionSequence(Bookmark af) { if (Core.ApplicationData.Instance.ActiveDatabase != null) { using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { List<string> gcCodes = Core.Settings.Default.LoadGCComBookmarkGeocaches(af); foreach(var gc in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection) { gc.Selected = gcCodes.Contains(gc.Code); } }); } } }
async private Task DeleteGeocache() { if (cacheList.SelectedItems.Count > 0) { List<Core.Data.Geocache> gcList = new List<Core.Data.Geocache>(); foreach (Core.Data.Geocache gc in cacheList.SelectedItems) { gcList.Add(gc); } Core.ApplicationData.Instance.ActiveGeocache = null; using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { int index = 0; DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("DeletingGeocaches", "DeletingGeocaches", gcList.Count, 0, true)) { foreach (var gc in gcList) { Utils.DataAccess.DeleteGeocache(gc); index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("DeletingGeocaches", gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } }); } } }
public async Task DownloadSelectedPQ() { List<LiveAPI.LiveV6.PQData> pqs = new List<LiveAPI.LiveV6.PQData>(); foreach (PQData p in listItems.SelectedItems) { pqs.Add(p.LiveAPIData); } using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(new Action(() => { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock("DownloadingPQ", "DownloadingPQ", pqs.Count, 0, true)) { int index = 0; try { using (var api = new LiveAPI.GeocachingLiveV6()) { Import imp = new Import(); foreach (LiveAPI.LiveV6.PQData pq in pqs) { if (progress.Update(pq.Name, pqs.Count, index)) { LiveAPI.LiveV6.GetPocketQueryZippedFileResponse resp = api.Client.GetPocketQueryZippedFile(api.Token, pq.GUID); if (resp.Status.StatusCode == 0) { using (System.IO.TemporaryFile tf = new System.IO.TemporaryFile(true)) { System.IO.File.WriteAllBytes(tf.Path, Convert.FromBase64String(resp.ZippedFile)); imp.ImportFile(tf.Path); updateProcessedPq(pq.GUID); } } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); break; } index++; } else { break; } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } })); } Close(); }
public async Task SelectWithinRadiusAsync() { try { Core.Data.Location center = null; double radius = 0; var sc = selectionContext.GeocacheSelectionContext; 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 { List <Core.Data.Geocache> gcList; if (sc == GAPPSF.UIControls.SelectionContext.Context.NewSelection) { gcList = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection; } else if (sc == GAPPSF.UIControls.SelectionContext.Context.WithinSelection) { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList(); } else { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where !a.Selected select a).ToList(); } DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("Searching", "Searching", gcList.Count, 0, true)) { int index = 0; foreach (var gc in gcList) { gc.Selected = Utils.Calculus.CalculateDistance(gc, center).EllipsoidalDistance <= radius; index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("Searching", gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } } 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; var sc = selectionContext.GeocacheSelectionContext; 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 { List<Core.Data.Geocache> gcList; if (sc == GAPPSF.UIControls.SelectionContext.Context.NewSelection) { gcList = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection; } else if (sc == GAPPSF.UIControls.SelectionContext.Context.WithinSelection) { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList(); } else { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where !a.Selected select a).ToList(); } DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("Searching", "Searching", gcList.Count, 0, true)) { int index = 0; foreach (var gc in gcList) { gc.Selected = (gc.Lat >= minLat && gc.Lat <= maxLat && gc.Lon >= minLon && gc.Lon <= maxLon); index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("Searching", gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } } 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; var sc = selectionContext.GeocacheSelectionContext; 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 { List <Core.Data.Geocache> gcList; if (sc == GAPPSF.UIControls.SelectionContext.Context.NewSelection) { gcList = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection; } else if (sc == GAPPSF.UIControls.SelectionContext.Context.WithinSelection) { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList(); } else { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where !a.Selected select a).ToList(); } DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("Searching", "Searching", gcList.Count, 0, true)) { int index = 0; foreach (var gc in gcList) { gc.Selected = (gc.Lat >= minLat && gc.Lat <= maxLat && gc.Lon >= minLon && gc.Lon <= maxLon); index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("Searching", gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } })); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }
public async Task SelectWithinRadiusAsync() { try { Core.Data.Location center = null; double radius = 0; var sc = selectionContext.GeocacheSelectionContext; 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 { List<Core.Data.Geocache> gcList; if (sc == GAPPSF.UIControls.SelectionContext.Context.NewSelection) { gcList = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection; } else if (sc == GAPPSF.UIControls.SelectionContext.Context.WithinSelection) { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList(); } else { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where !a.Selected select a).ToList(); } DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("Searching", "Searching", gcList.Count, 0, true)) { int index = 0; foreach (var gc in gcList) { gc.Selected = Utils.Calculus.CalculateDistance(gc, center).EllipsoidalDistance <= radius; index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("Searching", gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } })); } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }
public async Task AssignRegion() { if (Core.ApplicationData.Instance.ActiveDatabase != null) { List<Core.Data.Geocache> gcList = new List<Core.Data.Geocache>(); if (selectionContext.GeocacheSelectionContext == UIControls.SelectionContext.Context.NewSelection) { gcList = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection; } else if (selectionContext.GeocacheSelectionContext == UIControls.SelectionContext.Context.WithinSelection) { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Selected select a).ToList(); } else { gcList = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where !a.Selected select a).ToList(); } using (Utils.DataUpdater upd = new Utils.DataUpdater(Core.ApplicationData.Instance.ActiveDatabase)) { await Task.Run(() => { try { //select the available areas List<Core.Data.AreaInfo> areas; if (string.IsNullOrEmpty(SelectedArea)) { areas = Shapefiles.ShapeFilesManager.Instance.GetAreasByLevel(SelectedAreaLevel); } else { areas = Shapefiles.ShapeFilesManager.Instance.GetAreasByName(SelectedArea, SelectedAreaLevel); } if (areas != null && areas.Count > 0) { if (!string.IsNullOrEmpty(Prefix)) { areas = (from a in areas where a.Name.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase) select a).ToList(); } } if (areas != null && areas.Count > 0) { DateTime nextUpdate = DateTime.Now.AddSeconds(1); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("Searching", "Searching", gcList.Count, 0, true)) { int index = 0; foreach (var gc in gcList) { if (InEnvelope) { gc.Selected = Shapefiles.ShapeFilesManager.Instance.GetEnvelopAreasOfLocation(new Core.Data.Location(gc.Lat, gc.Lon), areas).Count > 0; } else { gc.Selected = Shapefiles.ShapeFilesManager.Instance.GetAreasOfLocation(new Core.Data.Location(gc.Lat, gc.Lon), areas).Count > 0; } index++; if (DateTime.Now >= nextUpdate) { if (!prog.Update("Searching", gcList.Count, index)) { break; } nextUpdate = DateTime.Now.AddSeconds(1); } } } } else { foreach (var gc in gcList) { gc.Selected = false; } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); } } }