Пример #1
0
 /// <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);
     }
 }
Пример #2
0
        /// <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);
        }
Пример #3
0
 public EntryInfo CopyFile(Guid fileGuid, string destinationPath)
 {
     using (var db = new FileDB(_filedbPath, FileAccess.Read))
     {
         return db.Read(fileGuid, destinationPath);
     }
 }
Пример #4
0
 public static void ReadFileContent(string dbFileName, EntryInfo entry, Stream output)
 {
     using (var db = new FileDB(dbFileName, FileAccess.Read))
     {
         db.ReadContent(entry, output);
     }
 }
Пример #5
0
 /// <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));
     }
 }
Пример #6
0
 /// <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));
     }
 }
Пример #7
0
 public static EntryInfo ReadMetadata(string dbFileName, Guid id)
 {
     using (var db = new FileDB(dbFileName, FileAccess.Read))
     {
         return(db.ReadMetadata(id));
     }
 }
Пример #8
0
 /// <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);
     }
 }
Пример #9
0
 /// <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));
     }
 }
Пример #10
0
 /// <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));
     }
 }
Пример #11
0
 /// <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();
     }
 }
Пример #12
0
 public EntryInfo Search(Guid id)
 {
     using (var db = new FileDB(_filedbPath, FileAccess.Read))
     {
         return db.Search(id);
     }
 }
Пример #13
0
 /// <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());
     }
 }
Пример #14
0
 public EntryInfo StoreFile(string fileToStore)
 {
     using (var db = new FileDB(_filedbPath, FileAccess.Write))
     {
         return db.Store(fileToStore);
     }
 }
Пример #15
0
 public static EntryInfo ReadMetadata(string dbFileName, Guid id)
 {
     using (var db = new FileDB(dbFileName, FileAccess.Read))
     {
         return db.ReadMetadata(id);
     }
 }
Пример #16
0
 /// <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);
     }
 }
Пример #17
0
 public ActionResult Structure()
 {
     using (var db = new FileDB(pathDB, FileAccess.Read))
     {
         ViewData["DebugInfo"] = db.Debug.DisplayPages();
     }
     return View();
 }
Пример #18
0
 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);
         }
 }
Пример #19
0
        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++;
        }
Пример #20
0
 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;
     }
 }
Пример #21
0
        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);
        }
Пример #22
0
        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);

        }
Пример #23
0
        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();
            }
        }
Пример #24
0
 /// <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);
     }
 }
Пример #25
0
 /// <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);
     }
 }
Пример #26
0
 /// <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();
     }
 }
Пример #27
0
        /// <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);
        }
Пример #28
0
        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");
                    }
                }
            }
        }
Пример #29
0
 /// <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();
     }
 }
Пример #30
0
        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");
        }
Пример #31
-1
 /// <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);
     }
 }
Пример #32
-1
 public static void ReadFileContent(string dbFileName, EntryInfo entry, Stream output)
 {
     using (var db = new FileDB(dbFileName, FileAccess.Read))
     {
         db.ReadContent(entry, output);
     }
 }