/// <summary> /// Store a file inside the database /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="fileName">Filename to associate with file (eg: MyPhoto.jpg)</param> /// <param name="input">Stream with a file content</param> /// <returns>EntryInfo with file information</returns> public static EntryInfo Store(string dbFileName, string fileName, Stream input) { using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { return db.Store(fileName, input); } }
/// <summary> /// Shrink datafile /// </summary> public void Shrink() { var dbFileName = _fileStream.Name; var fileAccess = _fileStream.CanWrite ? FileAccess.ReadWrite : FileAccess.Read; var tempFile = Path.GetDirectoryName(dbFileName) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(dbFileName) + ".temp" + Path.GetExtension(dbFileName); if (File.Exists(tempFile)) { File.Delete(tempFile); } var entries = ListFiles(); FileDB.CreateEmptyFile(tempFile, false); using (var tempDb = new FileDB(tempFile, FileAccess.ReadWrite)) { foreach (var entry in entries) { using (var stream = new MemoryStream()) { Read(entry.ID, stream); stream.Seek(0, SeekOrigin.Begin); tempDb.Store(entry, stream); } } } Dispose(); File.Delete(dbFileName); File.Move(tempFile, dbFileName); Connect(dbFileName, fileAccess); }
public EntryInfo CopyFile(Guid fileGuid, string destinationPath) { using (var db = new FileDB(_filedbPath, FileAccess.Read)) { return db.Read(fileGuid, destinationPath); } }
public static void ReadFileContent(string dbFileName, EntryInfo entry, Stream output) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { db.ReadContent(entry, output); } }
/// <summary> /// Read a file inside the database file /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="id">File ID</param> /// <param name="fileName">Filename/Path to save the file (eg: C:\Temp\MyPhoto.jpg)</param> /// <returns>EntryInfo with file information</returns> public static EntryInfo Read(string dbFileName, Guid id, string fileName) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { return(db.Read(id, fileName)); } }
/// <summary> /// Read a file inside the database file /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="id">File ID</param> /// <param name="output">Stream to save the file</param> /// <returns>EntryInfo with file information</returns> public static EntryInfo Read(string dbFileName, Guid id, Stream output) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { return(db.Read(id, output)); } }
public static EntryInfo ReadMetadata(string dbFileName, Guid id) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { return(db.ReadMetadata(id)); } }
/// <summary> /// Export all file inside a database to a directory /// </summary> /// <param name="dbFileName">FileDB database file</param> /// <param name="directory">Directory to export files</param> /// <param name="filePattern">File Pattern. Use keys: {id} {extension} {filename}. Eg: "{filename}.{id}.{extension}"</param> public static void Export(string dbFileName, string directory, string filePattern) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { db.Export(directory, filePattern); } }
/// <summary> /// Store a file inside the database /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="fileName">Filename to associate with file (eg: MyPhoto.jpg)</param> /// <param name="input">Stream with a file content</param> /// <returns>EntryInfo with file information</returns> public static EntryInfo Store(string dbFileName, string fileName, Stream input) { using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { return(db.Store(fileName, input)); } }
/// <summary> /// Delete a file inside a database /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="id">Guid of file</param> /// <returns>True with found and delete the file, otherwise false</returns> public static bool Delete(string dbFileName, Guid id) { using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { return(db.Delete(id)); } }
/// <summary> /// Shrink database file /// </summary> /// <param name="dbFileName">Path to database file (eg: C:\Temp\MyDB.dat)</param> public static void Shrink(string dbFileName) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { db.Shrink(); } }
public EntryInfo Search(Guid id) { using (var db = new FileDB(_filedbPath, FileAccess.Read)) { return db.Search(id); } }
/// <summary> /// Delete a file inside a database /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <returns>Array with all files identities</returns> public static EntryInfo[] ListFiles(string dbFileName) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { return(db.ListFiles()); } }
public EntryInfo StoreFile(string fileToStore) { using (var db = new FileDB(_filedbPath, FileAccess.Write)) { return db.Store(fileToStore); } }
public static EntryInfo ReadMetadata(string dbFileName, Guid id) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { return db.ReadMetadata(id); } }
/// <summary> /// Read a file inside the database file /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="id">File ID</param> /// <param name="output">Stream to save the file</param> /// <returns>EntryInfo with file information</returns> public static EntryInfo Read(string dbFileName, Guid id, Stream output) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { return db.Read(id, output); } }
public ActionResult Structure() { using (var db = new FileDB(pathDB, FileAccess.Read)) { ViewData["DebugInfo"] = db.Debug.DisplayPages(); } return View(); }
public static EntryInfo Store(string dbFileName, string fileName, byte[] inputBuffer) { using (MemoryStream ms = new MemoryStream(inputBuffer)) using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { EntryInfo en = db.Store(fileName, ms); ms.Close(); return(en); } }
public FileDbContext(FileAccess access, string connectionString = "ACTSfilesConnection") { var fileDbConnectionString = ConfigurationManager.ConnectionStrings[connectionString].ConnectionString; var fileDbPath = Path.Combine((string)AppDomain.CurrentDomain.GetData("DataDirectory"), fileDbConnectionString); Files = new FileDB(fileDbPath, access); if (access.HasFlag(FileAccess.Write)) lock (_lockObj) _writeCounter++; }
public static EntryInfo Store(string dbFileName, string fileName, byte[] inputBuffer) { using (MemoryStream ms = new MemoryStream(inputBuffer)) using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { EntryInfo en = db.Store(fileName, ms); ms.Close(); return en; } }
private void Connect(string fileName, FileAccess fileAccess) { if (!File.Exists(fileName)) { FileDB.CreateEmptyFile(fileName); } // Não permite acesso somente gravação (transforma em leitura/gravação) var fa = fileAccess == FileAccess.Write || fileAccess == FileAccess.ReadWrite ? FileAccess.ReadWrite : FileAccess.Read; _fileStream = new FileStream(fileName, FileMode.Open, fa, FileShare.ReadWrite, (int)BasePage.PAGE_SIZE, FileOptions.None); _engine = new Engine(_fileStream); }
static void Test2() { //------------------------------------------------------------------------------ string dbFileName = @"d:\\WImageTest\\testdb2.dat"; //EntryInfo[] fileList2 = FileDB.ListFiles(dbFileName); //var filename1 = fileList2[0].FileUrl; //1. open byte[] inputBuffer = GenerateTestDataBuffer("hello!...1"); List<SampleStoreRequest> storeReqs = new List<SampleStoreRequest>() { new SampleStoreRequest("a01", GenerateTestDataBuffer("hello_a01")), new SampleStoreRequest("a02", GenerateTestDataBuffer("hello_a02")), new SampleStoreRequest("a03", GenerateTestDataBuffer("hello_a03")), new SampleStoreRequest("a04", GenerateTestDataBuffer("hello_a04")), new SampleStoreRequest("a05", GenerateTestDataBuffer("hello_a05")) }; using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { EntryInfo[] prevFiles = db.ListFiles(); int j = storeReqs.Count; for (int i = 0; i < j; ++i) { SampleStoreRequest req = storeReqs[i]; using (var dataStream = new MemoryStream(req.buffer)) { EntryInfo en = db.Store(req.fileName, dataStream); db.Flush(); } } } //------------------------------------------------------------------------------ //test read back EntryInfo[] fileList = FileDB.ListFiles(dbFileName); }
public ActionResult Download(string id) { // Using a classic way to download a file, insted of FileContentResult mode. // Optimize for big files (download on demand) using (var db = new FileDB(pathDB, FileAccess.Read)) { var info = db.Search(Guid.Parse(id)); Response.Buffer = false; Response.BufferOutput = false; Response.ContentType = info.MimeType; Response.AppendHeader("Content-Length", info.FileLength.ToString()); Response.AppendHeader("content-disposition", "attachment; filename=" + info.FileName); db.Read(info.ID, Response.OutputStream); return new EmptyResult(); } }
/// <summary> /// Delete a file inside a database /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="id">Guid of file</param> /// <returns>True with found and delete the file, otherwise false</returns> public static bool Delete(string dbFileName, Guid id) { using (var db = new FileDB(dbFileName, FileAccess.ReadWrite)) { return db.Delete(id); } }
/// <summary> /// Delete a file inside a database /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <returns>Array with all files identities</returns> public static EntryInfo[] ListFiles(string dbFileName) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { return db.ListFiles(); } }
/// <summary> /// Shrink datafile /// </summary> public void Shrink() { var dbFileName = _fileStream.Name; var fileAccess = _fileStream.CanWrite ? FileAccess.ReadWrite : FileAccess.Read; var tempFile = Path.GetDirectoryName(dbFileName) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(dbFileName) + ".temp" + Path.GetExtension(dbFileName); if (File.Exists(tempFile)) File.Delete(tempFile); var entries = ListFiles(); FileDB.CreateEmptyFile(tempFile, false); using (var tempDb = new FileDB(tempFile, FileAccess.ReadWrite)) { foreach (var entry in entries) { using (var stream = new MemoryStream()) { Read(entry.ID, stream); stream.Seek(0, SeekOrigin.Begin); tempDb.Store(entry, stream); } } } Dispose(); File.Delete(dbFileName); File.Move(tempFile, dbFileName); Connect(dbFileName, fileAccess); }
public ActionResult Thumbnail(string id) { using (var db = new FileDB(pathDB, FileAccess.Read)) { var info = db.Search(Guid.Parse(id)); if (!info.MimeType.StartsWith("image", StringComparison.InvariantCultureIgnoreCase)) return File(Server.MapPath("~/Content/no-picture.jpg"), "image/jpg"); using (MemoryStream output = new MemoryStream()) { db.Read(info.ID, output); Image image = Image.FromStream(output); Image thumbnailImage = image.GetThumbnailImage(64, 64, new Image.GetThumbnailImageAbort(delegate { return true; }), IntPtr.Zero); using (MemoryStream imageStream = new MemoryStream()) { thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png); return File(imageStream.ToArray(), "image/png"); } } } }
public ActionResult DeleteAll() { using (var db = new FileDB(pathDB, FileAccess.ReadWrite)) { var ent = db.ListFiles(); foreach(var e in ent) db.Delete(e.ID); } return RedirectToAction("Index"); }
/// <summary> /// Read a file inside the database file /// </summary> /// <param name="dbFileName">Database path/filname (eg: C:\Temp\MyDB.dat)</param> /// <param name="id">File ID</param> /// <param name="fileName">Filename/Path to save the file (eg: C:\Temp\MyPhoto.jpg)</param> /// <returns>EntryInfo with file information</returns> public static EntryInfo Read(string dbFileName, Guid id, string fileName) { using (var db = new FileDB(dbFileName, FileAccess.Read)) { return db.Read(id, fileName); } }