예제 #1
0
        internal void Open(long taskId)
        {
            this.Name     = "t" + taskId + ".idx";
            this.FullName = Path.Combine(Utilities.ConfigManager.GetValue("Backups.IndexFolder"), this.Name);
            if (!File.Exists(FullName))
            {
                throw new Exception("This index doesn't exists or doesn't have a local copy");
            }
            indexDbConn = new SqliteConnection();
            //indexDbConn.ConnectionString = "Version=3;Synchronous=off;Compress=True;data source=file:"+this.FullName;
            indexDbConn.ConnectionString = "Version=3,Synchronous=off,data source=file:" + this.FullName + "";
            indexDbConn.Open();
            dataFormatter = new BinaryFormatter();
            dataMs        = new MemoryStream();

            //get Header
            string headerQ = "SELECT data FROM header";

            System.Data.IDbCommand headerC = indexDbConn.CreateCommand();
            headerC.CommandText = headerQ;
            System.Data.IDataReader hReader = headerC.ExecuteReader();
            hReader.Read();
            dataMs = new MemoryStream();
            long dataSize = hReader.GetBytes(0, 0, null, 0, 0);
            int  offset = 0, bytesRead = 0;

            byte[] buffer = new byte[dataSize];
            //Console.WriteLine ("open() read="+hReader.GetBytes(0, 0, buffer, offset, BUFFER_SIZE));

            /*while((bytesRead = (int)hReader.GetBytes(0, offset, buffer, 0, 100)) > 0) {
             *      Console.WriteLine("open() read header : read="+bytesRead+", offset="+offset);
             *  dataMs.Write(buffer, 0, bytesRead);
             *  offset += bytesRead;
             *
             * }*/
            int curPos = 0;

            while (bytesRead < dataSize)
            {
                bytesRead += (int)hReader.GetBytes(0, curPos, buffer, curPos, (int)dataSize);
                curPos    += bytesRead;
            }
            dataMs.Write(buffer, 0, bytesRead);
            dataMs.Flush();
            //MemoryStream gzMs = new MemoryStream();
            dataMs.Position = 0;
            using (MemoryStream uncompressedStream = new MemoryStream()){
                using (gz = new System.IO.Compression.GZipStream(dataMs, System.IO.Compression.CompressionMode.Decompress, true)){
                    gz.CopyTo(uncompressedStream);
                }
                uncompressedStream.Position = 0;
                this.Header = (IndexHeader)dataFormatter.Deserialize(uncompressedStream);
            }

            dataMs.SetLength(0);
        }
예제 #2
0
 internal Index_bk()
 {
     this.Header = new IndexHeader();
 }