示例#1
0
        /// <summary>
        /// Deletes the database.
        /// </summary>
        public void Dispose()
        {
            var filePath = new FileInfo(dataSourcePath);

            if (!filePath.Exists)
            {
                return;
            }
            sharedConnection.Dispose();
            sqLiteConnection.Dispose();
            SQLiteConnection.ClearAllPools();

            // SQLite requires all created sql connection/command objects to be disposed
            // in order to delete the database file
            GC.Collect(2, GCCollectionMode.Forced);
            System.Threading.Thread.Sleep(100);

            File.Delete(dataSourcePath);
        }
示例#2
0
 /// <summary>
 /// remove the database from memory
 /// </summary>
 public void Dispose()
 {
     sharedConnection.Dispose();
 }
        public MemoryMappedFileRepository(ChunkDataRepositoryCollection Repo, string Path, string Name)
            : base(Repo)
        {
            if (Repo == null)
            {
                throw new ArgumentNullException("Repo");
            }
            if (Path == null)
            {
                throw new ArgumentNullException("Path");
            }
            if (Name == null)
            {
                throw new ArgumentNullException("Name");
            }
            publicChunks = new SortedSet <ChunkDescriptor> (new ChunkDescriptor.Comparer_Hash());
            path         = Path;
            name         = Name;
            string FPath  = Path + System.IO.Path.DirectorySeparatorChar + Name;
            bool   Exists = System.IO.File.Exists(FPath);

            if (!Exists)
            {
                System.IO.File.Create(FPath);
            }
            Base = new Mono.Data.Sqlite.SqliteConnection("Data Source=" + FPath);
            if (!Exists)
            {
                try{
                    id = Guid.NewGuid();
                    Base.Open();
                    using (Mono.Data.Sqlite.SqliteCommand Comm = new Mono.Data.Sqlite.SqliteCommand(
                               "CREATE TABLE CHUNKS(" +
                               "ID BLOB(64) NOT NULL, " +
                               "HAS_DEPENDENDANTS BIT NOT NULL, " +
                               "Path TEXT(400) NOT NULL)", Base))
                        Comm.ExecuteNonQuery();
                    using (Mono.Data.Sqlite.SqliteCommand Comm = new Mono.Data.Sqlite.SqliteCommand(
                               "CREATE TABLE ATTRIBUTES(" +
                               "NAME TEXT(128) PRIMARY KEY NOT NULL, " +
                               "VALUE BLOB(1024) NOT NULL)", Base))
                        Comm.ExecuteNonQuery();
                    using (Mono.Data.Sqlite.SqliteCommand Comm = new Mono.Data.Sqlite.SqliteCommand(
                               "CREATE TABLE DEPENDENCIES(" +
                               "ID BLOB(64) NOT NULL, " +
                               "DependantIDs BLOB(896) NOT NULL)", Base))         //default sqlite3 page size = 1024 = 64 for ID + 40 for everything sqlite needs + 920 which is a bit bigger than 14 Dependencies(896).
                        Comm.ExecuteNonQuery();
                    using (Mono.Data.Sqlite.SqliteCommand Comm = new Mono.Data.Sqlite.SqliteCommand(
                               "INSERT INTO ATTRIBUTES(" +
                               "NAME, " +
                               "VALUE) VALUES('ID', @p0)", Base)){
                        Comm.Parameters.AddWithValue("p0", ID.ToByteArray());
                        Comm.ExecuteNonQuery();
                    }
                }
                catch (Exception ex) {
                    if (Base != null)
                    {
                        if (Base.State == System.Data.ConnectionState.Open)
                        {
                            Base.Close();
                        }
                        Base.Dispose();
                    }
                    if (System.IO.File.Exists(FPath))
                    {
                        System.IO.File.Delete(FPath);
                    }
                    throw ex;
                }
            }
            else
            {
                Base.Open();
            }
        }
示例#4
0
 public MemoryMappedFileRepository(ChunkDataRepositoryCollection Repo, string Path, string Name)
     : base(Repo)
 {
     if (Repo == null)
         throw new ArgumentNullException ("Repo");
     if (Path == null)
         throw new ArgumentNullException ("Path");
     if (Name == null)
         throw new ArgumentNullException ("Name");
     publicChunks =  new SortedSet<ChunkDescriptor> (new ChunkDescriptor.Comparer_Hash());
     path = Path;
     name = Name;
     string FPath = Path + System.IO.Path.DirectorySeparatorChar + Name;
     bool Exists = System.IO.File.Exists (FPath);
     if (!Exists)
         System.IO.File.Create (FPath);
     Base = new Mono.Data.Sqlite.SqliteConnection ("Data Source=" + FPath);
     if (!Exists) {
         try{
             id = Guid.NewGuid();
         Base.Open();
         using(Mono.Data.Sqlite.SqliteCommand Comm  = new Mono.Data.Sqlite.SqliteCommand (
             "CREATE TABLE CHUNKS(" +
             "ID BLOB(64) NOT NULL, " +
             "HAS_DEPENDENDANTS BIT NOT NULL, " +
             "Path TEXT(400) NOT NULL)",Base))
             Comm.ExecuteNonQuery();
         using(Mono.Data.Sqlite.SqliteCommand Comm  = new Mono.Data.Sqlite.SqliteCommand (
             "CREATE TABLE ATTRIBUTES(" +
             "NAME TEXT(128) PRIMARY KEY NOT NULL, " +
             "VALUE BLOB(1024) NOT NULL)",Base))
             Comm.ExecuteNonQuery();
         using(Mono.Data.Sqlite.SqliteCommand Comm  = new Mono.Data.Sqlite.SqliteCommand (
             "CREATE TABLE DEPENDENCIES(" +
             "ID BLOB(64) NOT NULL, " +
             "DependantIDs BLOB(896) NOT NULL)",Base)) //default sqlite3 page size = 1024 = 64 for ID + 40 for everything sqlite needs + 920 which is a bit bigger than 14 Dependencies(896).
             Comm.ExecuteNonQuery();
         using(Mono.Data.Sqlite.SqliteCommand Comm  = new Mono.Data.Sqlite.SqliteCommand (
             "INSERT INTO ATTRIBUTES(" +
             "NAME, " +
             "VALUE) VALUES('ID', @p0)",Base)){
                 Comm.Parameters.AddWithValue("p0", ID.ToByteArray());
                 Comm.ExecuteNonQuery();
             }
         }
         catch(Exception ex){
             if(Base != null) {
                 if(Base.State == System.Data.ConnectionState.Open) {
                     Base.Close();
                 }
                 Base.Dispose();
             }
             if(System.IO.File.Exists (FPath))
                 System.IO.File.Delete(FPath);
             throw ex;
         }
     }
     else
         Base.Open();
 }
示例#5
0
 public void Dispose()
 {
     db.Dispose();
 }