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 <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); }