示例#1
0
        private void readGeocacheData(RecordInfo ri, MemoryStream ms, BinaryReader br)
        {
            _geocachesInDB.Add(ri.ID, ri);
            Framework.Data.Geocache gc = new Framework.Data.Geocache();
            gc.Code = ri.ID;

            //read data
            gc.Archived = br.ReadBoolean();
            gc.Available = br.ReadBoolean();
            gc.Container = Utils.DataAccess.GetGeocacheContainer(Core.GeocacheContainers, br.ReadInt32());
            gc.DataFromDate = DateTimeFromLong(br.ReadInt64());
            gc.PublishedTime = DateTimeFromLong(br.ReadInt64());
            gc.Difficulty = br.ReadDouble();
            gc.Terrain = br.ReadDouble();
            gc.Favorites = br.ReadInt32();
            gc.Flagged = br.ReadBoolean();
            gc.Found = br.ReadBoolean();
            gc.GeocacheType = Utils.DataAccess.GetGeocacheType(Core.GeocacheTypes, br.ReadInt32());
            gc.Lat = br.ReadDouble();
            gc.Lon = br.ReadDouble();
            gc.Locked = br.ReadBoolean();
            if (br.ReadBoolean())
            {
                gc.CustomLat = br.ReadDouble();
                gc.CustomLon = br.ReadDouble();
            }
            else
            {
                gc.CustomLat = null;
                gc.CustomLon = null;
                br.ReadDouble();
                br.ReadDouble();
            }
            gc.MemberOnly = br.ReadBoolean();
            List<int> attrList = new List<int>();
            int cnt = br.ReadByte();
            for (int i = 0; i < cnt; i++)
            {
                attrList.Add(br.ReadInt32());
            }
            gc.AttributeIds = attrList;

            ms.Position = 300;
            gc.City = br.ReadString();
            ms.Position = 400;
            gc.Country = br.ReadString();
            ms.Position = 500;
            gc.EncodedHints = br.ReadString();
            ms.Position = 1000;
            gc.Municipality = br.ReadString();
            ms.Position = 1100;
            gc.Name = br.ReadString();
            ms.Position = 1200; //spare now
            gc.Notes = br.ReadString();
            ms.Position = 2000;
            gc.Owner = br.ReadString();
            ms.Position = 2100;
            gc.OwnerId = br.ReadString();
            ms.Position = 2150;
            gc.PersonaleNote = br.ReadString();
            ms.Position = 2400;
            gc.PlacedBy = br.ReadString();
            ms.Position = 2500;
            gc.State = br.ReadString();
            ms.Position = 2600;
            gc.Url = br.ReadString();
            //ms.Position = 3000;
            //gc.LongDescriptionInHtml = br.ReadBoolean();
            //gc.ShortDescriptionInHtml = br.ReadBoolean();
            //gc.ShortDescription = br.ReadString();
            //gc.LongDescription = br.ReadString();

            Calculus.SetDistanceAndAngleGeocacheFromLocation(gc, Core.CenterLocation);
            gc.Saved = true;
            gc.IsDataChanged = false;
            Core.Geocaches.Add(gc);
        }
示例#2
0
        private void readWaypointData(RecordInfo ri, MemoryStream ms, BinaryReader br)
        {
            _wptsInDB.Add(ri.ID, ri);
            Framework.Data.Waypoint wp = new Framework.Data.Waypoint();
            wp.Code = ri.ID;
            //wp.GeocacheCode = ri.SubID;

            wp.DataFromDate = DateTimeFromLong(br.ReadInt64());
            if (br.ReadBoolean())
            {
                wp.Lat = br.ReadDouble();
            }
            else
            {
                wp.Lat = null;
                br.ReadDouble();
            }
            if (br.ReadBoolean())
            {
                wp.Lon = br.ReadDouble();
            }
            else
            {
                wp.Lon = null;
                br.ReadDouble();
            }
            wp.Time = DateTimeFromLong(br.ReadInt64());
            wp.WPType = Utils.DataAccess.GetWaypointType(Core.WaypointTypes, br.ReadInt32());

            ms.Position = 200;
            wp.GeocacheCode = br.ReadString();
            ms.Position = 240;
            wp.Code = br.ReadString();
            ms.Position = 280;
            wp.Description = br.ReadString();
            ms.Position = 500;
            wp.Name = br.ReadString();
            ms.Position = 600;
            wp.Url = br.ReadString();
            ms.Position = 700;
            wp.UrlName = br.ReadString();
            ms.Position = 800;
            wp.Comment = br.ReadString();

            wp.Saved = true;
            wp.IsDataChanged = false;
            Core.Waypoints.Add(wp);
        }
