private void newDialog_DialogClosed(object sender, EventArgs e) { inputDialog.DialogClosed -= newDialog_DialogClosed; if (inputDialog.DialogResult) { if (!string.IsNullOrEmpty(inputDialog.InputText)) { string s = inputDialog.InputText.Trim(); if (s.Length > 0) { //add groep int maxId = 0; if (AvailableTrackableGroups.Count > 0) { maxId = AvailableTrackableGroups.Max(x => x.ID); } maxId++; TrackableGroup tg = new TrackableGroup(); tg.ID = maxId; tg.Name = s; try { Core.Settings.Default.AddTrackableGroup(tg); AvailableTrackableGroups.Add(tg); SelectedTrackableGroup = tg; } catch (Exception ex) { Core.ApplicationData.Instance.Logger.AddLog(this, ex); } } } } }
public void AddOwnTrackables(TrackableGroup grp) { bool canceled = false; using (Utils.ProgressBlock progr = new Utils.ProgressBlock("GetTrackableData", "GetTrackableData", 1, 0, true)) using (var api = new LiveAPI.GeocachingLiveV6()) { List <string> trkCodes = new List <string>(); var req = new LiveAPI.LiveV6.GetTrackablesByOwnerRequest(); req.AccessToken = api.Token; req.TrackableLogsCount = 0; req.StartIndex = 0; req.MaxPerPage = Core.Settings.Default.LiveAPIGetOwnedTrackablesBatchSize; int total = 0; while (true) { var resp = api.Client.GetOwnedTrackables(req); if (resp.Status.StatusCode == 0) { if (resp.Trackables != null) { foreach (var t in resp.Trackables) { trkCodes.Add(t.Code); Core.Settings.Default.AddUpdateTrackable(grp, GetTrackableItemFromLiveAPI(t)); total++; } if (!progr.Update("GetTrackableData", total, 2 * total)) { canceled = true; break; } } if (resp.Trackables.Count() < req.MaxPerPage) { break; } else { req.StartIndex = total; System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetOwnedTrackables); } } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); break; } } if (!canceled) { progr.Update("GetTrackableData", total, total); AddUpdateTrackables(grp, trkCodes); } } }
public void AddOwnTrackables(TrackableGroup grp) { bool canceled = false; using (Utils.ProgressBlock progr = new Utils.ProgressBlock("GetTrackableData", "GetTrackableData", 1, 0, true)) using (var api = new LiveAPI.GeocachingLiveV6()) { List<string> trkCodes = new List<string>(); var req = new LiveAPI.LiveV6.GetTrackablesByOwnerRequest(); req.AccessToken = api.Token; req.TrackableLogsCount = 0; req.StartIndex = 0; req.MaxPerPage = Core.Settings.Default.LiveAPIGetOwnedTrackablesBatchSize; int total = 0; while (true) { var resp = api.Client.GetOwnedTrackables(req); if (resp.Status.StatusCode == 0) { if (resp.Trackables != null) { foreach (var t in resp.Trackables) { trkCodes.Add(t.Code); Core.Settings.Default.AddUpdateTrackable(grp, GetTrackableItemFromLiveAPI(t)); total++; } if (!progr.Update("GetTrackableData", total, 2 * total)) { canceled = true; break; } } if (resp.Trackables.Count() < req.MaxPerPage) { break; } else { req.StartIndex = total; System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetOwnedTrackables); } } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); break; } } if (!canceled) { progr.Update("GetTrackableData", total, total); AddUpdateTrackables(grp, trkCodes); } } }
public async Task AddUpdateTrackablesAsync(TrackableGroup grp, List <string> trkList) { await Task.Run(() => { try { AddUpdateTrackables(grp, trkList); } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); }
public async Task AddOwnTrackablesAsync(TrackableGroup grp) { await Task.Run(() => { try { AddOwnTrackables(grp); } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); }
public async Task AddUpdateTrackablesAsync(TrackableGroup grp, List<string> trkList) { await Task.Run(() => { try { AddUpdateTrackables(grp, trkList); } catch(Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } }); }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (SelectedTrackableGroup != null) { try { TrackableGroup tg = SelectedTrackableGroup; Core.Settings.Default.DeleteTrackableGroup(tg); AvailableTrackableGroups.Remove(tg); } catch (Exception ex) { Core.ApplicationData.Instance.Logger.AddLog(this, ex); } } }
public void AddUpdateTrackables(TrackableGroup grp, List <string> trkList) { using (Utils.ProgressBlock progr = new Utils.ProgressBlock("GetTrackableData", "GetTrackableData", trkList.Count, 0, true)) using (var api = new LiveAPI.GeocachingLiveV6()) { int index = 0; while (index < trkList.Count && AddUpdateTrackable(api, grp, trkList[index])) { index++; if (!progr.Update("GetTrackableData", trkList.Count, index)) { break; } else if (index < trkList.Count) { System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetTrackablesByTBCode); } } } }
private bool AddUpdateTrackable(LiveAPI.GeocachingLiveV6 api, TrackableGroup grp, string trkCode) { bool result = true; if (trkCode.ToUpper().StartsWith("TB")) { try { var resp = api.Client.GetTrackablesByTBCode(api.Token, trkCode.ToUpper(), 0); if (resp.Status.StatusCode == 0) { if (resp.Trackables != null) { foreach (var t in resp.Trackables) { TrackableItem trk = GetTrackableItemFromLiveAPI(t); Core.Settings.Default.AddUpdateTrackable(grp, trk); var resp2 = api.Client.GetTrackableTravelList(api.Token, trk.Code); if (resp2.Status.StatusCode == 0) { if (resp2.TrackableTravels != null) { List <TravelItem> travelList = new List <TravelItem>(); foreach (var tt in resp2.TrackableTravels) { if (tt.Latitude != null && tt.Longitude != null) { TravelItem ti = new TravelItem(); ti.TrackableCode = trk.Code; if (tt.CacheID != null) { ti.GeocacheCode = Utils.Conversion.GetCacheCodeFromCacheID((int)tt.CacheID); } else { ti.GeocacheCode = ""; } ti.DateLogged = tt.DateLogged; ti.Lat = (double)tt.Latitude; ti.Lon = (double)tt.Longitude; travelList.Add(ti); } } Core.Settings.Default.UpdateTrackableTravels(trk, travelList); } //get all logs List <LogItem> logs = new List <LogItem>(); int maxPageSize = Core.Settings.Default.LiveAPIGetTrackableLogsByTBCodeBatchSize; while (true) { var resp3 = api.Client.GetTrackableLogsByTBCode(api.Token, trk.Code, logs.Count, maxPageSize); if (resp3.Status.StatusCode == 0) { if (resp3.TrackableLogs != null) { foreach (var tl in resp3.TrackableLogs) { LogItem li = new LogItem(); li.TrackableCode = trk.Code; if (tl.CacheID != null) { li.GeocacheCode = Utils.Conversion.GetCacheCodeFromCacheID((int)tl.CacheID); } else { li.GeocacheCode = ""; } li.LogCode = tl.Code; li.ID = tl.ID; li.IsArchived = tl.IsArchived; li.LoggedBy = tl.LoggedBy == null ? "" : tl.LoggedBy.UserName; li.LogGuid = tl.LogGuid.ToString(); li.LogIsEncoded = tl.LogIsEncoded; li.LogText = tl.LogText; li.WptLogTypeId = tl.LogType == null ? -1 : (int)tl.LogType.WptLogTypeId; li.Url = tl.Url; li.UTCCreateDate = tl.UTCCreateDate; li.VisitDate = tl.VisitDate; logs.Add(li); } if (resp3.TrackableLogs.Count() < maxPageSize) { break; } System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetTrackableLogsByTBCode); } else { break; } } else { logs = null; result = false; Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp3.Status.StatusMessage); break; } } if (logs != null) { Core.Settings.Default.UpdateTrackableLogs(trk, logs); } } else { result = false; Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp2.Status.StatusMessage); } } } } else { result = false; Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); } } catch (Exception e) { result = false; Core.ApplicationData.Instance.Logger.AddLog(this, e); } } return(result); }
public void AddUpdateTrackables(TrackableGroup grp, List<string> trkList) { using (Utils.ProgressBlock progr = new Utils.ProgressBlock("GetTrackableData", "GetTrackableData", trkList.Count, 0, true)) using (var api = new LiveAPI.GeocachingLiveV6()) { int index = 0; while (index < trkList.Count && AddUpdateTrackable(api, grp, trkList[index])) { index++; if (!progr.Update("GetTrackableData", trkList.Count, index)) { break; } else if (index < trkList.Count) { System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetTrackablesByTBCode); } } } }
private bool AddUpdateTrackable(LiveAPI.GeocachingLiveV6 api, TrackableGroup grp, string trkCode) { bool result = true; if (trkCode.ToUpper().StartsWith("TB")) { try { var resp = api.Client.GetTrackablesByTBCode(api.Token, trkCode.ToUpper(), 0); if (resp.Status.StatusCode == 0) { if (resp.Trackables != null) { foreach (var t in resp.Trackables) { TrackableItem trk = GetTrackableItemFromLiveAPI(t); Core.Settings.Default.AddUpdateTrackable(grp, trk); var resp2 = api.Client.GetTrackableTravelList(api.Token, trk.Code); if (resp2.Status.StatusCode == 0) { if (resp2.TrackableTravels != null) { List<TravelItem> travelList = new List<TravelItem>(); foreach (var tt in resp2.TrackableTravels) { if (tt.Latitude != null && tt.Longitude != null) { TravelItem ti = new TravelItem(); ti.TrackableCode = trk.Code; if (tt.CacheID != null) { ti.GeocacheCode = Utils.Conversion.GetCacheCodeFromCacheID((int)tt.CacheID); } else { ti.GeocacheCode = ""; } ti.DateLogged = tt.DateLogged; ti.Lat = (double)tt.Latitude; ti.Lon = (double)tt.Longitude; travelList.Add(ti); } } Core.Settings.Default.UpdateTrackableTravels(trk, travelList); } //get all logs List<LogItem> logs = new List<LogItem>(); int maxPageSize = Core.Settings.Default.LiveAPIGetTrackableLogsByTBCodeBatchSize; while (true) { var resp3 = api.Client.GetTrackableLogsByTBCode(api.Token, trk.Code, logs.Count, maxPageSize); if (resp3.Status.StatusCode == 0) { if (resp3.TrackableLogs != null) { foreach (var tl in resp3.TrackableLogs) { LogItem li = new LogItem(); li.TrackableCode = trk.Code; if (tl.CacheID != null) { li.GeocacheCode = Utils.Conversion.GetCacheCodeFromCacheID((int)tl.CacheID); } else { li.GeocacheCode = ""; } li.LogCode = tl.Code; li.ID = tl.ID; li.IsArchived = tl.IsArchived; li.LoggedBy = tl.LoggedBy == null ? "" : tl.LoggedBy.UserName; li.LogGuid = tl.LogGuid.ToString(); li.LogIsEncoded = tl.LogIsEncoded; li.LogText = tl.LogText; li.WptLogTypeId = tl.LogType == null ? -1 : (int)tl.LogType.WptLogTypeId; li.Url = tl.Url; li.UTCCreateDate = tl.UTCCreateDate; li.VisitDate = tl.VisitDate; logs.Add(li); } if (resp3.TrackableLogs.Count() < maxPageSize) { break; } System.Threading.Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetTrackableLogsByTBCode); } else { break; } } else { logs = null; result = false; Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp3.Status.StatusMessage); break; } } if (logs!=null) { Core.Settings.Default.UpdateTrackableLogs(trk, logs); } } else { result = false; Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp2.Status.StatusMessage); } } } } else { result = false; Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); } } catch(Exception e) { result = false; Core.ApplicationData.Instance.Logger.AddLog(this, e); } } return result; }