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(); }
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(); } }