示例#3
0
        private void readLogData(RecordInfo ri, MemoryStream ms, BinaryReader br)
        {
            _logsInDB.Add(ri.ID, ri);
            Framework.Data.Log l = new Framework.Data.Log();
            l.ID = ri.ID;
            //l.GeocacheCode = ri.SubID;

            l.LogType = Utils.DataAccess.GetLogType(Core.LogTypes, br.ReadInt32());
            l.Date = DateTimeFromLong(br.ReadInt64());
            l.DataFromDate = DateTimeFromLong(br.ReadInt64());
            //l.Encoded = br.ReadBoolean();
            ms.Position = 180;
            l.GeocacheCode = br.ReadString();
            ms.Position = 220;
            l.Finder = br.ReadString();
            //ms.Position = 320;
            //l.FinderId = br.ReadString();
            //ms.Position = 350;
            //l.TBCode = br.ReadString();
            //ms.Position = 380;
            //l.Text = br.ReadString();

            l.Saved = true;
            l.IsDataChanged = false;
            Core.Logs.Add(l);
        }
示例#4
0
        private void readUserWaypointData(RecordInfo ri, MemoryStream ms, BinaryReader br)
        {
            _usrwptsInDB.Add(ri.ID, ri);
            Framework.Data.UserWaypoint wp = new Framework.Data.UserWaypoint();
            wp.ID = int.Parse(ri.ID);
            //wp.GeocacheCode = ri.SubID;

            wp.Date = DateTimeFromLong(br.ReadInt64());
            wp.Lat = br.ReadDouble();
            wp.Lon = br.ReadDouble();
            ms.Position = 200;
            wp.GeocacheCode = br.ReadString();
            ms.Position = 220;
            wp.Description = br.ReadString();

            wp.Saved = true;
            wp.IsDataChanged = false;
            Core.UserWaypoints.Add(wp);
        }
示例#5
0
        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);
        }
示例#6
0
        private void readGeocacheImageData(RecordInfo ri, MemoryStream ms, BinaryReader br)
        {
            _geocacheimgsInDB.Add(ri.ID, ri);
            Framework.Data.GeocacheImage l = new Framework.Data.GeocacheImage();
            l.ID = ri.ID;

            l.DataFromDate = DateTimeFromLong(br.ReadInt64());
            l.GeocacheCode = br.ReadString();
            ms.Position = 220;
            l.Url = br.ReadString();
            ms.Position = 420;
            l.MobileUrl = br.ReadString();
            ms.Position = 520;
            l.ThumbUrl = br.ReadString();
            ms.Position = 620;
            l.Name = br.ReadString();
            ms.Position = 800;
            l.Description = br.ReadString();

            l.Saved = true;
            l.IsDataChanged = false;
            Core.GeocacheImages.Add(l);
        }
