public bool LogGeocache(LiveAPI.GeocachingLiveV6 api, LogInfo logInfo, List<LiveAPI.LiveV6.Trackable> dropTbs, List<string> retrieveTbs) { bool result = false; try { var req = new LiveAPI.LiveV6.CreateFieldNoteAndPublishRequest(); req.AccessToken = api.Token; req.CacheCode = logInfo.GeocacheCode; req.EncryptLogText = false; req.FavoriteThisCache = logInfo.AddToFavorites; req.Note = logInfo.LogText; req.PromoteToLog = true; req.WptLogTypeId = logInfo.LogType.ID; req.UTCDateLogged = logInfo.VisitDate.Date.AddHours(12).ToUniversalTime(); var resp = api.Client.CreateFieldNoteAndPublish(req); if (resp.Status.StatusCode == 0) { bool error = false; if (Core.ApplicationData.Instance.ActiveDatabase!=null) { var gc = Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection.GetGeocache(logInfo.GeocacheCode); if (gc != null) { if (logInfo.LogType.AsFound) { gc.Found = true; } } LiveAPI.Import.ImportLog(Core.ApplicationData.Instance.ActiveDatabase, resp.Log); if (gc!=null) { gc.ResetCachedLogData(); } } //log trackables (14=drop off, 13=retrieve from cache, 75=visited) if (dropTbs != null && dropTbs.Count > 0) { var reqT = new LiveAPI.LiveV6.CreateTrackableLogRequest(); reqT.AccessToken = api.Token; reqT.LogType = 14; reqT.UTCDateLogged = logInfo.VisitDate.Date.AddHours(12).ToUniversalTime(); foreach (var tb in dropTbs) { reqT.TrackingNumber = tb.TrackingCode; reqT.CacheCode = logInfo.GeocacheCode; var resp2 = api.Client.CreateTrackableLog(reqT); if (resp2.Status.StatusCode != 0) { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp2.Status.StatusMessage); error = true; //break; } } } if (retrieveTbs != null && retrieveTbs.Count > 0) { var reqT = new LiveAPI.LiveV6.CreateTrackableLogRequest(); reqT.AccessToken = api.Token; reqT.LogType = 13; reqT.UTCDateLogged = logInfo.VisitDate.Date.AddHours(12).ToUniversalTime(); foreach (var tb in retrieveTbs) { reqT.TrackingNumber = tb; reqT.CacheCode = logInfo.GeocacheCode; var resp2 = api.Client.CreateTrackableLog(reqT); if (resp2.Status.StatusCode != 0) { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp2.Status.StatusMessage); error = true; //break; } } } //add log images foreach (var li in logInfo.Images) { var uplReq = new LiveAPI.LiveV6.UploadImageToGeocacheLogRequest(); uplReq.AccessToken = api.Token; uplReq.LogGuid = resp.Log.Guid; uplReq.ImageData = new LiveAPI.LiveV6.UploadImageData(); uplReq.ImageData.FileCaption = li.Caption; uplReq.ImageData.FileDescription = li.Description; uplReq.ImageData.FileName = li.Uri; //todo: scale image to comply to limits uplReq.ImageData.base64ImageData = System.Convert.ToBase64String(System.IO.File.ReadAllBytes(li.Uri)); var resp2 = api.Client.UploadImageToGeocacheLog(uplReq); if (resp2.Status.StatusCode != 0) { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp2.Status.StatusMessage); error = true; //break; } } if (logInfo.AddToFavorites) { Favorites.Manager.Instance.AddFavoritedGeocache(logInfo.GeocacheCode); } result = true; } else { Core.ApplicationData.Instance.Logger.AddLog(this, Core.Logger.Level.Error, resp.Status.StatusMessage); } } catch(Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } return result; }
public PQData(LiveAPI.LiveV6.PQData _liveAPIData) { LiveAPIData = _liveAPIData; }
private TrackableItem GetTrackableItemFromLiveAPI(LiveAPI.LiveV6.Trackable t) { TrackableItem trk = new TrackableItem(); trk.Code = t.Code; trk.AllowedToBeCollected = t.AllowedToBeCollected; trk.Archived = t.Archived; trk.BugTypeID = t.BugTypeID; trk.CurrentGeocacheCode = t.CurrentGeocacheCode; trk.CurrentGoal = t.CurrentGoal; trk.DateCreated = t.DateCreated; trk.Description = t.Description; trk.IconUrl = t.IconUrl; trk.IconData = Core.Settings.Default.GetTrackableIconData(trk.IconUrl); if (trk.IconData==null && !string.IsNullOrEmpty(t.IconUrl)) { try { using (System.Net.WebClient wc = new System.Net.WebClient()) { trk.IconData = wc.DownloadData(t.IconUrl); } } catch(Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } } trk.Id = t.Id; trk.InCollection = t.InCollection; trk.Name = t.Name; trk.TBTypeName = t.TBTypeName; trk.Url = t.Url; trk.WptTypeID = t.WptTypeID; if (t.OriginalOwner != null) { trk.Owner = t.OriginalOwner.UserName; } else { trk.Owner = ""; } return trk; }
private List<LiveAPI.LiveV6.Trackable> getOwnedTrackables(LiveAPI.GeocachingLiveV6 api) { List<LiveAPI.LiveV6.Trackable> result = new List<LiveAPI.LiveV6.Trackable>(); try { var req = new LiveAPI.LiveV6.GetTrackablesByUserRequest(); req.AccessToken = api.Token; req.MaxPerPage = 10; req.StartIndex = 0; req.TrackableLogsCount = 0; var resp = api.Client.GetUsersTrackables(req); while (resp.Status.StatusCode == 0) { if (resp.Trackables != null) { foreach (LiveAPI.LiveV6.Trackable tb in resp.Trackables) { result.Add(tb); } if (resp.Trackables.Count() < req.MaxPerPage) { break; } else { req.StartIndex += req.MaxPerPage; resp = api.Client.GetUsersTrackables(req); } } else { break; } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } return result; }
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; }