public static void Copy(IGeocacheData src, IGeocacheData dest) { dest.Code = src.Code; dest.Name = src.Name; dest.DataFromDate = src.DataFromDate; dest.PublishedTime = src.PublishedTime; dest.Lat = src.Lat; dest.Lon = src.Lon; dest.CustomLat = src.CustomLat; dest.CustomLon = src.CustomLon; dest.Available = src.Available; dest.Archived = src.Archived; dest.Country = src.Country; dest.State = src.State; dest.Municipality = src.Municipality; dest.City = src.City; dest.GeocacheType = src.GeocacheType; dest.PlacedBy = src.PlacedBy; dest.Owner = src.Owner; dest.OwnerId = src.OwnerId; dest.Container = src.Container; dest.Terrain = src.Terrain; dest.Difficulty = src.Difficulty; dest.ShortDescription = src.ShortDescription; dest.ShortDescriptionInHtml = src.ShortDescriptionInHtml; dest.LongDescription = src.LongDescription; dest.LongDescriptionInHtml = src.LongDescriptionInHtml; dest.EncodedHints = src.EncodedHints; dest.Url = src.Url; dest.MemberOnly = src.MemberOnly; if (src.AttributeIds == null) { dest.AttributeIds = null; } else { dest.AttributeIds = (from a in src.AttributeIds select a).ToList(); } dest.Favorites = src.Favorites; dest.PersonalNote = src.PersonalNote; dest.Notes = src.Notes; dest.Flagged = src.Flagged; dest.Found = src.Found; dest.Locked = src.Locked; }
//new record to be stored public Geocache(Storage.Database db, IGeocacheData data) : base(null) { _code = data.Code; using (MemoryStream ms = new MemoryStream(_buffer)) using (BinaryWriter bw = new BinaryWriter(ms)) { ms.Position = 0; //todo: add string length checks!!! ms.Position = 150; bw.Write(data.Archived); //150 bw.Write(data.Available); //151 bw.Write(data.Container == null ? 0 : data.Container.ID); //152 bw.Write(data.DataFromDate.ToFileTime()); //156 bw.Write(data.PublishedTime.ToFileTime()); //164 bw.Write(data.Difficulty); //172 bw.Write(data.Terrain); //180 bw.Write(data.Favorites); //188 bw.Write(data.Flagged); //192 bw.Write(data.Found); //193 bw.Write(data.GeocacheType == null ? 0 : data.GeocacheType.ID); //194 bw.Write(data.Lat); //198 bw.Write(data.Lon); //206 bw.Write(data.Locked); //214 bw.Write(data.CustomLat != null); //215 if (data.CustomLat != null) { bw.Write((double)data.CustomLat); //216 } else { bw.Write((double)0.0); } bw.Write(data.CustomLon != null); //224 if (data.CustomLon != null) { bw.Write((double)data.CustomLon); //225 } else { bw.Write((double)0.0); } bw.Write(data.MemberOnly); byte attrCount = (byte)(data.AttributeIds == null ? 0 : data.AttributeIds.Count); bw.Write(attrCount); //234 if (attrCount > 0) { foreach (int i in data.AttributeIds) { bw.Write(i); } } ms.Position = 300; bw.Write(data.City ?? ""); ms.Position = 400; bw.Write(data.Country ?? ""); ms.Position = 500; bw.Write(data.EncodedHints ?? ""); ms.Position = 1000; bw.Write(data.Municipality ?? ""); ms.Position = 1100; bw.Write(data.Name ?? ""); ms.Position = 1200; bw.Write(data.Notes ?? ""); ms.Position = 2000; bw.Write(data.Owner ?? ""); ms.Position = 2100; bw.Write(data.OwnerId ?? ""); ms.Position = 2150; bw.Write(data.PersonalNote ?? ""); ms.Position = 2400; bw.Write(data.PlacedBy ?? ""); ms.Position = 2500; bw.Write(data.State ?? ""); ms.Position = 2600; bw.Write(data.Url ?? ""); //spare ms.Position = 3000; bw.Write(data.LongDescriptionInHtml); //3000 bw.Write(data.ShortDescriptionInHtml); //3001 //read both if needs description! bw.Write(data.ShortDescription); //3002 bw.Write(data.LongDescription); RecordInfo = db.RequestGeocacheRecord(data.Code, _buffer, ms.Position, 500); } db.GeocacheCollection.Add(this); }
private void createRecord(Storage.Database db, IGeocacheData data) { using (MemoryStream ms = new MemoryStream(DataBuffer)) using (BinaryWriter bw = new BinaryWriter(ms)) { ms.Position = 0; ms.Position = 150; bw.Write(data.Archived); //150 bw.Write(data.Available); //151 bw.Write(data.Container == null ? 0 : data.Container.ID); //152 bw.Write(Utils.Conversion.DateTimeToLong(data.DataFromDate)); //156 bw.Write(Utils.Conversion.DateTimeToLong(data.PublishedTime)); //164 bw.Write(data.Difficulty); //172 bw.Write(data.Terrain); //180 bw.Write(data.Favorites); //188 bw.Write(data.Flagged); //192 bw.Write(data.Found); //193 bw.Write(data.GeocacheType == null ? 0 : data.GeocacheType.ID); //194 bw.Write(data.Lat); //198 bw.Write(data.Lon); //206 bw.Write(data.Locked); //214 bw.Write(data.CustomLat != null); //215 if (data.CustomLat != null) { bw.Write((double)data.CustomLat); //216 } else { bw.Write((double)0.0); } bw.Write(data.CustomLon != null); //224 if (data.CustomLon != null) { bw.Write((double)data.CustomLon); //225 } else { bw.Write((double)0.0); } bw.Write(data.MemberOnly); byte attrCount = (byte)(data.AttributeIds == null ? 0 : data.AttributeIds.Count); bw.Write(attrCount); //234 if (attrCount > 0) { foreach (int i in data.AttributeIds) { bw.Write(i); } } ms.Position = 300; bw.Write(GetSafeString(300, 400, data.City) ?? ""); ms.Position = 400; bw.Write(GetSafeString(400, 500, data.Country) ?? ""); ms.Position = 500; bw.Write(GetSafeString(500, 1000, data.EncodedHints) ?? ""); ms.Position = 1000; bw.Write(GetSafeString(1000, 1100, data.Municipality) ?? ""); ms.Position = 1100; bw.Write(GetSafeString(1100, 1200, data.Name) ?? ""); ms.Position = 1200; //spare now //bw.Write(GetSafeString(1200, 2000, data.Notes) ?? ""); bw.Write(""); //do not overwrite note if note is not set (e.g. import GPX) if (!string.IsNullOrEmpty(data.Notes)) { Core.Settings.Default.SetGeocacheNotes(data.Code, data.Notes); } ms.Position = 2000; bw.Write(GetSafeString(2000, 2100, data.Owner) ?? ""); ms.Position = 2100; bw.Write(GetSafeString(2100, 2150, data.OwnerId) ?? ""); ms.Position = 2150; bw.Write(GetSafeString(2150, 2400, data.PersonalNote) ?? ""); ms.Position = 2400; bw.Write(GetSafeString(2400, 2500, data.PlacedBy) ?? ""); ms.Position = 2500; bw.Write(GetSafeString(2500, 2600, data.State) ?? ""); ms.Position = 2600; bw.Write(GetSafeString(2600, 2800, data.Url) ?? ""); //spare ms.Position = 3000; bw.Write(data.LongDescriptionInHtml); //3000 bw.Write(data.ShortDescriptionInHtml); //3001 //read both if needs description! bw.Write(data.ShortDescription ?? ""); //3002 bw.Write(data.LongDescription ?? ""); RecordInfo = db.RequestGeocacheRecord(data.Code, "", DataBuffer, ms.Position, 500); } }
//new record to be stored public Geocache(Storage.Database db, IGeocacheData data) : this(null) { createRecord(db, data); db.GeocacheCollection.Add(this); }