protected virtual bool AddLogImage(Framework.Data.LogImage l) { bool result = false; if (_logImgsEmpty) { Core.Logs.Add(l); result = true; } else { Framework.Data.LogImage oldwp = Utils.DataAccess.GetLogImage(Core.LogImages, l.ID); if (oldwp == null) { Core.LogImages.Add(l); result = true; } else { if (l.DataFromDate >= l.DataFromDate) { Utils.DataAccess.UpdateLogImageData(oldwp, l); } } } return(result); }
public void OnLogImageRemoved(Framework.Data.LogImage li) { if (!_updating && LogImageRemoved != null) { LogImageRemoved(this, new Framework.EventArguments.LogImageEventArgs(li)); } OnListDataChanged(); }
public override void Remove(object value) { Framework.Data.LogImage li = value as Framework.Data.LogImage; if (li != null) { RemoveAt(IndexOf(li)); } }
public void OnDataChanged(Framework.Data.LogImage li) { _dataChanged = true; if (!_updating && DataChanged != null) { DataChanged(this, new Framework.EventArguments.LogImageEventArgs(li)); _dataChanged = false; li.IsDataChanged = false; } }
public static bool UpdateLogImageData(Framework.Data.LogImage l, Framework.Data.LogImage newData) { bool result = false; if (l.ID == newData.ID) { l.UpdateFrom(newData); result = true; } return(result); }
public override void RemoveAt(int index) { if (index >= 0 && index < Count) { Framework.Data.LogImage li = this[index] as Framework.Data.LogImage; //grouping (_logGroups[li.LogID ?? ""] as Hashtable).Remove(li.ID); //end grouping _qaItems.Remove(li.ID); li.DataChanged -= new EventArguments.LogImageEventHandler(gc_DataChanged); base.RemoveAt(index); OnLogImageRemoved(li); } }
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); }
public static bool AddLogImage(Framework.Interfaces.ICore core, Framework.Data.LogImage l) { bool result = false; Framework.Data.LogImage oldwp = DataAccess.GetLogImage(core.LogImages, l.ID); if (oldwp == null) { core.LogImages.Add(l); result = true; } else { if (l.DataFromDate >= oldwp.DataFromDate) { DataAccess.UpdateLogImageData(oldwp, l); } } return(result); }
private void getImagesThreadMethod() { Framework.Data.LogImage li = null; lock (_logImagesToGrab) { if (_logImagesToGrab.Count > 0) { li = _logImagesToGrab[0]; _logImagesToGrab.RemoveAt(0); } } using (System.Net.WebClient wc = new System.Net.WebClient()) { string fnp = System.IO.Path.Combine(Core.PluginDataPath, "LogImageCache"); while (li != null) { try { string fn = System.IO.Path.Combine(fnp, System.IO.Path.GetFileName(li.Url)); if (!System.IO.File.Exists(fn)) { wc.DownloadFile(li.Url, fn); } } catch { } li = null; lock (_logImagesToGrab) { if (_logImagesToGrab.Count > 0) { li = _logImagesToGrab[0]; _logImagesToGrab.RemoveAt(0); } } } } }
public override int Add(object value) { int result; Framework.Data.LogImage li = value as Framework.Data.LogImage; if (li != null) { _qaItems[li.ID] = li; //grouping if (_logGroups[li.LogID ?? ""] == null) { _logGroups[li.LogID ?? ""] = new Hashtable(); } (_logGroups[li.LogID ?? ""] as Hashtable)[li.ID] = li; //end grouping _sorted = false; result = base.Add(li); li.DataChanged += new EventArguments.LogImageEventHandler(gc_DataChanged); OnLogImageAdded(li); } else { //for now, only supported between begin and end update List <LogImage> lgs = value as List <LogImage>; if (lgs != null) { _batchAddition = lgs; result = 0; } else { result = -1; } } return(result); }
public override bool Load(bool geocachesOnly) { bool result = true; if (_dbcon != null) { List<string> activeAttr = new List<string>(); using (MySqlCommand cmd = new MySqlCommand("select field_name from geocache_cfields", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { string s = string.Format("{0}", dr["field_name"]); activeAttr.Add(s); Core.Geocaches.AddCustomAttribute(s); } int gcCount = 0; int logCount = 0; int logimgCount = 0; int wptCount = 0; using (MySqlCommand cmd = new MySqlCommand("select geocache, log, waypoint, logimage from counter", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) if (dr.Read()) { gcCount = (int)dr["geocache"]; logCount = (int)dr["log"]; logimgCount = (int)dr["waypoint"]; wptCount = (int)dr["logimage"]; } using (Utils.ProgressBlock fixscr = new ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select id, code, name, datafromdate, lat, lon, disttocent, angletocent, available, archived, country, state, cachetype, placedby, owner, ownerid, container, terrain, difficulty, encodedhints, url, memberonly, customcoords, attrids, favorites, selected, municipality, city, customlat, customlon, notes, publiceddate, personalnote, flagged, found, locked from geocache", _dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.ID = (string)dr["id"]; gc.Code = (string)dr["code"]; if (string.IsNullOrEmpty(gc.ID) && !string.IsNullOrEmpty(gc.Code) && gc.Code.ToUpper().StartsWith("GC")) { gc.ID = Utils.Conversion.GetCacheIDFromCacheCode(gc.Code).ToString(); } gc.Name = (string)dr["name"]; gc.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); gc.Lat = (double)(float)dr["lat"]; gc.Lon = (double)(float)dr["lon"]; //gc.DistanceToCenter = (int)dr["disttocent"]; //gc.AngleToCenter = (int)dr["angletocent"]; gc.Available = (int)dr["available"] != 0; gc.Archived = (int)dr["archived"] != 0; gc.Country = (string)dr["country"]; gc.State = (string)dr["state"]; gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, (int)dr["cachetype"]); gc.PlacedBy = (string)dr["placedby"]; gc.Owner = (string)dr["owner"]; gc.OwnerId = (string)dr["ownerid"]; gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, (int)dr["container"]); gc.Terrain = (double)(float)dr["terrain"]; gc.Difficulty = (double)(float)dr["difficulty"]; gc.EncodedHints = (string)dr["encodedhints"]; gc.Url = (string)dr["url"]; gc.MemberOnly = (int)dr["memberonly"] != 0; gc.CustomCoords = (int)dr["customcoords"] != 0; string s = (string)dr["attrids"]; string[] parts = s.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); List<int> attrList = new List<int>(); if (parts != null) { foreach (string si in parts) { attrList.Add(int.Parse(si)); } } gc.AttributeIds = attrList; gc.Municipality = (string)dr["municipality"]; gc.City = (string)dr["city"]; object o = dr["customlat"]; if (o == null || o.GetType() == typeof(DBNull)) { gc.CustomLat = null; } else { gc.CustomLat = (double?)(float)o; } o = dr["customlon"]; if (o == null || o.GetType() == typeof(DBNull)) { gc.CustomLon = null; } else { gc.CustomLon = (double?)(float)o; } gc.Notes = (string)dr["notes"]; gc.PublishedTime = DateTime.Parse((string)dr["publiceddate"]).ToLocalTime(); gc.PersonaleNote = (string)dr["personalnote"]; gc.Flagged = (int)dr["flagged"] != 0; gc.Locked = (int)dr["locked"] != 0; gc.Found = (int)dr["found"] != 0; gc.Favorites = (int)dr["favorites"]; gc.Selected = (int)dr["selected"] != 0; foreach (string attrField in activeAttr) { object objValue = null; try { objValue = dr[string.Format("_{0}", attrField)]; } catch { } gc.SetCustomAttribute(attrField, objValue); } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); gc.Saved = true; gc.IsDataChanged = false; _geocachesInDB[gc.Code] = gc.Code; Core.Geocaches.Add(gc); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); procStep = 0; } } } } if (!geocachesOnly) { using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select ID, gccode, Finder, DataFromDate, LogType, Date from log", _dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Log lg = new Framework.Data.Log(); //id text, gccode text, tbcode text, date text, finder text, finderid text, logtext text, encoded integer, datafromdate text, logtype integer lg.ID = (string)dr["id"]; lg.GeocacheCode = (string)dr["gccode"]; lg.Date = DateTime.Parse((string)dr["date"]).ToLocalTime(); lg.Finder = (string)dr["finder"]; lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); lg.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, (int)dr["logtype"]); lg.Saved = true; lg.IsDataChanged = false; _logsInDB[lg.ID] = lg.ID; Core.Logs.Add(lg); index++; procStep++; if (procStep >= 20000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); procStep = 0; } } } } //(id text, logid text, url text, name text, datafromdate text) using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select * from logimage", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.LogImage lg = new Framework.Data.LogImage(); lg.ID = (string)dr["id"]; lg.LogID = (string)dr["logid"]; lg.Url = (string)dr["url"]; lg.Name = (string)dr["name"]; lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); lg.Saved = true; lg.IsDataChanged = false; _logimgsInDB[lg.ID] = lg.ID; Core.LogImages.Add(lg); index++; procStep++; if (procStep >= 2000) { progress.UpdateProgress("Loading...", "Loading log images...", logimgCount, index); procStep = 0; } } } //id text, code text, geocachecode text, name text, datafromdate text, comment text, description text, url text, urlname text, wptype integer, lat real, lon real, time text using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select * from waypoint", _dbcon)) { cmd.CommandTimeout = 0; using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.ID = (string)dr["id"]; wp.Code = (string)dr["code"]; wp.Url = (string)dr["url"]; wp.UrlName = (string)dr["urlname"]; wp.Name = (string)dr["name"]; wp.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); wp.Comment = (string)dr["comment"]; wp.GeocacheCode = (string)dr["geocachecode"]; wp.Description = (string)dr["description"]; wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, (int)dr["wptype"]); object o = dr["lat"]; if (o == null || o.GetType() == typeof(DBNull)) { wp.Lat = null; } else { wp.Lat = (double?)(float)o; } o = dr["lon"]; if (o == null || o.GetType() == typeof(DBNull)) { wp.Lon = null; } else { wp.Lon = (double?)(float)o; } wp.Time = DateTime.Parse((string)dr["time"]).ToLocalTime(); wp.Saved = true; wp.IsDataChanged = false; _wptsInDB[wp.Code] = wp.Code; Core.Waypoints.Add(wp); index++; procStep++; if (procStep >= 20000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } } } using (MySqlCommand cmd = new MySqlCommand("select * from userwaypoint", _dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = (int)dr["id"]; wp.GeocacheCode = (string)dr["geocachecode"]; wp.Description = (string)dr["description"]; wp.Lat = (double)(float)dr["lat"]; wp.Lon = (double)(float)dr["lon"]; wp.Date = DateTime.Parse((string)dr["time"]).ToLocalTime(); wp.Saved = true; wp.IsDataChanged = false; _usrwptsInDB[wp.ID] = wp.ID; Core.UserWaypoints.Add(wp); } } } } return result; }
protected override void ImportMethod() { System.Collections.Hashtable logTypes = new System.Collections.Hashtable(); using (Utils.ProgressBlock fixpr = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGDATA, 1, 0)) { String connect = String.Format("data source=file:{0}", _filename); using (SqliteConnection dbcon = new SqliteConnection(connect)) { //System.Diagnostics.Debugger.Break(); logTypes.Add("Found it", 2); logTypes.Add("Didn't find it", 3); logTypes.Add("Write note", 4); logTypes.Add("Archive", 5); logTypes.Add("Needs Archived", 7); logTypes.Add("Will Attend", 9); logTypes.Add("Attended", 10); logTypes.Add("Webcam Photo Taken", 11); logTypes.Add("Unarchive", 12); logTypes.Add("Temporarily Disable Listing", 22); logTypes.Add("Enable Listing", 23); logTypes.Add("Publish Listing", 24); logTypes.Add("Retract Listing", 25); logTypes.Add("Needs Maintenance", 45); logTypes.Add("Owner Maintenance", 46); logTypes.Add("Update Coordinates", 47); logTypes.Add("Post Reviewer Note", 68); logTypes.Add("Announcement", 74); int index = 0; int procStep = 0; dbcon.Open(); SqliteCommand lookup = new SqliteCommand("select aId, aInc from attributes where aCode = @Code", dbcon); lookup.CommandType = CommandType.Text; DbParameter par = lookup.CreateParameter(); par.Direction = ParameterDirection.Input; par.ParameterName = "@Code"; lookup.Parameters.Add(par); lookup.Prepare(); SqliteCommand import = new SqliteCommand("select count(1) from caches", dbcon); import.CommandType = CommandType.Text; int gcCount = (int)(long)import.ExecuteScalar(); if (gcCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGGEOCACHES, gcCount, 0)) { bool isPremiumAvailable = false; bool isFavPointAvailable = false; bool isGCNoteAvailable = false; try { import.CommandText = "select IsPremium from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isPremiumAvailable = true; } } catch { } try { import.CommandText = "select FavPoints from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isFavPointAvailable = true; } } catch { } try { import.CommandText = "select gcnote from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isGCNoteAvailable = true; } } catch { } import.CommandText = "select caches.Code, Name, LastGPXDate, PlacedDate, Latitude, Longitude, Status, " + "Archived, Country, State, CacheType, PlacedBy, OwnerName, OwnerId, Container, Terrain, Difficulty, ShortHTM" + ", LongHTM, " + string.Format("{0}", isPremiumAvailable? "IsPremium, ":"") + " HasCorrected, LatOriginal, LonOriginal, UserFlag, Found, " + string.Format("{0}", isFavPointAvailable? "FavPoints, ":"") + " ShortDescription, LongDescription, Hints, Url, UserNote" + string.Format("{0}", isGCNoteAvailable ? ", gcnote" : "") + " from caches" + " inner join cachememo on cachememo.code = caches.code"; SqliteDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); int cacheType; try { cacheType = getCacheType(((String)dr["CacheType"])[0]); } catch (ArgumentOutOfRangeException) { continue; } int container = getContainer(((String)dr["Container"])[0]); gc.Code = (string)dr["code"]; gc.Name = (string)dr["name"]; gc.DataFromDate = DateTime.Parse((string)dr["LastGPXDate"]); gc.Available = ((String)dr["Status"]).Equals("A"); gc.Archived = (int)dr["archived"] != 0; gc.Country = (string)dr["country"]; gc.State = (string)dr["state"]; gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, cacheType); gc.PlacedBy = (string)dr["placedby"]; gc.Owner = (string)dr["OwnerName"]; gc.OwnerId = dr["ownerid"].GetType() == typeof(DBNull) ? "" : dr["ownerid"].ToString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, container); gc.Terrain = (double)dr["terrain"]; gc.Difficulty = (double)dr["difficulty"]; gc.ShortDescription = (string)dr["ShortDescription"]; gc.ShortDescriptionInHtml = (int)dr["ShortHTM"] != 0; gc.LongDescription = (string)dr["LongDescription"]; gc.LongDescriptionInHtml = (int)dr["LongHTM"] != 0; gc.EncodedHints = (string)dr["Hints"]; gc.Url = (string)dr["url"]; if (isPremiumAvailable) { gc.MemberOnly = (int)dr["IsPremium"] != 0; } else { gc.MemberOnly = false; } gc.CustomCoords = (int)dr["HasCorrected"] != 0; if (gc.CustomCoords) { gc.CustomLat = Utils.Conversion.StringToDouble(dr["Latitude"] as String); gc.CustomLon = Utils.Conversion.StringToDouble(dr["Longitude"] as String); gc.Lat = Utils.Conversion.StringToDouble(dr["LatOriginal"] as string); gc.Lon = Utils.Conversion.StringToDouble(dr["LonOriginal"] as string); } else { gc.Lat = Utils.Conversion.StringToDouble(dr["Latitude"] as string); gc.Lon = Utils.Conversion.StringToDouble(dr["Longitude"] as string); } par.Value = gc.Code; DbDataReader attrs = lookup.ExecuteReader(); List<int> attrList = new List<int>(); while (attrs.Read()) { int attr = (int)(int)attrs["aId"]; if (attrs["aInc"].ToString() == "0") { attr *= -1; } attrList.Add(attr); } attrs.Close(); gc.AttributeIds = attrList; gc.Notes = (string)dr["UserNote"]; gc.PublishedTime = DateTime.Parse((string)dr["PlacedDate"]); if (isGCNoteAvailable) { gc.PersonaleNote = (string)dr["gcnote"]; } else { gc.PersonaleNote = ""; } gc.Flagged = (int)dr["UserFlag"] != 0; gc.Found = (int)dr["Found"] != 0; if (isFavPointAvailable) { gc.Favorites = (int)(int)dr["FavPoints"]; } else { gc.Favorites = 0; } gc.Selected = false; Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); AddGeocache(gc, null); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGGEOCACHES, gcCount, index); procStep = 0; } } dr.Close(); } import.CommandText = "select count(1) from logs"; int logCount = (int)(long)import.ExecuteScalar(); if (logCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGLOGS, logCount, 0)) { index = 0; procStep = 0; import.CommandText = "select l.lLogId, l.lParent, lDate, lTime, lBy, lownerid, lEncoded, lType, lText " + " from logs l" + " inner join logmemo m on m.lLogId = l.lLogId and m.lParent = l.lParent"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Log lg = new Framework.Data.Log(); String type = (String)dr["lType"]; int logType = (int)logTypes[type]; //id text, gccode text, tbcode text, date text, finder text, finderid text, logtext text, encoded integer, datafromdate text, logtype integer lg.ID = dr["lLogiD"].ToString(); lg.GeocacheCode = (string)dr["lParent"]; lg.TBCode = ""; lg.Date = (DateTime)dr["lDate"]; lg.Finder = (string)dr["lBy"]; lg.FinderId = dr["lownerid"].ToString(); lg.Text = (string)dr["lText"]; lg.Encoded = (long)dr["lEncoded"]!=0; lg.DataFromDate = DateTime.Now; lg.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, logType); AddLog(lg); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGLOGS, logCount, index); procStep = 0; } } dr.Close(); } } import.CommandText = "select count(1) from logimages"; int logimgCount = 0; try { logimgCount = (int)(long)import.ExecuteScalar(); } catch { //table does not exists } if (logimgCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGLOGIMAGES, logimgCount, 0)) { index = 0; procStep = 0; import.CommandText = "select iCode, iLogId, iImage, iName from logimages"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.LogImage lg = new Framework.Data.LogImage(); lg.ID = (string)dr["iCode"]; lg.LogID = dr["iLogID"].ToString(); lg.Url = (string)dr["iImage"]; lg.Name = (string)dr["iName"]; AddLogImage(lg); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGLOGIMAGES, logimgCount, index); procStep = 0; } } dr.Close(); } } //id text, code text, geocachecode text, name text, datafromdate text, comment text, description text, url text, urlname text, wptype integer, lat real, lon real, time text import.CommandText = "select count(1) from waypoints"; int wptCount = (int)(long)import.ExecuteScalar(); if (wptCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGWAYPOINTS, wptCount, 0)) { index = 0; procStep = 0; import.CommandText = "select w.cParent, w.cCode, cName, cDate, cType, cLat, cLon," + " cComment, cUrl" + " from waypoints w" + " inner join wayMemo m on w.cParent = m.cParent and w.cCode=m.cCode"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); int wpType = getWPType(((string)dr["cType"])[0]); wp.ID = (string)dr["cCode"]; wp.Code = (string)dr["cCode"]; wp.Url = (string)dr["cUrl"]; //wp.UrlName = (string)dr["urlname"]; wp.Name = (string)dr["cName"]; wp.DataFromDate = (DateTime)dr["cDate"]; wp.Comment = (string)dr["cComment"]; wp.GeocacheCode = (string)dr["cParent"]; //wp.Description = (string)dr["description"]; wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, wpType); double lat = Utils.Conversion.StringToDouble(dr["clat"] as string); double lon = Utils.Conversion.StringToDouble(dr["clon"] as string); if (Math.Abs(lat) < 0.00001) { wp.Lat = null; } else { wp.Lat = lat; } if (Math.Abs(lon) < 0.00001) { wp.Lon = null; } else { wp.Lon = lon; } wp.Time = (DateTime)dr["cDate"]; wp.Description = wp.WPType.Name; wp.UrlName = wp.WPType.Name; AddWaypoint(wp); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGWAYPOINTS, wptCount, index); procStep = 0; } } dr.Close(); } } try { //import corrected if table exists import.CommandText = "select kCode, kAfterLat, kAfterLon from Corrected"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { string gcCode = dr["kCode"] as string ?? ""; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, gcCode); if (gc != null) { object oLat = dr["kAfterLat"]; object oLon = dr["kAfterLon"]; if (oLat != null && oLat.GetType() != typeof(DBNull) && oLon != null && oLon.GetType() != typeof(DBNull)) { string sLat = oLat as string; string sLon = oLon as string; if (sLat.Length > 0 && sLon.Length > 0) { gc.CustomLat = Utils.Conversion.StringToDouble(sLat); gc.CustomLon = Utils.Conversion.StringToDouble(sLon); } } } } } catch { } } } } }
protected override void ImportMethod() { System.Collections.Hashtable logTypes = new System.Collections.Hashtable(); using (Utils.ProgressBlock fixpr = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGDATA, 1, 0)) { String connect = String.Format("data source=file:{0}", _filename); using (SqliteConnection dbcon = new SqliteConnection(connect)) { //System.Diagnostics.Debugger.Break(); logTypes.Add("Found it", 2); logTypes.Add("Didn't find it", 3); logTypes.Add("Write note", 4); logTypes.Add("Archive", 5); logTypes.Add("Needs Archived", 7); logTypes.Add("Will Attend", 9); logTypes.Add("Attended", 10); logTypes.Add("Webcam Photo Taken", 11); logTypes.Add("Unarchive", 12); logTypes.Add("Temporarily Disable Listing", 22); logTypes.Add("Temporarily Disable", 22); logTypes.Add("Enable Listing", 23); logTypes.Add("Enable", 23); logTypes.Add("Publish Listing", 24); logTypes.Add("Publish", 24); logTypes.Add("Retract Listing", 25); logTypes.Add("Retract", 25); logTypes.Add("Needs Maintenance", 45); logTypes.Add("Owner Maintenance", 46); logTypes.Add("Update Coordinates", 47); logTypes.Add("Post Reviewer Note", 68); logTypes.Add("Announcement", 74); int index = 0; int procStep = 0; dbcon.Open(); SqliteCommand lookup = new SqliteCommand("select aId, aInc from attributes where aCode = @Code", dbcon); lookup.CommandType = CommandType.Text; DbParameter par = lookup.CreateParameter(); par.Direction = ParameterDirection.Input; par.ParameterName = "@Code"; lookup.Parameters.Add(par); lookup.Prepare(); SqliteCommand import = new SqliteCommand("select count(1) from caches", dbcon); import.CommandType = CommandType.Text; int gcCount = (int)(long)import.ExecuteScalar(); if (gcCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGGEOCACHES, gcCount, 0)) { bool isPremiumAvailable = false; bool isFavPointAvailable = false; bool isGCNoteAvailable = false; try { import.CommandText = "select IsPremium from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isPremiumAvailable = true; } } catch { } try { import.CommandText = "select FavPoints from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isFavPointAvailable = true; } } catch { } try { import.CommandText = "select gcnote from Caches limit 1"; using (SqliteDataReader checkdr = import.ExecuteReader()) { isGCNoteAvailable = true; } } catch { } import.CommandText = "select caches.Code, Name, LastGPXDate, PlacedDate, Latitude, Longitude, Status, " + "Archived, Country, State, County, CacheType, PlacedBy, OwnerName, OwnerId, Container, Terrain, Difficulty, ShortHTM" + ", LongHTM, " + string.Format("{0}", isPremiumAvailable? "IsPremium, ":"") + " HasCorrected, LatOriginal, LonOriginal, UserFlag, Found, " + string.Format("{0}", isFavPointAvailable? "FavPoints, ":"") + " ShortDescription, LongDescription, Hints, Url, UserNote" + string.Format("{0}", isGCNoteAvailable ? ", gcnote" : "") + " from caches" + " inner join cachememo on cachememo.code = caches.code"; SqliteDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); int cacheType; try { cacheType = getCacheType(((String)dr["CacheType"])[0]); } catch (ArgumentOutOfRangeException) { continue; } int container = getContainer(((String)dr["Container"])[0]); gc.Code = (string)dr["code"]; gc.Name = (string)dr["name"]; if (string.IsNullOrEmpty((string)dr["LastGPXDate"])) { gc.DataFromDate = DateTime.Now.Date; } else { gc.DataFromDate = DateTime.Parse((string)dr["LastGPXDate"]); } gc.Available = ((String)dr["Status"]).Equals("A"); gc.Archived = (int)dr["archived"] != 0; gc.Country = (string)dr["country"]; gc.State = (string)dr["state"]; gc.Municipality = (string)dr["county"]; gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, cacheType); gc.PlacedBy = (string)dr["placedby"]; gc.Owner = (string)dr["OwnerName"]; gc.OwnerId = dr["ownerid"].GetType() == typeof(DBNull) ? "" : dr["ownerid"].ToString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, container); gc.Terrain = (double)dr["terrain"]; gc.Difficulty = (double)dr["difficulty"]; gc.ShortDescription = (string)dr["ShortDescription"]; gc.ShortDescriptionInHtml = (int)dr["ShortHTM"] != 0; gc.LongDescription = (string)dr["LongDescription"]; gc.LongDescriptionInHtml = (int)dr["LongHTM"] != 0; gc.EncodedHints = (string)dr["Hints"]; gc.Url = (string)dr["url"]; if (isPremiumAvailable) { gc.MemberOnly = (int)dr["IsPremium"] != 0; } else { gc.MemberOnly = false; } gc.CustomCoords = (int)dr["HasCorrected"] != 0; if (gc.CustomCoords) { gc.CustomLat = Utils.Conversion.StringToDouble(dr["Latitude"] as String); gc.CustomLon = Utils.Conversion.StringToDouble(dr["Longitude"] as String); gc.Lat = Utils.Conversion.StringToDouble(dr["LatOriginal"] as string); gc.Lon = Utils.Conversion.StringToDouble(dr["LonOriginal"] as string); } else { gc.Lat = Utils.Conversion.StringToDouble(dr["Latitude"] as string); gc.Lon = Utils.Conversion.StringToDouble(dr["Longitude"] as string); } par.Value = gc.Code; DbDataReader attrs = lookup.ExecuteReader(); List <int> attrList = new List <int>(); while (attrs.Read()) { int attr = (int)(int)attrs["aId"]; if (attrs["aInc"].ToString() == "0") { attr *= -1; } attrList.Add(attr); } attrs.Close(); gc.AttributeIds = attrList; gc.Notes = (string)dr["UserNote"]; gc.PublishedTime = DateTime.Parse((string)dr["PlacedDate"]); if (isGCNoteAvailable) { gc.PersonaleNote = (string)dr["gcnote"]; } else { gc.PersonaleNote = ""; } gc.Flagged = (int)dr["UserFlag"] != 0; gc.Found = (int)dr["Found"] != 0; if (isFavPointAvailable) { gc.Favorites = (int)(int)dr["FavPoints"]; } else { gc.Favorites = 0; } gc.Selected = false; Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); AddGeocache(gc, null); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGGEOCACHES, gcCount, index); procStep = 0; } } dr.Close(); } import.CommandText = "select count(1) from logs"; int logCount = (int)(long)import.ExecuteScalar(); if (logCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGLOGS, logCount, 0)) { index = 0; procStep = 0; import.CommandText = "select l.lLogId, l.lParent, lDate, lTime, lBy, lownerid, lEncoded, lType, lText " + " from logs l" + " inner join logmemo m on m.lLogId = l.lLogId and m.lParent = l.lParent"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Log lg = new Framework.Data.Log(); String type = (String)dr["lType"]; int logType = (int)logTypes[type]; //id text, gccode text, tbcode text, date text, finder text, finderid text, logtext text, encoded integer, datafromdate text, logtype integer lg.ID = dr["lLogiD"].ToString(); lg.GeocacheCode = (string)dr["lParent"]; lg.TBCode = ""; lg.Date = (DateTime)dr["lDate"]; lg.Finder = (string)dr["lBy"]; lg.FinderId = dr["lownerid"].ToString(); lg.Text = (string)dr["lText"]; lg.Encoded = (long)dr["lEncoded"] != 0; lg.DataFromDate = DateTime.Now; lg.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, logType); AddLog(lg); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGLOGS, logCount, index); procStep = 0; } } dr.Close(); } } import.CommandText = "select count(1) from logimages"; int logimgCount = 0; try { logimgCount = (int)(long)import.ExecuteScalar(); } catch { //table does not exists } if (logimgCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGLOGIMAGES, logimgCount, 0)) { index = 0; procStep = 0; import.CommandText = "select iCode, iLogId, iImage, iName from logimages"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.LogImage lg = new Framework.Data.LogImage(); lg.ID = (string)dr["iCode"]; lg.LogID = dr["iLogID"].ToString(); lg.Url = (string)dr["iImage"]; lg.Name = (string)dr["iName"]; AddLogImage(lg); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGLOGIMAGES, logimgCount, index); procStep = 0; } } dr.Close(); } } //id text, code text, geocachecode text, name text, datafromdate text, comment text, description text, url text, urlname text, wptype integer, lat real, lon real, time text import.CommandText = "select count(1) from waypoints"; int wptCount = (int)(long)import.ExecuteScalar(); if (wptCount > 0) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORTING, STR_IMPORTINGWAYPOINTS, wptCount, 0)) { index = 0; procStep = 0; import.CommandText = "select w.cParent, w.cCode, cName, cDate, cType, cLat, cLon," + " cComment, cUrl" + " from waypoints w" + " inner join wayMemo m on w.cParent = m.cParent and w.cCode=m.cCode"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); int wpType = getWPType(((string)dr["cType"])[0]); wp.ID = (string)dr["cCode"]; wp.Code = (string)dr["cCode"]; wp.Url = (string)dr["cUrl"]; //wp.UrlName = (string)dr["urlname"]; wp.Name = (string)dr["cName"]; wp.DataFromDate = (DateTime)dr["cDate"]; wp.Comment = (string)dr["cComment"]; wp.GeocacheCode = (string)dr["cParent"]; //wp.Description = (string)dr["description"]; wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, wpType); double lat = Utils.Conversion.StringToDouble(dr["clat"] as string); double lon = Utils.Conversion.StringToDouble(dr["clon"] as string); if (Math.Abs(lat) < 0.00001) { wp.Lat = null; } else { wp.Lat = lat; } if (Math.Abs(lon) < 0.00001) { wp.Lon = null; } else { wp.Lon = lon; } wp.Time = (DateTime)dr["cDate"]; wp.Description = wp.WPType.Name; wp.UrlName = wp.WPType.Name; AddWaypoint(wp); index++; procStep++; if (procStep >= 500) { progress.UpdateProgress(STR_IMPORTING, STR_IMPORTINGWAYPOINTS, wptCount, index); procStep = 0; } } dr.Close(); } } try { //import corrected if table exists import.CommandText = "select kCode, kAfterLat, kAfterLon from Corrected"; DbDataReader dr = import.ExecuteReader(); while (dr.Read()) { string gcCode = dr["kCode"] as string ?? ""; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, gcCode); if (gc != null) { object oLat = dr["kAfterLat"]; object oLon = dr["kAfterLon"]; if (oLat != null && oLat.GetType() != typeof(DBNull) && oLon != null && oLon.GetType() != typeof(DBNull)) { string sLat = oLat as string; string sLon = oLon as string; if (sLat.Length > 0 && sLon.Length > 0) { gc.CustomLat = Utils.Conversion.StringToDouble(sLat); gc.CustomLon = Utils.Conversion.StringToDouble(sLon); } } } } } catch { } } } } }
private bool insertFromDatabase(bool overwrite) { bool result = false; try { int lsize = sizeof(long); byte[] memBuffer = new byte[10 * 1024 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) using (FileCollection fc = new FileCollection(_selectedInsertFromFilename)) { int gcCount = 0; int logCount = 0; int logimgCount = 0; int geocacheimgCount = 0; int wptCount = 0; int usrwptCount = 0; Hashtable htInsertedGeocaches = new Hashtable(); Hashtable htInsertedLogs = new Hashtable(); XmlDocument doc = new XmlDocument(); doc.Load(fc.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText); logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText); logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText); wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText); usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText); if (root.SelectSingleNode("GeocacheImagesCount") != null) { geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText); } DateTime nextUpdateTime = DateTime.MinValue; RecordInfo ri = new RecordInfo(); using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; FileStream fs = fc._fsGeocaches; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free //ignore fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString().Substring(2); bool newGeocache; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID); if (gc == null) { gc = new Framework.Data.Geocache(); htInsertedGeocaches.Add(ri.ID, gc); newGeocache = true; } else { if (overwrite || htInsertedGeocaches[ri.ID] != null) { newGeocache = false; } else { continue; } } gc.BeginUpdate(); try { gc.Code = ri.ID; gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); } catch { } gc.EndUpdate(); if (newGeocache) { Core.Geocaches.Add(gc); } } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newGeocache; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID); if (gc == null) { gc = new Framework.Data.Geocache(); htInsertedGeocaches.Add(ri.ID, gc); newGeocache = true; } else { if (overwrite || htInsertedGeocaches[ri.ID] != null) { newGeocache = false; } else { continue; } } gc.BeginUpdate(); try { gc.Code = ri.ID; gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); } catch { } gc.EndUpdate(); if (newGeocache) { Core.Geocaches.Add(gc); } index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; FileStream fs = fc._fsLogs; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString().Substring(2); fs.Position = ri.Offset + ri.Length; bool newLog; bool logComplete = true; Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID); if (log == null) { newLog = true; log = htInsertedLogs[ri.ID] as Framework.Data.Log; if (log == null) { log = new Framework.Data.Log(); htInsertedLogs.Add(ri.ID, log); logComplete = false; } else { logComplete = true; } } else { if (overwrite) { newLog = false; } else { continue; } } log.BeginUpdate(); try { log.ID = ri.ID; log.TBCode = br.ReadString(); log.FinderId = br.ReadString(); log.Text = br.ReadString(); log.Encoded = br.ReadBoolean(); } catch { } log.EndUpdate(); if (newLog && logComplete && htInsertedLogs[ri.ID] != null) { if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null) { Core.Logs.Add(log); } htInsertedLogs.Remove(ri.ID); } } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newLog; bool logComplete = true; Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID); if (log == null) { newLog = true; log = htInsertedLogs[ri.ID] as Framework.Data.Log; if (log == null) { log = new Framework.Data.Log(); htInsertedLogs.Add(ri.ID, log); logComplete = false; } else { logComplete = true; } } else { if (overwrite) { newLog = false; } else { continue; } } log.BeginUpdate(); try { log.ID = ri.ID; log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Finder = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32()); } catch { } log.EndUpdate(); if (newLog && logComplete && htInsertedLogs[ri.ID] != null) { //check if geocache is present if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null) { Core.Logs.Add(log); } htInsertedLogs.Remove(ri.ID); } index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.Waypoint wp = Utils.DataAccess.GetWaypoint(Core.Waypoints, ri.ID); if (wp == null) { newWp = true; wp = new Framework.Data.Waypoint(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.Code = ri.ID; wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32()); } catch { } wp.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.Waypoints.Add(wp); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.LogImage li = Utils.DataAccess.GetLogImage(Core.LogImages, ri.ID); if (li == null) { newWp = true; li = new Framework.Data.LogImage(); } else { if (overwrite) { newWp = false; } else { continue; } } li.BeginUpdate(); try { li.ID = ri.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); } catch { } li.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetLog(Core.Logs, li.LogID ?? "") != null) { Core.LogImages.Add(li); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.GeocacheImage wp = Utils.DataAccess.GetGeocacheImage(Core.GeocacheImages, ri.ID); if (wp == null) { newWp = true; wp = new Framework.Data.GeocacheImage(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.ID = ri.ID; wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.GeocacheCode = br.ReadString(); wp.Description = br.ReadString(); wp.Name = br.ReadString(); wp.Url = br.ReadString(); wp.MobileUrl = br.ReadString(); wp.ThumbUrl = br.ReadString(); } catch { } wp.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.GeocacheImages.Add(wp); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index); procStep = 0; } } } } } { using (FileStream fs = File.Open(fc.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.UserWaypoint wp = Utils.DataAccess.GetUserWaypoint(Core.UserWaypoints, int.Parse(ri.ID)); if (wp == null) { newWp = true; wp = new Framework.Data.UserWaypoint(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.ID = int.Parse(ri.ID); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); } catch { } if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.UserWaypoints.Add(wp); } } wp.EndUpdate(); } } } } } } result = true; } catch { } return result; }
public void ProcessGeocachingComGPXCaches(ResultData data, string gpxDoc) { bool isGeoSpy = false; try { string firstPart; if (gpxDoc.Length < 2000) { firstPart = gpxDoc; } else { firstPart = gpxDoc.Substring(0, 2000); } XmlDocument doc = new XmlDocument(); doc.LoadXml(gpxDoc); XmlElement root = doc.DocumentElement; XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); if (firstPart.IndexOf("http://www.topografix.com/GPX/1/1", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/1"); } else { nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/0"); } if (firstPart.IndexOf("http://geoget.ararat.cz/GpxExtensions/v2", StringComparison.OrdinalIgnoreCase) > 0) { //GeoSpy isGeoSpy = true; _cachesGpxVersion = new Version(1, 0, 0); nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/0/2", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0/2"); _cachesGpxVersion = new Version(1,0,2); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/0/1", StringComparison.OrdinalIgnoreCase) > 0) { if (firstPart.IndexOf("creator=\"Opencaching.de - http://www.opencaching.de\"") > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else if (firstPart.IndexOf("http://www.opencaching.com/xmlschemas/opencaching/1/0") > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0/1"); } _cachesGpxVersion = new Version(1, 0, 1); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/1", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/1"); _cachesGpxVersion = new Version(1, 1, 0); } else { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); _cachesGpxVersion = new Version(1, 0, 0); } if (isGeoSpy) { _gpxDataTime = DateTime.Parse(root.SelectSingleNode("x:metadata", nsmgr).SelectSingleNode("x:time", nsmgr).InnerText); } else { _gpxDataTime = DateTime.Parse(root.SelectSingleNode("x:time", nsmgr).InnerText); } XmlNodeList wps = root.SelectNodes("x:wpt", nsmgr); if (wps != null) { Version V102 = new Version(1, 0, 2); foreach (XmlNode wp in wps) { XmlNode n; if (isGeoSpy) { n = wp.SelectSingleNode("x:extensions", nsmgr).SelectSingleNode("y:cache", nsmgr); } else { n = wp.SelectSingleNode("y:cache", nsmgr); } if (n == null) { //assume Child waypoint //check if it is a child waypoint by checking the name Framework.Data.Geocache parentGeocache = null; string wpname = wp.SelectSingleNode("x:name", nsmgr).InnerText.Substring(2); parentGeocache = (from g in data.Geocaches where g.Code.Substring(2) == wpname select g).FirstOrDefault(); if (parentGeocache == null) { parentGeocache = (from Framework.Data.Geocache g in _core.Geocaches where g.Code.Substring(2) == wpname select g).FirstOrDefault(); if (parentGeocache == null) { //parent is not available //now what? continue; } } Framework.Data.Waypoint cwp = new Framework.Data.Waypoint(); cwp.Code = wp.SelectSingleNode("x:name", nsmgr).InnerText; cwp.GeocacheCode = string.Concat(parentGeocache.Code.Substring(0,2), cwp.Code.Substring(2)); cwp.DataFromDate = _gpxDataTime; cwp.Comment = wp.SelectSingleNode("x:cmt", nsmgr).InnerText; if (SafeAttributeInnerText(wp, "lat", "").Length > 0) { cwp.Lat = Utils.Conversion.StringToDouble(wp.Attributes["lat"].InnerText); cwp.Lon = Utils.Conversion.StringToDouble(wp.Attributes["lon"].InnerText); if (Math.Abs((double)cwp.Lat) < 0.0001 && Math.Abs((double)cwp.Lon) < 0.0001) { cwp.Lat = null; cwp.Lon = null; } } else { cwp.Lat = null; cwp.Lon = null; } cwp.Description = wp.SelectSingleNode("x:desc", nsmgr).InnerText; cwp.ID = cwp.Code; cwp.Name = cwp.Code; cwp.Comment = wp.SelectSingleNode("x:cmt", nsmgr).InnerText; cwp.Time = DateTime.Parse(wp.SelectSingleNode("x:time", nsmgr).InnerText); cwp.Url = SafeInnerText(wp.SelectSingleNode("x:url", nsmgr),""); cwp.UrlName = SafeInnerText(wp.SelectSingleNode("x:urlname", nsmgr),""); cwp.WPType = DataAccess.GetWaypointType(_core.WaypointTypes, wp.SelectSingleNode("x:sym", nsmgr).InnerText); data.Waypoints.Add(cwp); continue; } Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Lat = Utils.Conversion.StringToDouble(SafeAttributeInnerText(wp, "lat", "0.0")); gc.Lon = Utils.Conversion.StringToDouble(SafeAttributeInnerText(wp, "lon", "0.0")); gc.Code = wp.SelectSingleNode("x:name", nsmgr).InnerText; gc.Title = n.SelectSingleNode("y:name", nsmgr).InnerText; gc.DataFromDate = _gpxDataTime; gc.PublishedTime = DateTime.Parse(wp.SelectSingleNode("x:time", nsmgr).InnerText); if (isGeoSpy) { gc.Url = wp.SelectSingleNode("x:link", nsmgr).Attributes["href"].Value; } else { gc.Url = SafeInnerText(wp.SelectSingleNode("x:url", nsmgr), ""); } if (SafeInnerText(wp.SelectSingleNode("x:sym", nsmgr), "").EndsWith(" Found")) { gc.Found = true; } gc.Available = bool.Parse(n.Attributes["available"].InnerText); gc.Archived = bool.Parse(SafeInnerText(n.Attributes["archived"], "False")); gc.Country = SafeInnerText(n.SelectSingleNode("y:country", nsmgr), ""); gc.State = SafeInnerText(n.SelectSingleNode("y:state", nsmgr), ""); gc.ID = SafeInnerText(n.Attributes["id"], ""); gc.OwnerId = SafeAttributeInnerText(n.SelectSingleNode("y:owner", nsmgr), "id", ""); if (_cachesGpxVersion >= V102) { gc.GeocacheType = DataAccess.GetGeocacheType(_core.GeocacheTypes, int.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:type", nsmgr), "id", "-1"))); gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, int.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:container", nsmgr), "id", "-1"))); gc.Favorites = int.Parse(SafeInnerText(n.SelectSingleNode("y:favorite_points", nsmgr), "0")); gc.MemberOnly = bool.Parse(SafeInnerText(n.Attributes["memberonly"], "False")); gc.CustomCoords = bool.Parse(SafeInnerText(n.Attributes["customcoords"], "False")); gc.PersonaleNote = SafeInnerText(n.Attributes["personal_note"], ""); } else { string srchTxt = SafeInnerText(n.SelectSingleNode("y:type", nsmgr), "Unknown"); if (!srchTxt.StartsWith("Groundspeak")) { if (srchTxt.Contains("Trash")) { srchTxt = "Trash"; } else { int pos = srchTxt.IndexOf(' '); if (pos > 0) { srchTxt = srchTxt.Substring(0, pos); } } } gc.GeocacheType = DataAccess.GetGeocacheType(_core.GeocacheTypes, srchTxt); if (isGeoSpy) { gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, "Virtual"); } else { gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, SafeInnerText(n.SelectSingleNode("y:container", nsmgr), "Unknown")); } } gc.PlacedBy = SafeInnerText(n.SelectSingleNode("y:placed_by", nsmgr),""); gc.Owner = SafeInnerText(n.SelectSingleNode("y:owner", nsmgr),""); gc.Terrain = Conversion.StringToDouble(SafeInnerText(n.SelectSingleNode("y:terrain", nsmgr), "1")); gc.Difficulty = Conversion.StringToDouble(SafeInnerText(n.SelectSingleNode("y:difficulty", nsmgr), "1")); gc.ShortDescription = SafeInnerText(n.SelectSingleNode("y:short_description", nsmgr), ""); gc.ShortDescriptionInHtml = bool.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:short_description", nsmgr), "html", "False")); gc.LongDescription = SafeInnerText(n.SelectSingleNode("y:long_description", nsmgr), ""); gc.LongDescriptionInHtml = bool.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:long_description", nsmgr), "html", "False")); gc.EncodedHints = SafeInnerText(n.SelectSingleNode("y:encoded_hints", nsmgr), ""); XmlNode attrs = n.SelectSingleNode("y:attributes", nsmgr); if (attrs != null && attrs.ChildNodes!=null) { foreach (XmlNode attr in attrs.ChildNodes) { int attrId = int.Parse(attr.Attributes["id"].InnerText); int attrInc = int.Parse(SafeAttributeInnerText(attr, "inc", "1")); if (attrInc == 1) { gc.AttributeIds.Add(attrId); } else { gc.AttributeIds.Add(-1*attrId); } } } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, _core.CenterLocation); data.Geocaches.Add(gc); //Logs XmlNode ln = n.SelectSingleNode("y:logs", nsmgr); if (ln != null) { XmlNodeList logs = ln.SelectNodes("y:log", nsmgr); if (logs != null) { foreach (XmlNode l in logs) { Framework.Data.Log lg = new Framework.Data.Log(); lg.GeocacheCode = gc.Code; string lid = SafeAttributeInnerText(l, "id", ""); if (lid.StartsWith("GL")) { lg.ID = lid; } else { if (string.IsNullOrEmpty(lid) || lid.StartsWith("-")) { continue; } try { lg.ID = string.Concat("GL", Utils.Conversion.GetCacheCodeFromCacheID(int.Parse(lid)).Substring(2)); } catch { continue; } } lg.DataFromDate = _gpxDataTime; lg.Date = DateTime.Parse(l.SelectSingleNode("y:date", nsmgr).InnerText); lg.Encoded = bool.Parse(l.SelectSingleNode("y:text", nsmgr).Attributes["encoded"].InnerText); if (isGeoSpy) { lg.Text = Conversion.StripHtmlTags(System.Web.HttpUtility.HtmlDecode(l.SelectSingleNode("y:text", nsmgr).InnerText).Replace("</p>", "\r\n\r\n")); } else { lg.Text = l.SelectSingleNode("y:text", nsmgr).InnerText; } lg.Finder = l.SelectSingleNode("y:finder", nsmgr).InnerText; if (l.SelectSingleNode("y:finder", nsmgr).Attributes["id"] != null) { lg.FinderId = l.SelectSingleNode("y:finder", nsmgr).Attributes["id"].InnerText; } else { //GCTour has no finder id lg.FinderId = "1"; } if (_cachesGpxVersion >= V102) { lg.LogType = DataAccess.GetLogType(_core.LogTypes, int.Parse(l.SelectSingleNode("y:type", nsmgr).Attributes["id"].InnerText)); } else { lg.LogType = DataAccess.GetLogType(_core.LogTypes, l.SelectSingleNode("y:type", nsmgr).InnerText); } data.Logs.Add(lg); //log images XmlNode lni = l.SelectSingleNode("y:images", nsmgr); if (lni != null) { XmlNodeList logis = lni.SelectNodes("y:image", nsmgr); if (logis != null) { foreach (XmlNode li in logis) { Framework.Data.LogImage lgi = new Framework.Data.LogImage(); lgi.Url = li.SelectSingleNode("y:url", nsmgr).InnerText; lgi.ID = lgi.Url; lgi.LogID = lg.ID; lgi.Name = li.SelectSingleNode("y:name", nsmgr).InnerText; lgi.DataFromDate = _gpxDataTime; data.LogImages.Add(lgi); } } } } } } } } } catch { } }
private bool insertFromDatabase(bool overwrite) { bool result = false; try { int lsize = sizeof(long); byte[] memBuffer = new byte[10 * 1024 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) using (FileCollection fc = new FileCollection(_selectedInsertFromFilename)) { int gcCount = 0; int logCount = 0; int logimgCount = 0; int geocacheimgCount = 0; int wptCount = 0; int usrwptCount = 0; Hashtable htInsertedGeocaches = new Hashtable(); Hashtable htInsertedLogs = new Hashtable(); XmlDocument doc = new XmlDocument(); doc.Load(fc.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText); logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText); logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText); wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText); usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText); if (root.SelectSingleNode("GeocacheImagesCount") != null) { geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText); } DateTime nextUpdateTime = DateTime.MinValue; RecordInfo ri = new RecordInfo(); using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; FileStream fs = fc._fsGeocaches; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free //ignore fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString().Substring(2); bool newGeocache; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID); if (gc == null) { gc = new Framework.Data.Geocache(); htInsertedGeocaches.Add(ri.ID, gc); newGeocache = true; } else { if (overwrite || htInsertedGeocaches[ri.ID] != null) { newGeocache = false; } else { continue; } } gc.BeginUpdate(); try { gc.Code = ri.ID; gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); } catch { } gc.EndUpdate(); if (newGeocache) { Core.Geocaches.Add(gc); } } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newGeocache; Framework.Data.Geocache gc = Utils.DataAccess.GetGeocache(Core.Geocaches, ri.ID); if (gc == null) { gc = new Framework.Data.Geocache(); htInsertedGeocaches.Add(ri.ID, gc); newGeocache = true; } else { if (overwrite || htInsertedGeocaches[ri.ID] != null) { newGeocache = false; } else { continue; } } gc.BeginUpdate(); try { gc.Code = ri.ID; gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); } catch { } gc.EndUpdate(); if (newGeocache) { Core.Geocaches.Add(gc); } index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; FileStream fs = fc._fsLogs; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString().Substring(2); fs.Position = ri.Offset + ri.Length; bool newLog; bool logComplete = true; Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID); if (log == null) { newLog = true; log = htInsertedLogs[ri.ID] as Framework.Data.Log; if (log == null) { log = new Framework.Data.Log(); htInsertedLogs.Add(ri.ID, log); logComplete = false; } else { logComplete = true; } } else { if (overwrite) { newLog = false; } else { continue; } } log.BeginUpdate(); try { log.ID = ri.ID; log.TBCode = br.ReadString(); log.FinderId = br.ReadString(); log.Text = br.ReadString(); log.Encoded = br.ReadBoolean(); } catch { } log.EndUpdate(); if (newLog && logComplete && htInsertedLogs[ri.ID] != null) { if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null) { Core.Logs.Add(log); } htInsertedLogs.Remove(ri.ID); } } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newLog; bool logComplete = true; Framework.Data.Log log = Utils.DataAccess.GetLog(Core.Logs, ri.ID); if (log == null) { newLog = true; log = htInsertedLogs[ri.ID] as Framework.Data.Log; if (log == null) { log = new Framework.Data.Log(); htInsertedLogs.Add(ri.ID, log); logComplete = false; } else { logComplete = true; } } else { if (overwrite) { newLog = false; } else { continue; } } log.BeginUpdate(); try { log.ID = ri.ID; log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Finder = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32()); } catch { } log.EndUpdate(); if (newLog && logComplete && htInsertedLogs[ri.ID] != null) { //check if geocache is present if (htInsertedGeocaches[log.GeocacheCode ?? ""] != null || Utils.DataAccess.GetGeocache(Core.Geocaches, log.GeocacheCode ?? "") != null) { Core.Logs.Add(log); } htInsertedLogs.Remove(ri.ID); } index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.Waypoint wp = Utils.DataAccess.GetWaypoint(Core.Waypoints, ri.ID); if (wp == null) { newWp = true; wp = new Framework.Data.Waypoint(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.Code = ri.ID; wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32()); } catch { } wp.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.Waypoints.Add(wp); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.LogImage li = Utils.DataAccess.GetLogImage(Core.LogImages, ri.ID); if (li == null) { newWp = true; li = new Framework.Data.LogImage(); } else { if (overwrite) { newWp = false; } else { continue; } } li.BeginUpdate(); try { li.ID = ri.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); } catch { } li.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetLog(Core.Logs, li.LogID ?? "") != null) { Core.LogImages.Add(li); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } } } } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(fc.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.GeocacheImage wp = Utils.DataAccess.GetGeocacheImage(Core.GeocacheImages, ri.ID); if (wp == null) { newWp = true; wp = new Framework.Data.GeocacheImage(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.ID = ri.ID; wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.GeocacheCode = br.ReadString(); wp.Description = br.ReadString(); wp.Name = br.ReadString(); wp.Url = br.ReadString(); wp.MobileUrl = br.ReadString(); wp.ThumbUrl = br.ReadString(); } catch { } wp.EndUpdate(); if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.GeocacheImages.Add(wp); } } index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index); procStep = 0; } } } } } { using (FileStream fs = File.Open(fc.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free fs.Position = ri.Offset + ri.Length; } else { //read fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); bool newWp; Framework.Data.UserWaypoint wp = Utils.DataAccess.GetUserWaypoint(Core.UserWaypoints, int.Parse(ri.ID)); if (wp == null) { newWp = true; wp = new Framework.Data.UserWaypoint(); } else { if (overwrite) { newWp = false; } else { continue; } } wp.BeginUpdate(); try { wp.ID = int.Parse(ri.ID); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); } catch { } if (newWp) { if (Utils.DataAccess.GetGeocache(Core.Geocaches, wp.GeocacheCode ?? "") != null) { Core.UserWaypoints.Add(wp); } } wp.EndUpdate(); } } } } } } result = true; } catch { } return(result); }
public void Import(Framework.Interfaces.ICore core, Utils.BasePlugin.Plugin owner, string fileName) { using (Utils.ProgressBlock upd = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT, 1, 0)) { using (FileStream fs = File.OpenRead(fileName)) using (BinaryReader br = new BinaryReader(fs)) { string tag = br.ReadString(); if (tag == "GAPP") { bool IsLittleEndian = br.ReadBoolean(); int version = br.ReadInt32(); if (IsLittleEndian == BitConverter.IsLittleEndian && version<=3) { int count = br.ReadInt32(); using (Utils.ProgressBlock prog = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT_CACHES, count, 0)) { for (int index = 0; index < count; index++) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Code = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); string s = br.ReadString(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.Selected = br.ReadBoolean(); gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); if (version > 1) { gc.Locked = br.ReadBoolean(); } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, core.CenterLocation); (owner as Import).AddImportedGeocache(gc); int logcount = br.ReadInt32(); for (int lc = 0; lc < logcount; lc++) { Framework.Data.Log log = new Framework.Data.Log(); log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Encoded = br.ReadBoolean(); log.Finder = br.ReadString(); log.FinderId = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(core.LogTypes, br.ReadInt32()); log.TBCode = br.ReadString(); log.Text = br.ReadString(); (owner as Import).AddImportedLog(log); int logimgcount = br.ReadInt32(); for (int lic = 0; lic < logimgcount; lic++) { Framework.Data.LogImage li = new Framework.Data.LogImage(); li.DataFromDate = DateTime.Parse(br.ReadString()); li.ID = br.ReadString(); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); (owner as Import).AddImportedLogImage(li); } } int wpcount = br.ReadInt32(); for (int wpc = 0; wpc < wpcount; wpc++) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.Code = br.ReadString(); wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(core.WaypointTypes, br.ReadInt32()); (owner as Import).AddImportedWaypoint(wp); } if (version > 2) { int usrwpcount = br.ReadInt32(); for (int wpc = 0; wpc < usrwpcount; wpc++) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = br.ReadInt32(); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); (owner as Import).AddImportedUserWaypoint(wp); } } if (index % 200 == 0) { prog.UpdateProgress(STR_IMPORT, STR_IMPORT_CACHES, count, index); } } } } else { //message } } else { //message } } } }
private void readLogImageData(RecordInfo ri, MemoryStream ms, BinaryReader br) { _logimgsInDB.Add(ri.ID, ri); Framework.Data.LogImage l = new Framework.Data.LogImage(); l.ID = ri.ID; l.DataFromDate = DateTimeFromLong(br.ReadInt64()); ms.Position = 180; l.LogID = br.ReadString(); ms.Position = 220; l.Url = br.ReadString(); ms.Position = 420; l.Name = br.ReadString(); l.Saved = true; l.IsDataChanged = false; Core.LogImages.Add(l); }
public void ProcessGeocachingComGPXCaches(ResultData data, string gpxDoc) { bool isGeoSpy = false; try { string firstPart; if (gpxDoc.Length < 2000) { firstPart = gpxDoc; } else { firstPart = gpxDoc.Substring(0, 2000); } XmlDocument doc = new XmlDocument(); doc.LoadXml(gpxDoc); XmlElement root = doc.DocumentElement; XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); if (firstPart.IndexOf("http://www.topografix.com/GPX/1/1", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/1"); } else { nsmgr.AddNamespace("x", "http://www.topografix.com/GPX/1/0"); } if (firstPart.IndexOf("http://geoget.ararat.cz/GpxExtensions/v2", StringComparison.OrdinalIgnoreCase) > 0) { //GeoSpy isGeoSpy = true; _cachesGpxVersion = new Version(1, 0, 0); nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/0/2", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0/2"); _cachesGpxVersion = new Version(1, 0, 2); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/0/1", StringComparison.OrdinalIgnoreCase) > 0) { if (firstPart.IndexOf("creator=\"Opencaching.de - http://www.opencaching.de\"") > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else if (firstPart.IndexOf("http://www.opencaching.com/xmlschemas/opencaching/1/0") > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); } else { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0/1"); } _cachesGpxVersion = new Version(1, 0, 1); } else if (firstPart.IndexOf("http://www.groundspeak.com/cache/1/1", StringComparison.OrdinalIgnoreCase) > 0) { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/1"); _cachesGpxVersion = new Version(1, 1, 0); } else { nsmgr.AddNamespace("y", "http://www.groundspeak.com/cache/1/0"); _cachesGpxVersion = new Version(1, 0, 0); } if (isGeoSpy) { _gpxDataTime = DateTime.Parse(root.SelectSingleNode("x:metadata", nsmgr).SelectSingleNode("x:time", nsmgr).InnerText); } else { _gpxDataTime = DateTime.Parse(root.SelectSingleNode("x:time", nsmgr).InnerText); } XmlNodeList wps = root.SelectNodes("x:wpt", nsmgr); if (wps != null) { Version V102 = new Version(1, 0, 2); foreach (XmlNode wp in wps) { XmlNode n; if (isGeoSpy) { n = wp.SelectSingleNode("x:extensions", nsmgr).SelectSingleNode("y:cache", nsmgr); } else { n = wp.SelectSingleNode("y:cache", nsmgr); } if (n == null) { //assume Child waypoint //check if it is a child waypoint by checking the name Framework.Data.Geocache parentGeocache = null; string wpname = wp.SelectSingleNode("x:name", nsmgr).InnerText.Substring(2); parentGeocache = (from g in data.Geocaches where g.Code.Substring(2) == wpname select g).FirstOrDefault(); if (parentGeocache == null) { parentGeocache = (from Framework.Data.Geocache g in _core.Geocaches where g.Code.Substring(2) == wpname select g).FirstOrDefault(); if (parentGeocache == null) { //parent is not available //now what? continue; } } Framework.Data.Waypoint cwp = new Framework.Data.Waypoint(); cwp.Code = wp.SelectSingleNode("x:name", nsmgr).InnerText; cwp.GeocacheCode = string.Concat(parentGeocache.Code.Substring(0, 2), cwp.Code.Substring(2)); cwp.DataFromDate = _gpxDataTime; cwp.Comment = wp.SelectSingleNode("x:cmt", nsmgr).InnerText; if (SafeAttributeInnerText(wp, "lat", "").Length > 0) { cwp.Lat = Utils.Conversion.StringToDouble(wp.Attributes["lat"].InnerText); cwp.Lon = Utils.Conversion.StringToDouble(wp.Attributes["lon"].InnerText); if (Math.Abs((double)cwp.Lat) < 0.0001 && Math.Abs((double)cwp.Lon) < 0.0001) { cwp.Lat = null; cwp.Lon = null; } } else { cwp.Lat = null; cwp.Lon = null; } cwp.Description = wp.SelectSingleNode("x:desc", nsmgr).InnerText; cwp.ID = cwp.Code; cwp.Name = cwp.Code; cwp.Comment = wp.SelectSingleNode("x:cmt", nsmgr).InnerText; cwp.Time = DateTime.Parse(wp.SelectSingleNode("x:time", nsmgr).InnerText); cwp.Url = SafeInnerText(wp.SelectSingleNode("x:url", nsmgr), ""); cwp.UrlName = SafeInnerText(wp.SelectSingleNode("x:urlname", nsmgr), ""); cwp.WPType = DataAccess.GetWaypointType(_core.WaypointTypes, wp.SelectSingleNode("x:sym", nsmgr).InnerText); data.Waypoints.Add(cwp); continue; } Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Lat = Utils.Conversion.StringToDouble(SafeAttributeInnerText(wp, "lat", "0.0")); gc.Lon = Utils.Conversion.StringToDouble(SafeAttributeInnerText(wp, "lon", "0.0")); gc.Code = wp.SelectSingleNode("x:name", nsmgr).InnerText; gc.Title = n.SelectSingleNode("y:name", nsmgr).InnerText; gc.DataFromDate = _gpxDataTime; gc.PublishedTime = DateTime.Parse(wp.SelectSingleNode("x:time", nsmgr).InnerText); if (isGeoSpy) { gc.Url = wp.SelectSingleNode("x:link", nsmgr).Attributes["href"].Value; } else { gc.Url = SafeInnerText(wp.SelectSingleNode("x:url", nsmgr), ""); } if (SafeInnerText(wp.SelectSingleNode("x:sym", nsmgr), "").EndsWith(" Found")) { gc.Found = true; } gc.Available = bool.Parse(n.Attributes["available"].InnerText); gc.Archived = bool.Parse(SafeInnerText(n.Attributes["archived"], "False")); gc.Country = SafeInnerText(n.SelectSingleNode("y:country", nsmgr), ""); gc.State = SafeInnerText(n.SelectSingleNode("y:state", nsmgr), ""); gc.ID = SafeInnerText(n.Attributes["id"], ""); gc.OwnerId = SafeAttributeInnerText(n.SelectSingleNode("y:owner", nsmgr), "id", ""); if (_cachesGpxVersion >= V102) { gc.GeocacheType = DataAccess.GetGeocacheType(_core.GeocacheTypes, int.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:type", nsmgr), "id", "-1"))); gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, int.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:container", nsmgr), "id", "-1"))); gc.Favorites = int.Parse(SafeInnerText(n.SelectSingleNode("y:favorite_points", nsmgr), "0")); gc.MemberOnly = bool.Parse(SafeInnerText(n.Attributes["memberonly"], "False")); gc.CustomCoords = bool.Parse(SafeInnerText(n.Attributes["customcoords"], "False")); gc.PersonaleNote = SafeInnerText(n.Attributes["personal_note"], ""); } else { string srchTxt = SafeInnerText(n.SelectSingleNode("y:type", nsmgr), "Unknown"); if (!srchTxt.StartsWith("Groundspeak")) { if (srchTxt.Contains("Trash")) { srchTxt = "Trash"; } else { int pos = srchTxt.IndexOf(' '); if (pos > 0) { srchTxt = srchTxt.Substring(0, pos); } } } gc.GeocacheType = DataAccess.GetGeocacheType(_core.GeocacheTypes, srchTxt); if (isGeoSpy) { gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, "Virtual"); } else { gc.Container = DataAccess.GetGeocacheContainer(_core.GeocacheContainers, SafeInnerText(n.SelectSingleNode("y:container", nsmgr), "Unknown")); } } gc.PlacedBy = SafeInnerText(n.SelectSingleNode("y:placed_by", nsmgr), ""); gc.Owner = SafeInnerText(n.SelectSingleNode("y:owner", nsmgr), ""); gc.Terrain = Conversion.StringToDouble(SafeInnerText(n.SelectSingleNode("y:terrain", nsmgr), "1")); gc.Difficulty = Conversion.StringToDouble(SafeInnerText(n.SelectSingleNode("y:difficulty", nsmgr), "1")); gc.ShortDescription = SafeInnerText(n.SelectSingleNode("y:short_description", nsmgr), ""); gc.ShortDescriptionInHtml = bool.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:short_description", nsmgr), "html", "False")); gc.LongDescription = SafeInnerText(n.SelectSingleNode("y:long_description", nsmgr), ""); gc.LongDescriptionInHtml = bool.Parse(SafeAttributeInnerText(n.SelectSingleNode("y:long_description", nsmgr), "html", "False")); gc.EncodedHints = SafeInnerText(n.SelectSingleNode("y:encoded_hints", nsmgr), ""); XmlNode attrs = n.SelectSingleNode("y:attributes", nsmgr); if (attrs != null && attrs.ChildNodes != null) { foreach (XmlNode attr in attrs.ChildNodes) { int attrId = int.Parse(attr.Attributes["id"].InnerText); int attrInc = int.Parse(SafeAttributeInnerText(attr, "inc", "1")); if (attrInc == 1) { gc.AttributeIds.Add(attrId); } else { gc.AttributeIds.Add(-1 * attrId); } } } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, _core.CenterLocation); data.Geocaches.Add(gc); //Logs XmlNode ln = n.SelectSingleNode("y:logs", nsmgr); if (ln != null) { XmlNodeList logs = ln.SelectNodes("y:log", nsmgr); if (logs != null) { foreach (XmlNode l in logs) { Framework.Data.Log lg = new Framework.Data.Log(); lg.GeocacheCode = gc.Code; string lid = SafeAttributeInnerText(l, "id", ""); if (lid.StartsWith("GL")) { lg.ID = lid; } else { if (string.IsNullOrEmpty(lid) || lid.StartsWith("-")) { continue; } try { lg.ID = string.Concat("GL", Utils.Conversion.GetCacheCodeFromCacheID(int.Parse(lid)).Substring(2)); } catch { continue; } } lg.DataFromDate = _gpxDataTime; lg.Date = DateTime.Parse(l.SelectSingleNode("y:date", nsmgr).InnerText); lg.Encoded = bool.Parse(l.SelectSingleNode("y:text", nsmgr).Attributes["encoded"].InnerText); if (isGeoSpy) { lg.Text = Conversion.StripHtmlTags(System.Web.HttpUtility.HtmlDecode(l.SelectSingleNode("y:text", nsmgr).InnerText).Replace("</p>", "\r\n\r\n")); } else { lg.Text = l.SelectSingleNode("y:text", nsmgr).InnerText; } lg.Finder = l.SelectSingleNode("y:finder", nsmgr).InnerText; if (l.SelectSingleNode("y:finder", nsmgr).Attributes["id"] != null) { lg.FinderId = l.SelectSingleNode("y:finder", nsmgr).Attributes["id"].InnerText; } else { //GCTour has no finder id lg.FinderId = "1"; } if (_cachesGpxVersion >= V102) { lg.LogType = DataAccess.GetLogType(_core.LogTypes, int.Parse(l.SelectSingleNode("y:type", nsmgr).Attributes["id"].InnerText)); } else { lg.LogType = DataAccess.GetLogType(_core.LogTypes, l.SelectSingleNode("y:type", nsmgr).InnerText); } data.Logs.Add(lg); //log images XmlNode lni = l.SelectSingleNode("y:images", nsmgr); if (lni != null) { XmlNodeList logis = lni.SelectNodes("y:image", nsmgr); if (logis != null) { foreach (XmlNode li in logis) { Framework.Data.LogImage lgi = new Framework.Data.LogImage(); lgi.Url = li.SelectSingleNode("y:url", nsmgr).InnerText; lgi.ID = lgi.Url; lgi.LogID = lg.ID; lgi.Name = li.SelectSingleNode("y:name", nsmgr).InnerText; lgi.DataFromDate = _gpxDataTime; data.LogImages.Add(lgi); } } } } } } } } } catch { } }
public override bool Load(bool geocachesOnly) { bool result = true; if (File.Exists(_fileCollection.DatabaseInfoFilename)) { int lsize = sizeof(long); byte[] memBuffer = new byte[10 * 1024 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) { int gcCount = 0; int logCount = 0; int logimgCount = 0; int geocacheimgCount = 0; int wptCount = 0; int usrwptCount = 0; XmlDocument doc = new XmlDocument(); doc.Load(_fileCollection.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText); logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText); logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText); wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText); usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText); if (root.SelectSingleNode("GeocacheImagesCount") != null) { geocacheimgCount = int.Parse(root.SelectSingleNode("GeocacheImagesCount").InnerText); } DateTime nextUpdateTime = DateTime.MinValue; using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; //int procStep = 0; List<Framework.Data.Geocache> gcList = new List<Framework.Data.Geocache>(); FileStream fs = _fileCollection._fsGeocaches; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //lazy loading ri.FreeSlot = false; int readCount = Math.Min(32, (int)(ri.Length - lsize - 1)); fs.Read(memBuffer, 0, readCount); ms.Position = 0; ri.ID = br.ReadString(); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.Geocache gc = new Framework.Data.Geocache(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; gc.Code = br.ReadString(); ri.ID = gc.Code; gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation); gc.Saved = true; gc.IsDataChanged = false; //gcList.Add(gc); Core.Geocaches.Add(gc); index++; //procStep++; //if (procStep >= 1000) if (DateTime.Now>=nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); //procStep = 0; } } _fileCollection._geocachesInDB.Add(ri.ID, ri); } //Core.Geocaches.Add(gcList); } if (!geocachesOnly) { using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; List<Framework.Data.Log> lgList = new List<Framework.Data.Log>(); FileStream fs = _fileCollection._fsLogs; fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { //lazy loading ri.FreeSlot = false; int readCount = Math.Min(32, (int)(ri.Length - lsize - 1)); fs.Read(memBuffer, 0, readCount); ms.Position = 0; ri.ID = br.ReadString(); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.Log log = new Framework.Data.Log(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; log.ID = br.ReadString(); ri.ID = log.ID; log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Finder = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32()); log.Saved = true; log.IsDataChanged = false; lgList.Add(log); index++; //procStep++; //if (procStep >= 1000) if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); //procStep = 0; } } _fileCollection._logsInDB.Add(ri.ID, ri); } Core.Logs.Add(lgList); } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.Waypoint> wptList = new List<Framework.Data.Waypoint>(); using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; wp.Code = br.ReadString(); ri.ID = wp.Code; wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32()); wp.Saved = true; wp.IsDataChanged = false; wptList.Add(wp); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } _fileCollection._wptsInDB.Add(ri.ID, ri); } } Core.Waypoints.Add(wptList); } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.LogImage> lgiList = new List<Framework.Data.LogImage>(); using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.LogImage li = new Framework.Data.LogImage(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; li.ID = br.ReadString(); ri.ID = li.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); li.Saved = true; li.IsDataChanged = false; lgiList.Add(li); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } _fileCollection._logimgsInDB.Add(ri.ID, ri); } } Core.LogImages.Add(lgiList); } using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.GeocacheImage> lgiList = new List<Framework.Data.GeocacheImage>(); using (FileStream fs = File.Open(_fileCollection.GeocacheImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.GeocacheImage li = new Framework.Data.GeocacheImage(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; li.ID = br.ReadString(); ri.ID = li.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.GeocacheCode = br.ReadString(); li.Description = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); li.MobileUrl = br.ReadString(); li.ThumbUrl = br.ReadString(); li.Saved = true; li.IsDataChanged = false; lgiList.Add(li); index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHEIMAGES, geocacheimgCount, index); procStep = 0; } } _fileCollection._geocacheimgsInDB.Add(ri.ID, ri); } } Core.GeocacheImages.Add(lgiList); } //using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; List<Framework.Data.UserWaypoint> uwplList = new List<Framework.Data.UserWaypoint>(); using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); wp.ID = int.Parse(ri.ID); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); wp.Saved = true; wp.IsDataChanged = false; uwplList.Add(wp); index++; procStep++; if (procStep >= 1000) { //progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } _fileCollection._usrwptsInDB.Add(ri.ID, ri); } } Core.UserWaypoints.Add(uwplList); } } } } } return result; }
public bool RepairV1() { bool result = true; if (File.Exists(_fileCollection.DatabaseInfoFilename)) { int lsize = sizeof(long); byte[] memBuffer = new byte[10 * 1024 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) { int gcCount = 0; int logCount = 0; int logimgCount = 0; int wptCount = 0; int usrwptCount = 0; XmlDocument doc = new XmlDocument(); doc.Load(_fileCollection.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText); logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText); logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText); wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText); usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText); DateTime nextUpdateTime = DateTime.MinValue; using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; FileStream fs = _fileCollection._fsGeocaches; fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { ri.FreeSlot = false; fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); br.ReadString(); br.ReadBoolean(); br.ReadString(); br.ReadBoolean(); } else { //read ri.FreeSlot = false; Framework.Data.Geocache gc = new Framework.Data.Geocache(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; gc.Code = br.ReadString(); ri.ID = gc.Code; gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); gc.Saved = true; gc.IsDataChanged = false; index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; FileStream fs = _fileCollection._fsLogs; fs.Position = 0; long lastOKPosition = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { ri.FreeSlot = false; fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); br.ReadString(); br.ReadString(); br.ReadString(); br.ReadBoolean(); } else { //read ri.FreeSlot = false; Framework.Data.Log log = new Framework.Data.Log(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; log.ID = br.ReadString(); ri.ID = log.ID; log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Finder = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32()); log.Saved = true; log.IsDataChanged = false; index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; wp.Code = br.ReadString(); ri.ID = wp.Code; wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32()); wp.Saved = true; wp.IsDataChanged = false; index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.LogImage li = new Framework.Data.LogImage(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; li.ID = br.ReadString(); ri.ID = li.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); li.Saved = true; li.IsDataChanged = false; index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } { int index = 0; _uniqueCheckList.Clear(); using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); wp.ID = int.Parse(ri.ID); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); wp.Saved = true; wp.IsDataChanged = false; index++; } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } } } } 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; }
public override bool LoadLogImages(List<Framework.Data.LogImage> logimgs) { bool result = false; MySqlConnection dbcon = GetMySqlConnection(Properties.Settings.Default.SqlServer, Properties.Settings.Default.Database, Properties.Settings.Default.SqlServerPwd, Properties.Settings.Default.SqlServerUsername, Properties.Settings.Default.SqlServerUseIS, Properties.Settings.Default.SqlServerPort); if (dbcon != null && InitDatabase(dbcon, Properties.Settings.Default.Database)) { int logimgCount = 0; using (MySqlCommand cmd = new MySqlCommand("select logimage from counter", dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) if (dr.Read()) { logimgCount = (int)dr["logimage"]; } int index = 0; int procStep = 0; using (MySqlCommand cmd = new MySqlCommand("select * from logimage", dbcon)) using (MySqlDataReader dr = cmd.ExecuteReader()) while (dr.Read()) { Framework.Data.LogImage lg = new Framework.Data.LogImage(); lg.ID = (string)dr["id"]; lg.LogID = (string)dr["logid"]; lg.Url = (string)dr["url"]; lg.Name = (string)dr["name"]; lg.DataFromDate = DateTime.Parse((string)dr["datafromdate"]).ToLocalTime(); lg.Saved = true; lg.IsDataChanged = false; _logimgsInDB[lg.ID] = lg.ID; logimgs.Add(lg); index++; procStep++; if (procStep >= 2000) { UpdateLoadingInBackgroundProgress(STR_LOADING_LOGIMAGES_BG, logimgCount, index); procStep = 0; } } dbcon.Dispose(); dbcon = null; } return result; }
public void Import(Framework.Interfaces.ICore core, Utils.BasePlugin.Plugin owner, string fileName) { using (Utils.ProgressBlock upd = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT, 1, 0)) { using (FileStream fs = File.OpenRead(fileName)) using (BinaryReader br = new BinaryReader(fs)) { string tag = br.ReadString(); if (tag == "GAPP") { bool IsLittleEndian = br.ReadBoolean(); int version = br.ReadInt32(); if (IsLittleEndian == BitConverter.IsLittleEndian && version <= 3) { int count = br.ReadInt32(); using (Utils.ProgressBlock prog = new Utils.ProgressBlock(owner, STR_IMPORT, STR_IMPORT_CACHES, count, 0)) { for (int index = 0; index < count; index++) { Framework.Data.Geocache gc = new Framework.Data.Geocache(); gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Code = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); string s = br.ReadString(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.LongDescription = br.ReadString(); gc.LongDescriptionInHtml = br.ReadBoolean(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.Selected = br.ReadBoolean(); gc.ShortDescription = br.ReadString(); gc.ShortDescriptionInHtml = br.ReadBoolean(); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); if (version > 1) { gc.Locked = br.ReadBoolean(); } Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, core.CenterLocation); (owner as Import).AddImportedGeocache(gc); int logcount = br.ReadInt32(); for (int lc = 0; lc < logcount; lc++) { Framework.Data.Log log = new Framework.Data.Log(); log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Encoded = br.ReadBoolean(); log.Finder = br.ReadString(); log.FinderId = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(core.LogTypes, br.ReadInt32()); log.TBCode = br.ReadString(); log.Text = br.ReadString(); (owner as Import).AddImportedLog(log); int logimgcount = br.ReadInt32(); for (int lic = 0; lic < logimgcount; lic++) { Framework.Data.LogImage li = new Framework.Data.LogImage(); li.DataFromDate = DateTime.Parse(br.ReadString()); li.ID = br.ReadString(); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); (owner as Import).AddImportedLogImage(li); } } int wpcount = br.ReadInt32(); for (int wpc = 0; wpc < wpcount; wpc++) { Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); wp.Code = br.ReadString(); wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(core.WaypointTypes, br.ReadInt32()); (owner as Import).AddImportedWaypoint(wp); } if (version > 2) { int usrwpcount = br.ReadInt32(); for (int wpc = 0; wpc < usrwpcount; wpc++) { Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); wp.ID = br.ReadInt32(); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); (owner as Import).AddImportedUserWaypoint(wp); } } if (index % 200 == 0) { prog.UpdateProgress(STR_IMPORT, STR_IMPORT_CACHES, count, index); } } } } else { //message } } else { //message } } } }
public override bool LoadLogImages(List<Framework.Data.LogImage> logimgs) { bool result = true; int index = 0; int procStep = 0; if (File.Exists(_fileCollection.DatabaseInfoFilename)) { int lsize = sizeof(long); byte[] memBuffer = new byte[5 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) { int logimgCount = 0; XmlDocument doc = new XmlDocument(); doc.Load(_fileCollection.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText); using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.Read)) { fs.Position = 0; long eof = fs.Length; while (fs.Position < eof) { RecordInfo ri = new RecordInfo(); ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.LogImage li = new Framework.Data.LogImage(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; li.ID = br.ReadString(); ri.ID = li.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); li.Saved = true; li.IsDataChanged = false; logimgs.Add(li); index++; procStep++; if (procStep >= 2000) { UpdateLoadingInBackgroundProgress(STR_LOADING_LOGIMAGES_BG, logimgCount, index); procStep = 0; } } _fileCollection._logimgsInDB.Add(ri.ID, ri); } } } } return result; }
private void checkImageToLoad(object sender, EventArgs e) { string targetImageUrl = null; if (listView1.SelectedItems.Count > 0) { Framework.Data.LogImage li = listView1.SelectedItems[0].Tag as Framework.Data.LogImage; if (li != null) { Framework.Data.Log l = Core.Logs.GetLog(li.LogID); if (l != null) { linkLabel1.Links.Clear(); linkLabel1.Text = l.ID; label4.Text = l.Finder; textBox1.Text = l.Text; } else { linkLabel1.Links.Clear(); linkLabel1.Text = "-"; label4.Text = "-"; textBox1.Text = ""; } if (!PluginSettings.Instance.CacheImages && _cacheFolder != null) { targetImageUrl = li.Url; } else { string fn = System.IO.Path.Combine(_cacheFolder, System.IO.Path.GetFileName(li.Url)); if (System.IO.File.Exists(fn)) { _currentActiveImageUrl = li.Url; LoadCompleted(System.IO.File.ReadAllBytes(fn), li.Url, false); return; } else { targetImageUrl = li.Url; } } } else { linkLabel1.Links.Clear(); linkLabel1.Text = "-"; label4.Text = "-"; textBox1.Text = ""; } } if (targetImageUrl == _currentActiveImageUrl) { //ignore } else { _imageDownloader.Stop(); if (targetImageUrl == null) { Image prevImage = pictureBox1.Image; pictureBox1.Image = null; if (prevImage != null) { prevImage.Dispose(); } } else { _imageDownloader.LoadAsync(targetImageUrl); toolStripProgressBar1.Value = 0; toolStripProgressBar1.Visible = true; } _currentActiveImageUrl = targetImageUrl; } }
public bool RepairV1() { bool result = true; if (File.Exists(_fileCollection.DatabaseInfoFilename)) { int lsize = sizeof(long); byte[] memBuffer = new byte[10 * 1024 * 1024]; using (MemoryStream ms = new MemoryStream(memBuffer)) using (BinaryReader br = new BinaryReader(ms)) { int gcCount = 0; int logCount = 0; int logimgCount = 0; int wptCount = 0; int usrwptCount = 0; XmlDocument doc = new XmlDocument(); doc.Load(_fileCollection.DatabaseInfoFilename); XmlElement root = doc.DocumentElement; gcCount = int.Parse(root.SelectSingleNode("GeocacheCount").InnerText); logCount = int.Parse(root.SelectSingleNode("LogCount").InnerText); logimgCount = int.Parse(root.SelectSingleNode("LogImagesCount").InnerText); wptCount = int.Parse(root.SelectSingleNode("WaypointCount").InnerText); usrwptCount = int.Parse(root.SelectSingleNode("UserWaypointCount").InnerText); DateTime nextUpdateTime = DateTime.MinValue; using (Utils.ProgressBlock fixscr = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 1, 0)) { using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGGEOCACHES, gcCount, 0)) { int index = 0; FileStream fs = _fileCollection._fsGeocaches; fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { ri.FreeSlot = false; fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); br.ReadString(); br.ReadBoolean(); br.ReadString(); br.ReadBoolean(); } else { //read ri.FreeSlot = false; Framework.Data.Geocache gc = new Framework.Data.Geocache(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; gc.Code = br.ReadString(); ri.ID = gc.Code; gc.Archived = br.ReadBoolean(); gc.AttributeIds = ReadIntegerArray(br); gc.Available = br.ReadBoolean(); gc.City = br.ReadString(); gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32()); gc.CustomCoords = br.ReadBoolean(); gc.Country = br.ReadString(); if (br.ReadBoolean()) { gc.CustomLat = br.ReadDouble(); gc.CustomLon = br.ReadDouble(); } gc.Difficulty = br.ReadDouble(); gc.EncodedHints = br.ReadString(); gc.Favorites = br.ReadInt32(); gc.Flagged = br.ReadBoolean(); gc.Found = br.ReadBoolean(); gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32()); gc.ID = br.ReadString(); gc.Lat = br.ReadDouble(); gc.Lon = br.ReadDouble(); gc.MemberOnly = br.ReadBoolean(); gc.Municipality = br.ReadString(); gc.Name = br.ReadString(); gc.Notes = br.ReadString(); gc.Owner = br.ReadString(); gc.OwnerId = br.ReadString(); gc.PersonaleNote = br.ReadString(); gc.PlacedBy = br.ReadString(); gc.PublishedTime = DateTime.Parse(br.ReadString()); gc.State = br.ReadString(); gc.Terrain = br.ReadDouble(); gc.Title = br.ReadString(); gc.Url = br.ReadString(); gc.DataFromDate = DateTime.Parse(br.ReadString()); gc.Locked = br.ReadBoolean(); gc.Saved = true; gc.IsDataChanged = false; index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGGEOCACHES, gcCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGS, logCount, 0)) { int index = 0; nextUpdateTime = DateTime.MinValue; FileStream fs = _fileCollection._fsLogs; fs.Position = 0; long lastOKPosition = 0; long eof = fs.Length; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else if (memBuffer[lsize] == 2) { ri.FreeSlot = false; fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); br.ReadString(); br.ReadString(); br.ReadString(); br.ReadBoolean(); } else { //read ri.FreeSlot = false; Framework.Data.Log log = new Framework.Data.Log(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; log.ID = br.ReadString(); ri.ID = log.ID; log.DataFromDate = DateTime.Parse(br.ReadString()); log.Date = DateTime.Parse(br.ReadString()); log.Finder = br.ReadString(); log.GeocacheCode = br.ReadString(); log.ID = br.ReadString(); log.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32()); log.Saved = true; log.IsDataChanged = false; index++; if (DateTime.Now >= nextUpdateTime) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGS, logCount, index); nextUpdateTime = DateTime.Now.AddSeconds(1); } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(_fileCollection.WaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.Waypoint wp = new Framework.Data.Waypoint(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; wp.Code = br.ReadString(); ri.ID = wp.Code; wp.Comment = br.ReadString(); wp.DataFromDate = DateTime.Parse(br.ReadString()); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.ID = br.ReadString(); if (br.ReadBoolean()) { wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); } wp.Name = br.ReadString(); wp.Time = DateTime.Parse(br.ReadString()); wp.Url = br.ReadString(); wp.UrlName = br.ReadString(); wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32()); wp.Saved = true; wp.IsDataChanged = false; index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGWAYPOINTS, wptCount, index); procStep = 0; } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } _uniqueCheckList.Clear(); using (Utils.ProgressBlock progress = new ProgressBlock(this, STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, 0)) { int index = 0; int procStep = 0; using (FileStream fs = File.Open(_fileCollection.LogImagesFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.LogImage li = new Framework.Data.LogImage(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; li.ID = br.ReadString(); ri.ID = li.ID; li.DataFromDate = DateTime.Parse(br.ReadString()); li.LogID = br.ReadString(); li.Name = br.ReadString(); li.Url = br.ReadString(); li.Saved = true; li.IsDataChanged = false; index++; procStep++; if (procStep >= 1000) { progress.UpdateProgress(STR_LOADING, STR_LOADINGLOGIMAGES, logimgCount, index); procStep = 0; } } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } { int index = 0; _uniqueCheckList.Clear(); using (FileStream fs = File.Open(_fileCollection.UserWaypointsFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { fs.Position = 0; long eof = fs.Length; long lastOKPosition = 0; RecordInfo ri = new RecordInfo(); try { while (fs.Position < eof) { lastOKPosition = fs.Position; ri.Offset = fs.Position; fs.Read(memBuffer, 0, lsize + 1); ms.Position = 0; ri.Length = br.ReadInt64(); if (memBuffer[lsize] == 0) { //free ri.FreeSlot = true; ri.ID = string.Concat("_", ri.Offset.ToString()); fs.Position = ri.Offset + ri.Length; } else { //read ri.FreeSlot = false; Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint(); fs.Read(memBuffer, 0, (int)(ri.Length - lsize - 1)); ms.Position = 0; ri.ID = br.ReadString(); wp.ID = int.Parse(ri.ID); wp.Description = br.ReadString(); wp.GeocacheCode = br.ReadString(); wp.Lat = br.ReadDouble(); wp.Lon = br.ReadDouble(); wp.Date = DateTime.Parse(br.ReadString()); wp.Saved = true; wp.IsDataChanged = false; index++; } checkUniqueID(ri, fs); } } catch { //error in file after lastOKPosition fs.SetLength(lastOKPosition); } } } } } } return(result); }
public bool AddImportedLogImage(Framework.Data.LogImage li) { return(base.AddLogImage(li)); }