public static void DeleteLog(Database db, Core.Data.Log lg) { List <Core.Data.LogImage> gcil = GetLogImages(db, lg.ID); foreach (var wp in gcil) { wp.DeleteRecord(); db.LogImageCollection.Remove(wp); } lg.DeleteRecord(); db.LogCollection.Remove(lg); }
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 Core.Data.Log AddLog(Core.Storage.Database db, OKAPIService.Log lg, string finder, string finderId) { Core.Data.Log result = null; if (lg != null) { result = db.LogCollection.GetLog(lg.uuid); Core.Data.ILogData lgData; if (result == null) { lgData = new Core.Data.LogData(); lgData.ID = lg.uuid; } else { lgData = result; } lgData.DataFromDate = DateTime.Now; lgData.Date = DateTime.Parse(lg.date); lgData.Encoded = false; if (lg.user == null) { lgData.Finder = finder; lgData.FinderId = finderId; } else { lgData.Finder = lg.user.username; lgData.FinderId = lg.user.uuid; } lgData.GeocacheCode = lg.cache_code; lgData.Text = lg.comment; lgData.LogType = Utils.DataAccess.GetLogType(lg.type); if (lgData is Core.Data.LogData) { if (Utils.DataAccess.AddLog(db, lgData as Core.Data.LogData)) { result = db.LogCollection.GetLog(lgData.ID); } } } 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 void ImportGeocacheLogs(Core.Storage.Database db, List <Core.Data.Geocache> gcList) { try { using (Utils.ProgressBlock progress = new Utils.ProgressBlock("UpdatingGeocaches", "UpdatingGeocache", gcList.Count, 0, true)) { int totalcount = gcList.Count; using (LiveAPI.GeocachingLiveV6 client = new LiveAPI.GeocachingLiveV6()) { int index = 0; while (gcList.Count > 0) { int logCount = 0; int maxPerPage = Core.Settings.Default.LiveAPIGetGeocacheLogsByCacheCodeBatchSize; bool done = false; if (Core.Settings.Default.LiveAPIUpdateGeocacheLogsMax > 0 && Core.Settings.Default.LiveAPIUpdateGeocacheLogsMax < 30) { maxPerPage = Core.Settings.Default.LiveAPIUpdateGeocacheLogsMax; } List <string> ids = new List <string>(); if (index > 0) { Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetGeocacheLogsByCacheCode); } var resp = client.Client.GetGeocacheLogsByCacheCode(client.Token, gcList[0].Code, logCount, maxPerPage); while (resp.Status.StatusCode == 0 && resp.Logs != null && resp.Logs.Count() > 0 && !done) { foreach (var lg in resp.Logs) { if (!lg.IsArchived) { Core.Data.Log gcLog = ImportLog(db, lg); if (Core.Settings.Default.LiveAPIUpdateGeocacheLogsMax == 0 && gcLog != null) { ids.Add(gcLog.ID); } } } logCount += resp.Logs.Count(); if (Core.Settings.Default.LiveAPIUpdateGeocacheLogsMax > 0) { int left = Core.Settings.Default.LiveAPIUpdateGeocacheLogsMax - logCount; if (left < maxPerPage) { maxPerPage = left; } } if (maxPerPage > 0) { Thread.Sleep(Core.Settings.Default.LiveAPIDelayGetGeocacheLogsByCacheCode); resp = client.Client.GetGeocacheLogsByCacheCode(client.Token, gcList[0].Code, logCount, maxPerPage); } else { done = true; } } if (resp.Status.StatusCode != 0) { Core.ApplicationData.Instance.Logger.AddLog(new Import(), Core.Logger.Level.Error, resp.Status.StatusMessage); break; } else { if (Core.Settings.Default.LiveAPIDeselectAfterUpdate) { gcList[0].Selected = false; } if (Core.Settings.Default.LiveAPIUpdateGeocacheLogsMax == 0) { List <Core.Data.Log> allLogs = Utils.DataAccess.GetLogs(db, gcList[0].Code); foreach (Core.Data.Log gim in allLogs) { if (!ids.Contains(gim.ID)) { gim.DeleteRecord(); db.LogCollection.Remove(gim); } } } } index++; if (!progress.Update("UpdatingGeocache", totalcount, index)) { break; } gcList.RemoveAt(0); } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(new Import(), e); } }
public void ImportMunzeesFromDfxAt(Core.Storage.Database db, string url) { using (Utils.ProgressBlock fixpr = new Utils.ProgressBlock("ImportingMunzees", "DownloadingData", 2, 0)) { int index = 0; MunzeeDataList munzl; try { System.Net.HttpWebRequest webRequest; webRequest = System.Net.WebRequest.Create(url) as System.Net.HttpWebRequest; webRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.17 Safari/533.4"; DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(MunzeeDataList)); using (System.IO.Stream stream = webRequest.GetResponse().GetResponseStream()) { munzl = ser.ReadObject(stream) as MunzeeDataList; } fixpr.Update("DownloadingData", 2, 1); DateTime nextProgUpdate = DateTime.MinValue; string usrname = (Core.ApplicationData.Instance.AccountInfos.GetAccountInfo("MZ").AccountName ?? "").ToLower(); using (Utils.ProgressBlock prog = new Utils.ProgressBlock("SavingGeocaches", "SavingGeocaches", munzl.Count, 0)) { foreach (MunzeeData md in munzl) { string code = string.Format("MZ{0}", int.Parse(md.munzee_id).ToString("X4")); Core.Data.IGeocacheData gc = db.GeocacheCollection.GetGeocache(code); if (gc == null) { gc = new Core.Data.GeocacheData(); } gc.Archived = md.archived == "1"; gc.Available = !gc.Archived; //gc.City = md.location.Split(new char[]{','})[0]; gc.City = ""; gc.Code = code; gc.Container = Utils.DataAccess.GetGeocacheContainer(1); gc.Country = md.country; gc.DataFromDate = DateTime.Now; gc.Difficulty = 1.0; gc.Found = md.captured != "0"; if (md.type == "") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(95342); } else if (md.type == "virtual") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(95343); } else if (md.type == "maintenance") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(95344); } else if (md.type == "business") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(95345); } else if (md.type == "mystery") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(95346); } else if (md.type == "nfc") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(95347); } else if (md.type == "premium") { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(95348); } else { gc.GeocacheType = Utils.DataAccess.GetGeocacheType(95342); } gc.Lat = Utils.Conversion.StringToDouble(md.latitude); gc.Lon = Utils.Conversion.StringToDouble(md.longitude); gc.LongDescription = md.notes == null ? "" : md.notes.Replace("\r", "").Replace("\n", "\r\n"); gc.LongDescriptionInHtml = false; gc.MemberOnly = false; gc.Municipality = ""; gc.Name = md.friendly_name; gc.Owner = md.username; gc.OwnerId = ""; gc.PlacedBy = md.username; try { gc.PublishedTime = DateTime.ParseExact(md.deployed_at, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); } catch { gc.PublishedTime = DateTime.ParseExact(md.created_at, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); } gc.ShortDescription = ""; gc.ShortDescriptionInHtml = false; gc.State = ""; gc.Terrain = 1.0; gc.Url = string.Format("http://www.munzee.com/m/{0}/{1}/", md.username, md.code); bool gcAdded = true; if (gc is Core.Data.GeocacheData) { gcAdded = Utils.DataAccess.AddGeocache(Core.ApplicationData.Instance.ActiveDatabase, gc as Core.Data.GeocacheData); } if (gcAdded) { gc = (from a in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where a.Code == code select a).FirstOrDefault(); Utils.Calculus.SetDistanceAndAngleGeocacheFromLocation(gc as Core.Data.Geocache, Core.ApplicationData.Instance.CenterLocation); //check if found and if so, if log present if (gc.Found && !string.IsNullOrEmpty(md.captured_at)) { //foud and no log, add log bool foundLogPresent = false; List <Core.Data.Log> lgs = db.LogCollection.GetLogs(gc.Code); if (lgs != null) { Core.Data.Log l = (from Core.Data.Log lg in lgs where lg.LogType.AsFound && string.Compare(usrname, lg.Finder, true) == 0 select lg).FirstOrDefault(); foundLogPresent = (l != null); } if (!foundLogPresent) { Core.Data.LogData l = new Core.Data.LogData(); l.DataFromDate = DateTime.Now; l.Date = new DateTime(1970, 1, 1); l.Date = l.Date.AddSeconds(long.Parse(md.captured_at.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0])); l.Encoded = false; l.Finder = Core.ApplicationData.Instance.AccountInfos.GetAccountInfo("MZ").AccountName ?? ""; l.FinderId = "0"; l.GeocacheCode = gc.Code; l.ID = string.Format("ML{0}", gc.Code.Substring(2)); l.LogType = Utils.DataAccess.GetLogType(2); l.Text = "Captured"; Utils.DataAccess.AddLog(db, l); } } } index++; if (DateTime.Now >= nextProgUpdate) { prog.Update("SavingGeocaches", munzl.Count, index); nextProgUpdate = DateTime.Now.AddSeconds(0.5); } } } } catch (Exception e) { Core.ApplicationData.Instance.Logger.AddLog(this, e); } } }