protected override void ExportMethod() { int max = _gcList.Count; int index = 0; Hashtable htAttributes = new Hashtable(); htAttributes[1] = "dogs"; htAttributes[2] = "fee"; htAttributes[3] = "rappelling"; htAttributes[4] = "boat"; htAttributes[5] = "scuba"; htAttributes[6] = "kids"; htAttributes[7] = "onehour"; htAttributes[8] = "scenic"; htAttributes[9] = "hiking"; htAttributes[10] = "climbing"; htAttributes[11] = "wading"; htAttributes[12] = "swimming"; htAttributes[13] = "available"; htAttributes[14] = "night"; htAttributes[15] = "winter"; htAttributes[16] = "cactus"; htAttributes[17] = "poisonoak"; htAttributes[18] = "dangerousanimals"; htAttributes[19] = "ticks"; htAttributes[20] = "mine"; htAttributes[21] = "cliff"; htAttributes[22] = "hunting"; htAttributes[23] = "danger"; htAttributes[24] = "wheelchair"; htAttributes[25] = "parking"; htAttributes[26] = "public"; htAttributes[27] = "water"; htAttributes[28] = "restrooms"; htAttributes[29] = "phone"; htAttributes[30] = "picnic"; htAttributes[31] = "camping"; htAttributes[32] = "bicycles"; htAttributes[33] = "motorcycles"; htAttributes[34] = "quads"; htAttributes[35] = "jeeps"; htAttributes[36] = "snowmobiles"; htAttributes[37] = "horses"; htAttributes[38] = "campfires"; htAttributes[39] = "thorn"; htAttributes[40] = "stealth"; htAttributes[41] = "stroller"; htAttributes[42] = "firstaid"; htAttributes[43] = "cow"; htAttributes[44] = "flashlight"; htAttributes[45] = "landf"; htAttributes[46] = "rv"; htAttributes[47] = "field_puzzle"; htAttributes[48] = "UV"; htAttributes[49] = "snowshoes"; htAttributes[50] = "skiis"; htAttributes[51] = "s-tool"; htAttributes[52] = "nightcache"; htAttributes[53] = "parkngrab"; htAttributes[54] = "AbandonedBuilding"; htAttributes[55] = "hike_short"; htAttributes[56] = "hike_med"; htAttributes[57] = "hike_long"; htAttributes[58] = "fuel"; htAttributes[59] = "food"; htAttributes[60] = "wirelessbeacon"; htAttributes[61] = "partnership"; htAttributes[62] = "seasonal"; htAttributes[63] = "touristOK"; htAttributes[64] = "treeclimbing"; htAttributes[65] = "frontyard"; htAttributes[66] = "teamwork"; htAttributes[67] = "geotour"; using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_EXPORTINGCB, STR_CREATINGFILE, max, 0, true)) { string cbFile = System.IO.Path.Combine(_folder, "cgeo.sqlite"); string cbDataFile = System.IO.Path.Combine(_folder, "data"); if (System.IO.File.Exists(cbFile)) { System.IO.File.Delete(cbFile); } if (System.IO.File.Exists(cbDataFile)) { System.IO.File.Delete(cbDataFile); } CreateDatabase(cbFile); if (_dbcon != null) { _dbcon.ExecuteNonQuery("CREATE TABLE android_metadata (locale TEXT)"); _dbcon.ExecuteNonQuery("INSERT INTO android_metadata VALUES('en_US')"); //_dbcon.ExecuteNonQuery("CREATE TABLE sqlite_sequence (name, seq)"); DbCommand cmd = _dbcon.Command; int detailed = 1; int reason = 1; int reliable_latlon = 1; DateTime dt = DateTime.Now.AddSeconds(2); foreach (Framework.Data.Geocache gc in _gcList) { //---------------------------- // CACHE //---------------------------- cmd.Parameters.Clear(); cmd.CommandText = "insert into cg_caches (updated, detailed, detailedupdate, visiteddate, geocode, reason, cacheid, guid, type, name, owner, owner_real, hidden, hint, size, difficulty, terrain, latlon, location, latitude, longitude, reliable_latlon, personal_note, shortdesc, description, favourite_cnt, disabled, archived, members, found, coordsChanged, finalDefined) values (@updated, 1, @detailedupdate, @visiteddate, @geocode, @reason, @cacheid, @guid, @type, @name, @owner, @owner_real, @hidden, @hint, @size, @difficulty, @terrain, @latlon, @location, @latitude, @longitude, @reliable_latlon, @personal_note, @shortdesc, @description, @favourite_cnt, @disabled, @archived, @members, @found, @coordsChanged, @finalDefined)"; DbParameter par; par = cmd.CreateParameter(); par.ParameterName = "@updated"; par.DbType = DbType.Int64; par.Value = GetcgeoTime(DateTime.Now); cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@detailed"; par.DbType = DbType.Int32; par.Value = detailed; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@detailedupdate"; par.DbType = DbType.UInt64; par.Value = GetcgeoTime(DateTime.Now); cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@visiteddate"; par.DbType = DbType.UInt64; if (gc.FoundDate == null) { par.Value = 0; } else { par.Value = GetcgeoTime((DateTime)gc.FoundDate); } cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@geocode"; par.DbType = DbType.String; par.Value = gc.Code; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@reason"; par.DbType = DbType.Int32; par.Value = reason; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@cacheid"; par.DbType = DbType.String; if (gc.ID.StartsWith("GC")) { par.Value = Utils.Conversion.GetCacheIDFromCacheCode(gc.Code).ToString(); } else { par.Value = gc.ID; } cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@guid"; par.DbType = DbType.String; par.Value = DBNull.Value; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@type"; par.DbType = DbType.String; par.Value = gc.GeocacheType.GPXTag.Split(new char[] { ' ', '-' })[0].ToLower(); cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@name"; par.DbType = DbType.String; par.Value = gc.Name ?? ""; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@owner"; par.DbType = DbType.String; par.Value = gc.PlacedBy ?? ""; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@owner_real"; par.DbType = DbType.String; par.Value = gc.Owner ?? ""; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@hidden"; par.DbType = DbType.UInt64; par.Value = GetcgeoTime(gc.PublishedTime); cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@hint"; par.DbType = DbType.String; par.Value = gc.EncodedHints ?? ""; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@size"; par.DbType = DbType.String; par.Value = gc.Container.Name.ToLower(); cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@difficulty"; par.DbType = DbType.Single; par.Value = (float)gc.Difficulty; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@terrain"; par.DbType = DbType.Single; par.Value = (float)gc.Terrain; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@latlon"; par.DbType = DbType.String; par.Value = DBNull.Value; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@location"; par.DbType = DbType.String; if (string.IsNullOrEmpty(gc.State)) { par.Value = gc.Country ?? ""; } else { par.Value = string.Format("{0}, {1}", gc.State, gc.Country ?? ""); } cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@latitude"; par.DbType = DbType.Double; par.Value = gc.ContainsCustomLatLon ? gc.CustomLat : gc.Lat; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@longitude"; par.DbType = DbType.Double; par.Value = gc.ContainsCustomLatLon ? gc.CustomLon : gc.Lon; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@reliable_latlon"; par.DbType = DbType.Int32; par.Value = reliable_latlon; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@personal_note"; par.DbType = DbType.String; par.Value = gc.PersonaleNote ?? ""; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@shortdesc"; par.DbType = DbType.String; if (gc.ShortDescriptionInHtml) { par.Value = gc.ShortDescription ?? ""; } else { par.Value = HttpUtility.HtmlEncode(gc.ShortDescription ?? ""); } cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@description"; par.DbType = DbType.String; if (gc.LongDescriptionInHtml) { par.Value = gc.LongDescription ?? ""; } else { par.Value = HttpUtility.HtmlEncode(gc.LongDescription ?? ""); } cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@favourite_cnt"; par.DbType = DbType.Int32; par.Value = gc.Favorites; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@disabled"; par.DbType = DbType.Int32; par.Value = gc.Available ? 0 : 1; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@archived"; par.DbType = DbType.Int32; par.Value = gc.Archived ? 1 : 0; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@members"; par.DbType = DbType.Int32; par.Value = gc.MemberOnly ? 1 : 0; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@found"; par.DbType = DbType.Int32; par.Value = gc.Found ? 1 : 0; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@coordsChanged"; par.DbType = DbType.Int32; par.Value = gc.CustomCoords ? 1 : 0; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@finalDefined"; par.DbType = DbType.Int32; par.Value = 0; cmd.Parameters.Add(par); int res = cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); //---------------------------- // ATTRIBUTES //---------------------------- List <int> attrs = gc.AttributeIds; if (attrs != null && attrs.Count > 0) { cmd.CommandText = "insert into cg_attributes (geocode, updated, attribute) values (@geocode, @updated, @attribute)"; par = cmd.CreateParameter(); par.ParameterName = "@geocode"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@updated"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@attribute"; par.DbType = DbType.String; cmd.Parameters.Add(par); foreach (int att in attrs) { string atname = htAttributes[Math.Abs(att)] as string; if (!string.IsNullOrEmpty(atname)) { atname = atname.ToLower(); cmd.Parameters["@geocode"].Value = gc.Code; cmd.Parameters["@updated"].Value = GetcgeoTime(DateTime.Now); cmd.Parameters["@attribute"].Value = att > 0 ? string.Format("{0}_yes", atname) : string.Format("{0}_no", atname); cmd.ExecuteNonQuery(); } } cmd.Parameters.Clear(); } //---------------------------- // WAYPOINTS //---------------------------- List <Framework.Data.Waypoint> wpts = Utils.DataAccess.GetWaypointsFromGeocache(Core.Waypoints, gc.Code); if (wpts != null && wpts.Count > 0) { cmd.CommandText = "insert into cg_waypoints (geocode, updated, type, prefix, lookup, name, latlon, latitude, longitude, note) values (@geocode, @updated, @type, @prefix, @lookup, @name, @latlon, @latitude, @longitude, @note)"; par = cmd.CreateParameter(); par.ParameterName = "@geocode"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@updated"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@type"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@prefix"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@lookup"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@name"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@latlon"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@latitude"; par.DbType = DbType.Double; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@longitude"; par.DbType = DbType.Double; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@note"; par.DbType = DbType.String; cmd.Parameters.Add(par); foreach (Framework.Data.Waypoint wp in wpts) { if (wp.Lat != null && wp.Lon != null) { cmd.Parameters["@geocode"].Value = gc.Code; cmd.Parameters["@updated"].Value = GetcgeoTime(DateTime.Now); switch (wp.WPType.ID) { case 217: cmd.Parameters["@type"].Value = "pkg"; break; case 220: cmd.Parameters["@type"].Value = "flag"; break; case 218: cmd.Parameters["@type"].Value = "puzzle"; break; case 452: cmd.Parameters["@type"].Value = "waypoint"; break; case 219: cmd.Parameters["@type"].Value = "stage"; break; case 221: cmd.Parameters["@type"].Value = "trailhead"; break; default: cmd.Parameters["@type"].Value = "waypoint"; break; } cmd.Parameters["@prefix"].Value = wp.Code.Substring(0, 2); cmd.Parameters["@lookup"].Value = "---"; cmd.Parameters["@name"].Value = wp.Description ?? ""; cmd.Parameters["@latlon"].Value = Utils.Conversion.GetCoordinatesPresentation((double)wp.Lat, (double)wp.Lon); cmd.Parameters["@latitude"].Value = (double)wp.Lat; cmd.Parameters["@longitude"].Value = (double)wp.Lon; cmd.Parameters["@note"].Value = wp.Comment ?? ""; cmd.ExecuteNonQuery(); } } cmd.Parameters.Clear(); } //---------------------------- // LOGS //---------------------------- List <Framework.Data.Log> lgs = Utils.DataAccess.GetLogs(Core.Logs, gc.Code); if (lgs != null && lgs.Count > 0) { cmd.CommandText = "insert into cg_logs (geocode, updated, type, author, log, date, friend) values (@geocode, @updated, @type, @author, @log, @date, 0)"; par = cmd.CreateParameter(); par.ParameterName = "@geocode"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@updated"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@type"; par.DbType = DbType.Int32; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@author"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@log"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@date"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); foreach (Framework.Data.Log lg in lgs) { cmd.Parameters["@geocode"].Value = gc.Code; cmd.Parameters["@updated"].Value = GetcgeoTime(DateTime.Now); cmd.Parameters["@type"].Value = lg.LogType.ID; cmd.Parameters["@author"].Value = lg.Finder ?? ""; cmd.Parameters["@log"].Value = HttpUtility.HtmlEncode(lg.Text ?? "").Replace("\r", "").Replace("\n", "<br />"); cmd.Parameters["@date"].Value = GetcgeoTime(lg.Date); cmd.ExecuteNonQuery(); } cmd.Parameters.Clear(); } index++; if (DateTime.Now > dt) { if (!progress.UpdateProgress(STR_EXPORTINGCB, STR_CREATINGFILE, max, index)) { break; } dt = DateTime.Now.AddSeconds(2); } } //_dbcon.ExecuteNonQuery(string.Format("insert into sqlite_sequence (name, seq) values ('cg_caches', {0})", index)); _dbcon.Dispose(); _dbcon = null; //not working. you have to go through recover database on c:geo //System.IO.File.Copy(cbFile, cbDataFile); } } }
protected override void ExportMethod() { int max = _gcList.Count * 3; //caches, waypoints, logs int index = 0; using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_EXPORTINGCB, STR_CREATINGFILE, max, 0)) { string cbFile = System.IO.Path.Combine(_folder, "cachebox.db3"); if (System.IO.File.Exists(cbFile)) { System.IO.File.Delete(cbFile); } CreateDatabase(cbFile); if (_dbcon != null) { int fixedCatId = 1; string fixedGpxFilename = "12345678.gpx"; _dbcon.ExecuteNonQuery("PRAGMA user_version = 1022"); _dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "DatabaseSchemeVersion", "1022")); _dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "DatabaseSchemeVersionWin", "1022")); _dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "DatabaseId", DateTime.Now.ToFileTime())); _dbcon.ExecuteNonQuery(string.Format("insert into Config (Key, Value) values ('{0}', '{1}')", "MasterDatabaseId", DateTime.Now.ToFileTime() + 1)); _dbcon.ExecuteNonQuery(string.Format("insert into Category (Id, GpxFilename, Pinned) values ({0}, '{1}', {2})", fixedCatId, fixedGpxFilename, 0)); _dbcon.ExecuteNonQuery(string.Format("insert into GPXFilenames (Id, GpxFilename, Imported, CategoryId) values ({0}, '{1}', '{2}', {3})", 1, fixedGpxFilename, DateTime.Now.ToString("s"), fixedCatId)); //---------------------------- // CACHES //---------------------------- DbCommand cmd = _dbcon.Command; cmd.CommandText = "insert into Caches (Id, GcCode, GcId, Latitude, Longitude, Name, Size, Difficulty, Terrain, Archived, Available, Found, Type, PlacedBy, Owner, DateHidden, Hint, Description, Url, NumTravelbugs, Rating, Vote, VotePending, Notes, Solver, Favorit, AttributesPositive, AttributesNegative, TourName, GPXFilename_Id, HasUserData, ListingChanged, ImagesUpdated, DescriptionImagesUpdated, CorrectedCoordinates, AttributesPositiveHigh, AttributesNegativeHigh, State, Country) values (@Id, @GcCode, @GcId, @Latitude, @Longitude, @Name, @Size, @Difficulty, @Terrain, @Archived, @Available, @Found, @Type, @PlacedBy, @Owner, @DateHidden, @Hint, @Description, @Url, @NumTravelbugs, @Rating, @Vote, @VotePending, @Notes, @Solver, @Favorit, @AttributesPositive, @AttributesNegative, @TourName, @GPXFilename_Id, @HasUserData, @ListingChanged, @ImagesUpdated, @DescriptionImagesUpdated, @CorrectedCoordinates, @AttributesPositiveHigh, @AttributesNegativeHigh, @State, @Country)"; DbParameter par; par = cmd.CreateParameter(); par.ParameterName = "@Id"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@GcCode"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@GcId"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Latitude"; par.DbType = DbType.Single; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Longitude"; par.DbType = DbType.Single; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Name"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Size"; par.DbType = DbType.Int16; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Difficulty"; par.DbType = DbType.Int16; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Terrain"; par.DbType = DbType.Int16; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Archived"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Available"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Found"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Type"; par.DbType = DbType.Int16; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@PlacedBy"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Owner"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@DateHidden"; par.DbType = DbType.DateTime; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Hint"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Description"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Url"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@NumTravelbugs"; par.DbType = DbType.Int16; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Rating"; par.DbType = DbType.Int16; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Vote"; par.DbType = DbType.Int16; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@VotePending"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Notes"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Solver"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Favorit"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@AttributesPositive"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@AttributesNegative"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@TourName"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@GPXFilename_Id"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@HasUserData"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@ListingChanged"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@ImagesUpdated"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@DescriptionImagesUpdated"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@CorrectedCoordinates"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@AttributesPositiveHigh"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@AttributesNegativeHigh"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@State"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Country"; par.DbType = DbType.String; cmd.Parameters.Add(par); long startCacheId = DateTime.Now.ToFileTime() + 2; long cacheId = startCacheId; foreach (Framework.Data.Geocache gc in _gcList) { cmd.Parameters["@Id"].Value = cacheId; cmd.Parameters["@GcCode"].Value = gc.Code; cmd.Parameters["@GcId"].Value = gc.ID; if (gc.ContainsCustomLatLon) { cmd.Parameters["@Latitude"].Value = (float)gc.CustomLat; cmd.Parameters["@Longitude"].Value = (float)gc.CustomLon; } else { cmd.Parameters["@Latitude"].Value = (float)gc.Lat; cmd.Parameters["@Longitude"].Value = (float)gc.Lon; } cmd.Parameters["@Name"].Value = gc.Name ?? ""; switch (gc.Container.ID) { case 2: cmd.Parameters["@Size"].Value = 1; break; case 8: cmd.Parameters["@Size"].Value = 2; break; case 4: cmd.Parameters["@Size"].Value = 3; break; case 5: cmd.Parameters["@Size"].Value = 4; break; default: cmd.Parameters["@Size"].Value = 0; break; } cmd.Parameters["@Difficulty"].Value = (Int16)(gc.Difficulty * 2.0); cmd.Parameters["@Terrain"].Value = (Int16)(gc.Terrain * 2.0); cmd.Parameters["@Archived"].Value = gc.Archived; cmd.Parameters["@Available"].Value = gc.Available; cmd.Parameters["@Found"].Value = gc.Found; switch (gc.GeocacheType.ID) { case 2: cmd.Parameters["@Type"].Value = 0; break; case 3: cmd.Parameters["@Type"].Value = 1; break; case 4: cmd.Parameters["@Type"].Value = 8; break; case 5: cmd.Parameters["@Type"].Value = 9; break; case 6: cmd.Parameters["@Type"].Value = 5; break; case 8: cmd.Parameters["@Type"].Value = 2; break; case 11: cmd.Parameters["@Type"].Value = 3; break; case 13: cmd.Parameters["@Type"].Value = 7; break; case 137: cmd.Parameters["@Type"].Value = 4; break; case 453: cmd.Parameters["@Type"].Value = 6; break; case 1858: cmd.Parameters["@Type"].Value = 10; break; default: cmd.Parameters["@Type"].Value = 13; break; } cmd.Parameters["@PlacedBy"].Value = gc.PlacedBy ?? ""; cmd.Parameters["@Owner"].Value = gc.Owner ?? ""; cmd.Parameters["@DateHidden"].Value = gc.PublishedTime; cmd.Parameters["@Hint"].Value = gc.EncodedHints ?? ""; StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(gc.ShortDescription)) { if (gc.ShortDescriptionInHtml) { sb.Append(gc.ShortDescription); } else { sb.Append(HttpUtility.HtmlEncode(gc.ShortDescription).Replace("\r", "").Replace("\n", "<br />")); } sb.Append("<br />"); } if (!string.IsNullOrEmpty(gc.LongDescription)) { if (gc.LongDescriptionInHtml) { sb.Append(gc.LongDescription); } else { sb.Append(HttpUtility.HtmlEncode(gc.LongDescription).Replace("\r", "").Replace("\n", "<br />")); } } cmd.Parameters["@Description"].Value = sb.ToString(); cmd.Parameters["@Url"].Value = gc.Url ?? ""; cmd.Parameters["@NumTravelbugs"].Value = 0; cmd.Parameters["@Rating"].Value = 0; cmd.Parameters["@Vote"].Value = 0; cmd.Parameters["@VotePending"].Value = false; sb.Length = 0; if (gc.ContainsNote) { if (!string.IsNullOrEmpty(gc.PersonaleNote)) { sb.Append(gc.PersonaleNote); sb.Append(" - "); } if (!string.IsNullOrEmpty(gc.Notes)) { sb.Append(Utils.Conversion.StripHtmlTags(gc.Notes)); } } cmd.Parameters["@Notes"].Value = sb.Length; cmd.Parameters["@Solver"].Value = ""; cmd.Parameters["@Favorit"].Value = false; DLong tmpAttributesNegative = new DLong(0, 0); DLong tmpAttributesPositive = new DLong(0, 0); List <int> attrs = gc.AttributeIds; foreach (int ix in attrs) { if (ix > 0) { tmpAttributesPositive.BitOr(Attributes.GetAttributeDlong(Attributes.getAttributeEnumByGcComId(ix).Attribute)); } else { tmpAttributesNegative.BitOr(Attributes.GetAttributeDlong(Attributes.getAttributeEnumByGcComId(-ix).Attribute)); } } long AttributePositiveLow = (long)tmpAttributesPositive.getLow(); long AttributePositiveHigh = (long)tmpAttributesPositive.getHigh(); long AttributesNegativeLow = (long)tmpAttributesNegative.getLow(); long AttributesNegativeHigh = (long)tmpAttributesNegative.getHigh(); cmd.Parameters["@AttributesPositive"].Value = AttributePositiveLow; cmd.Parameters["@AttributesNegative"].Value = AttributesNegativeLow; cmd.Parameters["@AttributesPositiveHigh"].Value = AttributePositiveHigh; cmd.Parameters["@AttributesNegativeHigh"].Value = AttributesNegativeHigh; cmd.Parameters["@TourName"].Value = ""; cmd.Parameters["@AttributesNegative"].Value = 1; cmd.Parameters["@HasUserData"].Value = false; cmd.Parameters["@ListingChanged"].Value = false; cmd.Parameters["@ImagesUpdated"].Value = false; cmd.Parameters["@DescriptionImagesUpdated"].Value = false; cmd.Parameters["@CorrectedCoordinates"].Value = false; cmd.Parameters["@State"].Value = gc.State ?? ""; cmd.Parameters["@Country"].Value = gc.Country ?? ""; cmd.ExecuteNonQuery(); cacheId++; index++; if (index % 200 == 0) { progress.UpdateProgress(STR_EXPORTINGCB, STR_CREATINGFILE, max, index); } } //---------------------------- // WAYPOINTS //---------------------------- cmd.Parameters.Clear(); cmd.CommandText = "insert into Waypoint (GcCode, CacheId, Latitude, Longitude, Description, Clue, Type, SyncExclude, UserWaypoint, Title) values (@GcCode, @CacheId, @Latitude, @Longitude, @Description, @Clue, @Type, @SyncExclude, @UserWaypoint, @Title)"; par = cmd.CreateParameter(); par.ParameterName = "@GcCode"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@CacheId"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Latitude"; par.DbType = DbType.Single; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Longitude"; par.DbType = DbType.Single; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Description"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Clue"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Type"; par.DbType = DbType.Int16; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@SyncExclude"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@UserWaypoint"; par.DbType = DbType.Boolean; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Title"; par.DbType = DbType.String; cmd.Parameters.Add(par); cacheId = startCacheId; foreach (Framework.Data.Geocache gc in _gcList) { List <Framework.Data.Waypoint> wps = Utils.DataAccess.GetWaypointsFromGeocache(Core.Waypoints, gc.Code); if (wps != null && wps.Count > 0) { foreach (Framework.Data.Waypoint wp in wps) { if (wp.Lat != null && wp.Lon != null) { cmd.Parameters["@GcCode"].Value = wp.Code; cmd.Parameters["@CacheId"].Value = cacheId; cmd.Parameters["@Latitude"].Value = (float)(double)wp.Lat; cmd.Parameters["@Longitude"].Value = (float)(double)wp.Lon; cmd.Parameters["@Description"].Value = wp.Comment ?? ""; cmd.Parameters["@Clue"].Value = ""; switch (wp.WPType.ID) { case 217: cmd.Parameters["@Type"].Value = 17; break; case 220: cmd.Parameters["@Type"].Value = 18; break; case 218: cmd.Parameters["@Type"].Value = 15; break; case 452: cmd.Parameters["@Type"].Value = 11; break; case 219: cmd.Parameters["@Type"].Value = 14; break; case 221: cmd.Parameters["@Type"].Value = 16; break; default: cmd.Parameters["@Type"].Value = 13; break; } cmd.Parameters["@SyncExclude"].Value = false; cmd.Parameters["@UserWaypoint"].Value = string.IsNullOrEmpty(wp.Url) || !wp.Url.ToLower().StartsWith("http:"); cmd.Parameters["@Title"].Value = wp.Description ?? ""; cmd.ExecuteNonQuery(); } } } cacheId++; index++; if (index % 200 == 0) { progress.UpdateProgress(STR_EXPORTINGCB, STR_CREATINGFILE, max, index); } } //---------------------------- // LOGS //---------------------------- if (PluginSettings.Instance.MaxLogs > 0) { cmd.Parameters.Clear(); cmd.CommandText = "insert into Logs (Id, CacheId, Timestamp, Finder, Type, Comment) values (@Id, @CacheId, @Timestamp, @Finder, @Type, @Comment)"; par = cmd.CreateParameter(); par.ParameterName = "@Id"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@CacheId"; par.DbType = DbType.Int64; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Timestamp"; par.DbType = DbType.DateTime; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Finder"; par.DbType = DbType.String; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Type"; par.DbType = DbType.Int16; cmd.Parameters.Add(par); par = cmd.CreateParameter(); par.ParameterName = "@Comment"; par.DbType = DbType.String; cmd.Parameters.Add(par); long logId = 1; cacheId = startCacheId; foreach (Framework.Data.Geocache gc in _gcList) { List <Framework.Data.Log> logs = Utils.DataAccess.GetLogs(Core.Logs, gc.Code).Take(PluginSettings.Instance.MaxLogs).ToList(); if (logs != null && logs.Count > 0) { logs = logs.Take(PluginSettings.Instance.MaxLogs).ToList(); foreach (Framework.Data.Log lg in logs) { long id = logId; if (lg.ID.StartsWith("GL")) { id = Utils.Conversion.GetCacheIDFromCacheCode(lg.ID); } else { long.TryParse(lg.ID, out id); } cmd.Parameters["@Id"].Value = id; cmd.Parameters["@CacheId"].Value = cacheId; cmd.Parameters["@Timestamp"].Value = lg.Date; cmd.Parameters["@Finder"].Value = lg.Finder ?? ""; switch (lg.LogType.ID) { case 2: cmd.Parameters["@Type"].Value = 0; break; case 3: cmd.Parameters["@Type"].Value = 1; break; case 4: cmd.Parameters["@Type"].Value = 2; break; case 24: cmd.Parameters["@Type"].Value = 3; break; case 23: cmd.Parameters["@Type"].Value = 4; break; case 45: cmd.Parameters["@Type"].Value = 5; break; case 22: cmd.Parameters["@Type"].Value = 6; break; case 46: case 47: cmd.Parameters["@Type"].Value = 7; break; case 9: cmd.Parameters["@Type"].Value = 8; break; case 10: cmd.Parameters["@Type"].Value = 9; break; case 11: cmd.Parameters["@Type"].Value = 10; break; case 5: case 6: case 12: cmd.Parameters["@Type"].Value = 11; break; case 18: cmd.Parameters["@Type"].Value = 12; break; case 7: cmd.Parameters["@Type"].Value = 13; break; default: cmd.Parameters["@Type"].Value = 2; break; } cmd.Parameters["@Comment"].Value = lg.Text ?? ""; cmd.ExecuteNonQuery(); } } cacheId++; index++; if (index % 200 == 0) { progress.UpdateProgress(STR_EXPORTINGCB, STR_CREATINGFILE, max, index); } } } _dbcon.Dispose(); } } }