public static List<Core.Data.UserWaypoint> ImportUserWaypoints(Core.Storage.Database db, LiveV6.UserWaypoint[] wps, string GeocacheCode) { List<Core.Data.UserWaypoint> result = new List<Core.Data.UserWaypoint>(); List<Core.Data.UserWaypoint> curUwps = Utils.DataAccess.GetUserWaypointsFromGeocache(db, GeocacheCode); if (wps != null) { foreach (var lg in wps) { Core.Data.UserWaypoint g = ImportUserWaypoint(db, lg); if (g != null) { result.Add(g); if (curUwps.Contains(g)) { curUwps.Remove(g); } } } } foreach (var g in curUwps) { g.DeleteRecord(); db.UserWaypointCollection.Remove(g); } return result; }
public static List<Core.Data.Waypoint> ImportWaypoints(Core.Storage.Database db, LiveV6.AdditionalWaypoint[] wps) { List<Core.Data.Waypoint> result = new List<Core.Data.Waypoint>(); if (wps != null) { foreach (var lg in wps) { Core.Data.Waypoint g = ImportWaypoint(db, lg); if (g != null) { result.Add(g); } } } return result; }
public static Core.Data.Waypoint ImportWaypoint(Core.Storage.Database db, LiveV6.AdditionalWaypoint wp) { Core.Data.Waypoint result = null; if (wp != null) { result = db.WaypointCollection.GetWaypoint(wp.Code); Core.Data.IWaypointData wpd; if (result == null) { wpd = new Core.Data.WaypointData(); wpd.Code = wp.Code; wpd.ID = wp.Code; } else { wpd = result; } wpd.DataFromDate = DateTime.Now; wpd.WPType = Utils.DataAccess.GetWaypointType(wp.WptTypeID); wpd.Comment = wp.Comment; wpd.Description = wp.Description; wpd.GeocacheCode = wp.GeocacheCode; wpd.Lat = wp.Latitude; wpd.Lon = wp.Longitude; wpd.Name = wp.Name; wpd.Time = wp.UTCEnteredDate; wpd.Url = wp.Url; wpd.UrlName = wp.UrlName; if (wpd is Core.Data.WaypointData) { if (Utils.DataAccess.AddWaypoint(db, wpd as Core.Data.WaypointData)) { result = db.WaypointCollection.GetWaypoint(wp.Code); } } } return result; }
public static List<Core.Data.LogImage> ImportLogImages(Core.Storage.Database db, LiveV6.ImageData[] imgs, string LogId) { List<Core.Data.LogImage> result = new List<Core.Data.LogImage>(); if (imgs != null) { foreach (var lg in imgs) { Core.Data.LogImage g = ImportLogImage(db, lg, LogId); if (g != null) { result.Add(g); } } } return result; }
public static Core.Data.LogImage ImportLogImage(Core.Storage.Database db, LiveV6.ImageData img, string LogId) { Core.Data.LogImage result = null; if (img != null) { result = db.LogImageCollection.GetLogImage(img.Url); Core.Data.ILogImageData lgiData; if (result == null) { lgiData = new Core.Data.LogImageData(); lgiData.ID = img.Url; lgiData.LogId = LogId; lgiData.Url = img.Url; } else { lgiData = result; } lgiData.DataFromDate = DateTime.Now; lgiData.Name = img.Name; if (lgiData is Core.Data.LogImageData) { if (Utils.DataAccess.AddLogImage(db, lgiData as Core.Data.LogImageData)) { result = db.LogImageCollection.GetLogImage(img.Url); } } } return result; }
public static Core.Data.GeocacheImage ImportGeocacheImage(Core.Storage.Database db, LiveV6.ImageData img, string GeocacheCode) { Core.Data.GeocacheImage result = null; if (img != null) { result = db.GeocacheImageCollection.GetGeocacheImage(img.ImageGuid.ToString()); Core.Data.IGeocacheImageData wpd; if (result == null) { wpd = new Core.Data.GeocacheImageData(); wpd.ID = img.ImageGuid.ToString(); } else { wpd = result; } wpd.DataFromDate = DateTime.Now; wpd.GeocacheCode = GeocacheCode; wpd.Name = img.Name; wpd.Url = img.Url; wpd.ThumbUrl = img.ThumbUrl; wpd.MobileUrl = img.MobileUrl; wpd.Description = img.Description; if (wpd is Core.Data.GeocacheImageData) { if (Utils.DataAccess.AddGeocacheImage(db, wpd as Core.Data.GeocacheImageData)) { result = db.GeocacheImageCollection.GetGeocacheImage(img.ImageGuid.ToString()); } } } return result; }
public static Framework.Data.Waypoint Waypoint(Framework.Interfaces.ICore core, LiveV6.AdditionalWaypoint wp) { Framework.Data.Waypoint result = null; if (wp != null) { Framework.Data.Waypoint tmp = DataAccess.GetWaypoint(core.Waypoints, wp.Code); result = new Framework.Data.Waypoint(); if (tmp != null) { result.UpdateFrom(tmp); } result.Code = wp.Code; result.DataFromDate = DateTime.Now; result.WPType = DataAccess.GetWaypointType(core.WaypointTypes, wp.WptTypeID); result.Comment = wp.Comment; result.Description = wp.Description; result.GeocacheCode = wp.GeocacheCode; result.ID = wp.Code; result.Lat = wp.Latitude; result.Lon = wp.Longitude; result.Name = wp.Name; result.Time = wp.UTCEnteredDate; result.Url = wp.Url; result.UrlName = wp.UrlName; } return result; }
public static List<Core.Data.Geocache> ImportGeocaches(Core.Storage.Database db, LiveV6.Geocache[] gcList) { List<Core.Data.Geocache> result = new List<Core.Data.Geocache>(); if (gcList != null) { foreach (var gc in gcList) { Core.Data.Geocache g = ImportGeocache(db, gc); if (g!=null) { result.Add(g); } } } return result; }
public static Core.Data.Geocache ImportGeocache(Core.Storage.Database db, LiveV6.Geocache gc) { Core.Data.Geocache result = null; if (gc != null) { result = db.GeocacheCollection.GetGeocache(gc.Code); Core.Data.IGeocacheData gcData; if (result == null) { gcData = new Core.Data.GeocacheData(); gcData.Code = gc.Code; } else { gcData = result; } gcData.Archived = gc.Archived ?? false; gcData.Available = gc.Available ?? true; if (result == null || !result.Locked) { gcData.Container = Utils.DataAccess.GetGeocacheContainer((int)gc.ContainerType.ContainerTypeId); if (gc.Attributes != null) { List<int> attr = new List<int>(); foreach (LiveV6.Attribute a in gc.Attributes) { attr.Add(a.IsOn ? a.AttributeTypeID : -1 * a.AttributeTypeID); } gcData.AttributeIds = attr; } if (gc.Latitude != null) gcData.Lat = (double)gc.Latitude; if (gc.Longitude != null) gcData.Lon = (double)gc.Longitude; if (gc.Country != null) gcData.Country = gc.Country; gcData.DataFromDate = DateTime.Now; gcData.Difficulty = gc.Difficulty; gcData.Terrain = gc.Terrain; gcData.Name = gc.Name; if (gc.FavoritePoints != null) { gcData.Favorites = (int)gc.FavoritePoints; } gcData.GeocacheType = Utils.DataAccess.GetGeocacheType((int)gc.CacheType.GeocacheTypeId); if (gc.LongDescription != null) { gcData.LongDescription = gc.LongDescription; gcData.LongDescriptionInHtml = gc.LongDescriptionIsHtml; } if (gc.EncodedHints != null) { gcData.EncodedHints = gc.EncodedHints; } gcData.MemberOnly = gc.IsPremium ?? false; gcData.Owner = gc.Owner.UserName; if (gc.Owner.Id != null) { gcData.OwnerId = gc.Owner.Id.ToString(); } gcData.PlacedBy = gc.PlacedBy; gcData.PublishedTime = gc.UTCPlaceDate; if (gcData.ShortDescription != null) { gcData.ShortDescription = gc.ShortDescription; gcData.ShortDescriptionInHtml = gc.ShortDescriptionIsHtml; } if (gc.State == "None") { gcData.State = ""; } else { gcData.State = gc.State; } gcData.PersonalNote = gc.GeocacheNote; if (gc.HasbeenFoundbyUser != null) { gcData.Found = (bool)gc.HasbeenFoundbyUser; } gcData.Url = gc.Url; gcData.PersonalNote = gc.GeocacheNote ?? ""; if (gcData is Core.Data.GeocacheData) { if (Utils.DataAccess.AddGeocache(db, gcData as Core.Data.GeocacheData)) { result = db.GeocacheCollection.GetGeocache(gcData.Code); } } if (result != null) { Utils.Calculus.SetDistanceAndAngleGeocacheFromLocation(result, Core.ApplicationData.Instance.CenterLocation); ImportLogs(db, gc.GeocacheLogs); ImportWaypoints(db, gc.AdditionalWaypoints); ImportUserWaypoints(db, gc.UserWaypoints, gc.Code); ImportGeocacheImages(db, gc.Images, gc.Code); } } } return result; }
public static Framework.Data.Geocache Geocache(Framework.Interfaces.ICore core, LiveV6.Geocache gc) { Framework.Data.Geocache result = null; if (gc != null) { Framework.Data.Geocache tmp = DataAccess.GetGeocache(core.Geocaches, gc.Code); result = new Framework.Data.Geocache(); if (tmp != null) { result.UpdateFrom(tmp, null); } result.Code = gc.Code; result.ID = gc.ID.ToString(); result.Archived = gc.Archived ?? false; result.Available = gc.Available ?? true; result.Container = DataAccess.GetGeocacheContainer(core.GeocacheContainers, (int)gc.ContainerType.ContainerTypeId); if (gc.Attributes!=null) { List<int> attr = new List<int>(); foreach (LiveV6.Attribute a in gc.Attributes) { attr.Add(a.IsOn ? a.AttributeTypeID : -1 * a.AttributeTypeID); } result.AttributeIds = attr; } if (gc.Latitude != null) result.Lat = (double)gc.Latitude; if (gc.Longitude != null) result.Lon = (double)gc.Longitude; if (gc.Country != null) result.Country = gc.Country; result.DataFromDate = DateTime.Now; result.Difficulty = gc.Difficulty; result.Terrain = gc.Terrain; result.Title = gc.Name; if (gc.FavoritePoints != null) { result.Favorites = (int)gc.FavoritePoints; } result.GeocacheType = DataAccess.GetGeocacheType(core.GeocacheTypes, (int)gc.CacheType.GeocacheTypeId); if (gc.LongDescription != null) { result.LongDescription = gc.LongDescription; result.LongDescriptionInHtml = gc.LongDescriptionIsHtml; } if (gc.EncodedHints != null) { result.EncodedHints = gc.EncodedHints; } result.MemberOnly = gc.IsPremium ?? false; result.Owner = gc.Owner.UserName; if (gc.Owner.Id != null) { result.OwnerId = gc.Owner.Id.ToString(); } result.PlacedBy = gc.PlacedBy; result.PublishedTime = gc.UTCPlaceDate; if (result.ShortDescription != null) { result.ShortDescription = gc.ShortDescription; result.ShortDescriptionInHtml = gc.ShortDescriptionIsHtml; } if (gc.State == "None") { result.State = ""; } else { result.State = gc.State; } result.PersonaleNote = gc.GeocacheNote; if (gc.HasbeenFoundbyUser!=null) { result.Found = (bool)gc.HasbeenFoundbyUser; } result.Url = gc.Url; result.PersonaleNote = gc.GeocacheNote ?? ""; Calculus.SetDistanceAndAngleGeocacheFromLocation(result, core.CenterLocation); } return result; }
public static void ImportGeocaches(Core.Storage.Database db, LiveV6.SearchForGeocachesRequest req, int max) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock("ImportingGeocaches", "ImportingGeocaches", max, 0, true)) { try { using (GeocachingLiveV6 client = new GeocachingLiveV6()) { req.AccessToken = client.Token; var resp = client.Client.SearchForGeocaches(req); if (resp.Status.StatusCode == 0 && resp.Geocaches != null) { ImportGeocaches(db, resp.Geocaches); if (resp.Geocaches.Count() >= req.MaxPerPage && req.MaxPerPage < max) { if (progress.Update("ImportingGeocaches", max, resp.Geocaches.Count())) { var mreq = new LiveV6.GetMoreGeocachesRequest(); mreq.AccessToken = req.AccessToken; mreq.GeocacheLogCount = req.GeocacheLogCount; mreq.MaxPerPage = (int)Math.Min(req.MaxPerPage, max - resp.Geocaches.Count()); mreq.StartIndex = resp.Geocaches.Count(); mreq.TrackableLogCount = req.TrackableLogCount; mreq.IsLite = req.IsLite; mreq.GeocacheLogCount = req.GeocacheLogCount; while (resp.Status.StatusCode == 0 && resp.Geocaches != null && resp.Geocaches.Count() >= req.MaxPerPage) { resp = client.Client.GetMoreGeocaches(mreq); if (resp.Status.StatusCode == 0 && resp.Geocaches != null) { ImportGeocaches(db, resp.Geocaches); if (!progress.Update("ImportingGeocaches", max, mreq.StartIndex + resp.Geocaches.Count())) { break; } mreq.StartIndex += resp.Geocaches.Count(); mreq.MaxPerPage = (int)Math.Min(req.MaxPerPage, max - mreq.StartIndex); if (mreq.StartIndex >= max - 1) { break; } } else { Core.ApplicationData.Instance.Logger.AddLog(new Import(), Core.Logger.Level.Error, resp.Status.StatusMessage); } } } } } else { Core.ApplicationData.Instance.Logger.AddLog(new Import(), Core.Logger.Level.Error, resp.Status.StatusMessage); } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(new Import(), e); } } }
public static Framework.Data.Log Log(Framework.Interfaces.ICore core, LiveV6.GeocacheLog lg) { Framework.Data.Log result = null; if (lg != null) { Framework.Data.Log tmp = DataAccess.GetLog(core.Logs, lg.Code); result = new Framework.Data.Log(); if (tmp != null) { result.UpdateFrom(tmp); } result.DataFromDate = DateTime.Now; result.Date = lg.VisitDate; result.Encoded = lg.LogIsEncoded; result.Finder = lg.Finder.UserName; result.FinderId = lg.Finder.Id.ToString(); result.GeocacheCode = lg.CacheCode; result.ID = lg.Code; result.LogType = DataAccess.GetLogType(core.LogTypes, (int)lg.LogType.WptLogTypeId); result.Text = lg.LogText; } return result; }
public static Framework.Data.GeocacheImage GeocacheImage(Framework.Interfaces.ICore core, LiveV6.ImageData img, string GeocacheCode) { Framework.Data.GeocacheImage result = null; if (img != null) { Framework.Data.GeocacheImage tmp = DataAccess.GetGeocacheImage(core.GeocacheImages, img.ImageGuid.ToString()); result = new Framework.Data.GeocacheImage(); if (tmp != null) { result.UpdateFrom(tmp); } result.ID = img.ImageGuid.ToString(); result.DataFromDate = DateTime.Now; result.GeocacheCode = GeocacheCode; result.Name = img.Name; result.Url = img.Url; result.ThumbUrl = img.ThumbUrl; result.MobileUrl = img.MobileUrl; result.Description = img.Description; } return result; }
public static Framework.Data.UserWaypoint UserWaypoint(Framework.Interfaces.ICore core, LiveV6.UserWaypoint wp) { Framework.Data.UserWaypoint result = null; if (wp != null) { Framework.Data.UserWaypoint tmp = DataAccess.GetUserWaypoint(core.UserWaypoints, (int)wp.ID); result = new Framework.Data.UserWaypoint(); if (tmp != null) { result.UpdateFrom(tmp); } result.Description = wp.Description; result.GeocacheCode = wp.CacheCode; result.ID = (int)wp.ID; result.Lat = wp.Latitude; result.Lon = wp.Longitude; result.Date = wp.UTCDate.ToLocalTime(); } return result; }
public static Core.Data.UserWaypoint ImportUserWaypoint(Core.Storage.Database db, LiveV6.UserWaypoint wp) { Core.Data.UserWaypoint result = null; if (wp != null) { result = db.UserWaypointCollection.GetUserWaypoint(wp.ID.ToString()); Core.Data.IUserWaypointData wpd; if (result == null) { wpd = new Core.Data.UserWaypointData(); wpd.ID = wp.ID.ToString(); } else { wpd = result; } wpd.Description = wp.Description; wpd.GeocacheCode = wp.CacheCode; wpd.Lat = wp.Latitude; wpd.Lon = wp.Longitude; wpd.Date = wp.UTCDate.ToLocalTime(); if (wpd is Core.Data.UserWaypointData) { if (Utils.DataAccess.AddUserWaypoint(db, wpd as Core.Data.UserWaypointData)) { result = db.UserWaypointCollection.GetUserWaypoint(wp.ID.ToString()); if (wp.IsCorrectedCoordinate) { Core.Data.Geocache thisGC = db.GeocacheCollection.GetGeocache(wp.CacheCode); if (thisGC != null) { thisGC.CustomLat = wp.Latitude; thisGC.CustomLon = wp.Longitude; } } } } } return result; }
public static List<Core.Data.Log> ImportLogs(Core.Storage.Database db, LiveV6.GeocacheLog[] lgs) { List<Core.Data.Log> result = new List<Core.Data.Log>(); if (lgs != null) { foreach (var lg in lgs) { Core.Data.Log g = ImportLog(db, lg); if (g != null) { result.Add(g); } } } return result; }
public static List<Core.Data.GeocacheImage> ImportGeocacheImages(Core.Storage.Database db, LiveV6.ImageData[] wps, string GeocacheCode) { List<Core.Data.GeocacheImage> result = new List<Core.Data.GeocacheImage>(); List<Core.Data.GeocacheImage> curImgs = Utils.DataAccess.GetGeocacheImages(db, GeocacheCode); if (wps != null) { foreach (var lg in wps) { Core.Data.GeocacheImage g = ImportGeocacheImage(db, lg, GeocacheCode); if (g != null) { result.Add(g); if (curImgs.Contains(g)) { curImgs.Remove(g); } } } } foreach(var g in curImgs) { g.DeleteRecord(); db.GeocacheImageCollection.Remove(g); } return result; }
public static Core.Data.Log ImportLog(Core.Storage.Database db, LiveV6.GeocacheLog lg) { Core.Data.Log result = null; if (lg != null) { result = db.LogCollection.GetLog(lg.Code); Core.Data.ILogData lgData; if (result == null) { lgData = new Core.Data.LogData(); lgData.ID = lg.Code; } else { lgData = result; } lgData.DataFromDate = DateTime.Now; lgData.Date = lg.VisitDate; lgData.Encoded = lg.LogIsEncoded; lgData.Finder = lg.Finder.UserName; lgData.FinderId = lg.Finder.Id.ToString(); lgData.GeocacheCode = lg.CacheCode; lgData.LogType = Utils.DataAccess.GetLogType((int)lg.LogType.WptLogTypeId); lgData.Text = lg.LogText; if (lgData is Core.Data.LogData) { if (Utils.DataAccess.AddLog(db, lgData as Core.Data.LogData)) { result = db.LogCollection.GetLog(lgData.ID); if (result!=null) { ImportLogImages(db, lg.Images, result.ID); } } } } return result; }
public static List<Framework.Data.Geocache> AddGeocaches(Framework.Interfaces.ICore core, LiveV6.Geocache[] gcList) { List<Framework.Data.Geocache> result = new List<Framework.Data.Geocache>(); if (gcList != null) { foreach (var gcApi in gcList) { Framework.Data.Geocache activeGC = Utils.API.Convert.Geocache(core, gcApi); if (AddGeocache(core, activeGC)) { if (gcApi.GeocacheLogs != null) { foreach (var l in gcApi.GeocacheLogs) { Framework.Data.Log lg = Convert.Log(core, l); AddLog(core, lg); if (l.Images != null) { foreach (var li in l.Images) { AddLogImage(core, Convert.LogImage(core, li, lg.ID)); } } } } if (gcApi.AdditionalWaypoints != null) { foreach (var wp in gcApi.AdditionalWaypoints) { AddWaypoint(core, Convert.Waypoint(core, wp)); } } List<int> ids = new List<int>(); if (gcApi.UserWaypoints != null) { foreach (var wp in gcApi.UserWaypoints) { AddUserWaypoint(core, Convert.UserWaypoint(core, wp)); ids.Add((int)wp.ID); //copy user waypoint to corrected as assumed it is if (wp.IsCorrectedCoordinate) { Framework.Data.Geocache thisGC = Utils.DataAccess.GetGeocache(core.Geocaches, activeGC.Code); if (thisGC != null) { thisGC.CustomLat = wp.Latitude; thisGC.CustomLon = wp.Longitude; } } } } DataAccess.CheckUserWaypointsForGeocache(core.UserWaypoints, gcApi.Code, ids); if (gcApi.Images != null) { foreach (var imgd in gcApi.Images) { AddGeocacheImage(core, Convert.GeocacheImage(core, imgd, activeGC.Code)); } } } } } return result; }
public static Framework.Data.LogImage LogImage(Framework.Interfaces.ICore core, LiveV6.ImageData img, string LogId) { Framework.Data.LogImage result = null; if (img != null) { Framework.Data.LogImage tmp = DataAccess.GetLogImage(core.LogImages, img.Url); result = new Framework.Data.LogImage(); if (tmp != null) { result.UpdateFrom(tmp); } result.ID = img.Url; result.DataFromDate = DateTime.Now; result.LogID = LogId; result.Name = img.Name; result.Url = img.Url; } return result; }