示例#1
0
        /// <summary>
        /// reads an OnDiscAdress from the index.
        /// </summary>
        /// <param name="NumberOfAdress">is the number of the OnDiscAdress to be read</param>
        /// <returns></returns>
        public OnDiscAdress ReadOnDiscAdress(long NumberOfAdress)
        {
            //byte[] Readin;
            lock (DatabaseIndexFile)
            {
                // check if this is even possible...
                if (DatabaseIndexFile.Length <= NumberOfAdress * 33)
                {
                    return(null);
                }

                // seek to the multiple of NumberOfAdress
                DatabaseIndexFile.Seek(NumberOfAdress * 33, SeekOrigin.Begin);

                byte[]       _SerializedData;
                OnDiscAdress _deserializedAdress;

                try
                {
                    _SerializedData = new byte[33];
                    // todo: maybe a read cache might be great, to read more bytes sequential
                    DatabaseIndexFile.Read(_SerializedData, 0, 33);

                    _deserializedAdress = new OnDiscAdress();
                    _reader.Data        = _SerializedData;
                    _deserializedAdress.Deserialize(ref _reader);

                    return(_deserializedAdress);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
示例#2
0
        /// <summary>
        /// writes a new chunk of data to the disk (and index)
        /// </summary>
        /// <param name="Data">the byte array with the data</param>
        public void Write(byte[] Data)
        {
            // write the data to the database file
            OnDiscAdress adress = WriteToDatabase(Data);

            // and the adress to the index
            WriteToIndex(adress);
        }
示例#3
0
文件: AppendLog.cs 项目: loubo/sones
        public byte[] ReadData(OnDiscAdress Adress)
        {
            byte[] Readin;

            lock (DatabaseFile)
            {
                // seek to the position
                DatabaseFile.Seek(Adress.Start, SeekOrigin.Begin);
                Readin = new byte[Adress.End - Adress.Start];
                // read it in
                DatabaseFile.Read(Readin, 0, Readin.Length);
            }
            return Readin;
        }
示例#4
0
        public byte[] ReadData(OnDiscAdress Adress)
        {
            byte[] Readin;

            lock (DatabaseFile)
            {
                // seek to the position
                DatabaseFile.Seek(Adress.Start, SeekOrigin.Begin);
                Readin = new byte[Adress.End - Adress.Start];
                // read it in
                DatabaseFile.Read(Readin, 0, Readin.Length);
            }
            return(Readin);
        }
示例#5
0
        private void WriteToIndex(OnDiscAdress Adresspattern)
        {
            lock (DatabaseIndexFile)
            {
                // seek to the end...
                DatabaseIndexFile.Seek(DatabaseIndexFile.Length, SeekOrigin.Begin);
                // re-use the writer
                _writer.ResetBuffer();
                // serialize the index...
                byte[] ToWrite = Adresspattern.SerializeAligned(ref _writer);

                DatabaseIndexFile.Write(ToWrite, 0, ToWrite.Length);
                if (FlushOnWrite)
                {
                    DatabaseIndexFile.Flush();
                }
            }
        }
示例#6
0
        private OnDiscAdress WriteToDatabase(byte[] ToWrite)
        {
            OnDiscAdress OutputAdress = new OnDiscAdress();

            lock (DatabaseFile)
            {
                // seek to the end...
                DatabaseFile.Seek(DatabaseFile.Length, SeekOrigin.Begin);
                OutputAdress.Start = DatabaseFile.Position;
                DatabaseFile.Write(ToWrite, 0, ToWrite.Length);
                OutputAdress.End = DatabaseFile.Position;

                if (FlushOnWrite)
                {
                    DatabaseFile.Flush();
                }
            }
            return(OutputAdress);
        }
示例#7
0
文件: AppendLog.cs 项目: loubo/sones
        private void WriteToIndex(OnDiscAdress Adresspattern)
        {
            lock (DatabaseIndexFile)
            {
                // seek to the end...
                DatabaseIndexFile.Seek(DatabaseIndexFile.Length, SeekOrigin.Begin);
                // re-use the writer
                _writer.ResetBuffer();
                // serialize the index...
                byte[] ToWrite = Adresspattern.SerializeAligned(ref _writer);

                DatabaseIndexFile.Write(ToWrite, 0, ToWrite.Length);
                if (FlushOnWrite)
                    DatabaseIndexFile.Flush();
            }
        }
示例#8
0
文件: AppendLog.cs 项目: loubo/sones
        private OnDiscAdress WriteToDatabase(byte[] ToWrite)
        {
            OnDiscAdress OutputAdress = new OnDiscAdress();

            lock (DatabaseFile)
            {
                // seek to the end...
                DatabaseFile.Seek(DatabaseFile.Length, SeekOrigin.Begin);
                OutputAdress.Start = DatabaseFile.Position;
                DatabaseFile.Write(ToWrite, 0, ToWrite.Length);
                OutputAdress.End = DatabaseFile.Position;

                if (FlushOnWrite)
                    DatabaseFile.Flush();
            }
            return OutputAdress;
        }
示例#9
0
文件: AppendLog.cs 项目: loubo/sones
        /// <summary>
        /// reads an OnDiscAdress from the index. 
        /// </summary>
        /// <param name="NumberOfAdress">is the number of the OnDiscAdress to be read</param>
        /// <returns></returns>
        public OnDiscAdress ReadOnDiscAdress(long NumberOfAdress)
        {
            byte[] Readin;
            lock (DatabaseIndexFile)
            {
                // check if this is even possible...
                if (DatabaseIndexFile.Length <= NumberOfAdress * 33)
                    return null;

                // seek to the multiple of NumberOfAdress
                DatabaseIndexFile.Seek(NumberOfAdress * 33, SeekOrigin.Begin);

                byte[] _SerializedData;
                OnDiscAdress _deserializedAdress;

                try
                {
                    _SerializedData = new byte[33];
                    // todo: maybe a read cache might be great, to read more bytes sequential
                    DatabaseIndexFile.Read(_SerializedData, 0, 33);

                    _deserializedAdress = new OnDiscAdress();
                    _reader.Data = _SerializedData;
                    _deserializedAdress.Deserialize(ref _reader);

                    return _deserializedAdress;
                }
                catch (Exception)
                {
                    return null;
                }
            }
        }