示例#7
0
        public override bool Load(bool geocachesOnly)
        {
            bool result = true;
            if (File.Exists(PluginSettings.Instance.ActiveDataFile))
            {
                closeCurrentFile();
                _fileStream = File.Open(PluginSettings.Instance.ActiveDataFile, FileMode.Open, FileAccess.ReadWrite);
                if (_fileStream.Length==0)
                {
                    BinaryWriter fbw = new BinaryWriter(_fileStream);
                    //create meta data
                    _fileStream.SetLength(DATABASE_CONTENT_OFFSET);
                    _fileStream.Position = DATABASE_META_VERSION_POS;
                    long v = 1;
                    fbw.Write(v);
                    _fileStream.Position = DATABASE_META_ACTIVEGEOCACHE_POS;
                    fbw.Write("");
                }
                else
                {
                    //read meta data
                    BinaryReader fbw = new BinaryReader(_fileStream);
                    _fileStream.Position = DATABASE_META_VERSION_POS;
                    long v;
                    v= fbw.ReadInt64();
                    if (v!=1)
                    {
                        _fileStream.Dispose();
                        _fileStream = null;
                        throw new Exception("Not supported file version");
                    }
                }
                if (_fileStream.Length > DATABASE_CONTENT_OFFSET)
                {
                    BinaryReader fbr = new BinaryReader(_fileStream);
                    byte[] buffer = new byte[10000000];
                    using (MemoryStream ms = new MemoryStream(buffer))
                    using (BinaryReader br = new BinaryReader(ms))
                    {
                        long max = _fileStream.Length;
                        DateTime nextUpdate = DateTime.Now.AddSeconds(1);
                        using (Utils.ProgressBlock prog = new Utils.ProgressBlock(this, STR_LOADING, STR_LOADINGDATA, 100, 0))
                        {
                            _fileStream.Position = DATABASE_CONTENT_OFFSET;
                            long eof = _fileStream.Length;
                            while (_fileStream.Position < eof)
                            {
                                RecordInfo ri = new RecordInfo();
                                ri.Offset = _fileStream.Position;
                                _fileStream.Position = ri.Offset + RECORD_POS_LENGTH;
                                ri.Length = fbr.ReadInt64();
                                _fileStream.Position = ri.Offset + RECORD_POS_FIELDTYPE;
                                ri.FieldType = fbr.ReadByte();
                                if (ri.FieldType == RECORD_EMPTY)
                                {
                                    _emptyRecords.Add(ri);
                                    _emptyRecordsSorted = false;
                                }
                                else
                                {
                                    _fileStream.Position = ri.Offset + RECORD_POS_ID;
                                    ri.ID = fbr.ReadString();
                                    ri.SubID = fbr.ReadString();
                                    _fileStream.Position = ri.Offset + 150;
                                    _fileStream.Read(buffer, 150, (int)(ri.Length - 150));
                                    ms.Position = 150;
                                    switch (ri.FieldType)
                                    {
                                        case RECORD_GEOCACHE:
                                            readGeocacheData(ri, ms, br);
                                            break;
                                        case RECORD_LOG:
                                            readLogData(ri, ms, br);
                                            break;
                                        case RECORD_WAYPOINT:
                                            readWaypointData(ri, ms, br);
                                            break;
                                        case RECORD_USERWAYPOINT:
                                            readUserWaypointData(ri, ms, br);
                                            break;
                                        case RECORD_LOGIMAGE:
                                            readLogImageData(ri, ms, br);
                                            break;
                                        case RECORD_GEOCACHEIMAGE:
                                            readGeocacheImageData(ri, ms, br);
                                            break;
                                    }
                                }
                                _fileStream.Position = ri.Offset + ri.Length;

                                if (DateTime.Now >= nextUpdate)
                                {
                                    prog.UpdateProgress(STR_LOADING, STR_LOADINGDATA, 100, (int)(100.0 * (double)_fileStream.Position / (double)max));
                                    nextUpdate = DateTime.Now.AddSeconds(1);
                                }
                            }
                        }
                    }
                }
            }
            return result;
        }
示例#8
0
        private RecordInfo RequestRecord(FileStream fileStream, string id, string subId, byte recordType, byte[] recordData, long minimumLength, long extraBuffer)
        {
            RecordInfo result = null;
            if (!_emptyRecordsSorted)
            {
                _emptyRecords.Sort(delegate(RecordInfo x, RecordInfo y)
                {
                    return x.Length.CompareTo(y.Length);
                });
                _emptyRecordsSorted = true;
            }
            result = (from a in _emptyRecords where a.Length >= minimumLength select a).FirstOrDefault();

            if (result == null)
            {
                result = new RecordInfo();
                result.Length = minimumLength + extraBuffer;
                result.Offset = _fileStream.Length;
                result.ID = id;
                result.SubID = subId;
                result.FieldType = recordType;
                fileStream.SetLength(result.Offset + result.Length);
            }
            else
            {
                //re-use of an empty record
                result.ID = id;
                result.SubID = subId;
                _emptyRecords.Remove(result);
                result.FieldType = recordType;
            }
            //write record header data
            BinaryWriter bw = new BinaryWriter(_fileStream);
            fileStream.Position = result.Offset + RECORD_POS_LENGTH;
            bw.Write(result.Length);
            fileStream.Position = result.Offset + RECORD_POS_FIELDTYPE;
            fileStream.WriteByte(recordType);
            fileStream.Position = result.Offset + RECORD_POS_ID;
            bw.Write(result.ID);
            bw.Write(result.SubID);

            //write data
            fileStream.Position = result.Offset + 150;
            fileStream.Write(recordData, 150, (int)minimumLength - 150);

            //Flush();

            return result;
        }