Provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of GridFileStream objects. The api is very similar to the FileInfo class in System.IO.
Пример #1
0
        public void TestUpdateInfo()
        {
            string filename = "gfi-meta.txt";
            string fs       = "gfinfo";

            Object       id;
            GridFileInfo gfi = new GridFileInfo(DB, fs, filename);

            using (GridFileStream gfs = gfi.Create(FileMode.CreateNew)){
                id = gfs.GridFileInfo.Id;
                gfi.ContentType = "text/sam";
                Assert.AreEqual(gfi.ContentType, gfs.GridFileInfo.ContentType, "gridfileinfos don't point to the same object");
                TextWriter tw = new StreamWriter(gfs);
                tw.WriteLine("test");
                tw.Close();
            }
            gfi.Aliases = new List <String>()
            {
                "file1"
            };
            GridFileInfo gfi2 = new GridFileInfo(DB, fs, filename);

            Assert.IsTrue(gfi2.Exists, "Couldn't find " + filename);
            Assert.AreEqual("text/sam", gfi2.ContentType);
            Assert.AreNotEqual(gfi2.Aliases, gfi.Aliases, "Aliases shouldn't have been updated in the DB yet.");
            gfi.UpdateInfo();
            gfi2.Refresh();
            Assert.AreEqual(gfi2.Aliases, gfi.Aliases);
        }
Пример #2
0
        public GridFileStream(GridFileInfo gridfileinfo, IMongoCollection files, IMongoCollection chunks, FileAccess access)
        {
            switch (access)
            {
            case FileAccess.Read:
                canRead = true;
                break;

            case FileAccess.ReadWrite:
                canRead  = true;
                canWrite = true;
                break;

            case FileAccess.Write:
                canWrite = true;
                break;
            }
            this.gridFileInfo      = gridfileinfo;
            this.files             = files;
            this.chunks            = chunks;
            this.buffer            = new byte[gridFileInfo.ChunkSize];
            this.blankBuffer       = new byte[gridFileInfo.ChunkSize];
            this.highestPosWritten = this.gridFileInfo.Length;
            this.MoveTo(0);
        }
Пример #3
0
 public void TestFileExists()
 {
     string filename = "gfi-exists.txt";
     GridFileInfo gfi = new GridFileInfo(db["tests"], "gfexists", filename);
     Assert.IsFalse(gfi.Exists);
     GridFileStream gfs = gfi.Create();
     Assert.IsTrue(gfi.Exists);
 }
Пример #4
0
        public GridFileStream Create(String filename, FileMode mode, FileAccess access)
        {
            //Create is delegated to a GridFileInfo because the stream needs access to the gfi and it
            //is easier to do it this way and only write the implementation once.
            GridFileInfo gfi = new GridFileInfo(this.db, this.name, filename);

            return(gfi.Create(mode, access));
        }
Пример #5
0
 public void TestDelete()
 {
     String filename = "gfi-delete.txt";
     GridFile gf = new GridFile(db["tests"],"gfdelete");
     GridFileInfo gfi = new GridFileInfo(db["tests"],"gfdelete", filename);
     GridFileStream gfs = gfi.Create();  //TODO Expand Test to make sure that chunks for the file got deleted too.
     gfi.Delete();
     Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
 }
Пример #6
0
        public void TestFileExists()
        {
            string       filename = "gfi-exists.txt";
            GridFileInfo gfi      = new GridFileInfo(DB, "gfexists", filename);

            Assert.IsFalse(gfi.Exists);
            GridFileStream gfs = gfi.Create();

            Assert.IsTrue(gfi.Exists);
        }
Пример #7
0
        public void TestDelete()
        {
            String         filename = "gfi-delete.txt";
            GridFile       gf       = new GridFile(db["tests"], "gfdelete");
            GridFileInfo   gfi      = new GridFileInfo(db["tests"], "gfdelete", filename);
            GridFileStream gfs      = gfi.Create(); //TODO Expand Test to make sure that chunks for the file got deleted too.

            gfi.Delete();
            Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
        }
 public void TestDelete(){
     String filename = "gfi-delete.txt";
     GridFile gf = new GridFile(DB,"gfdelete");
     GridFileInfo gfi = new GridFileInfo(DB,"gfdelete", filename);
     var id = gfi.Id;
     GridFileStream gfs = gfi.Create();  //TODO Expand Test to make sure that chunks for the file got deleted too.
     gfi.Delete();
     Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
     Assert.IsTrue(0 == gf.Chunks.Count(new Document("_id", id)));
 }
 public void TestCreateNonExisting(){
     String filename = "newfile.txt";
     GridFile gf = new GridFile(DB,"gfcreate");
     GridFileInfo gfi = new GridFileInfo(DB,"gfcreate", filename);
     
     Assert.AreEqual(filename, gfi.FileName);
     GridFileStream gfs = gfi.Create();
     Assert.AreEqual(filename, gfi.FileName, "Filename got erased?");
     Assert.IsTrue(gf.Exists(gfi.FileName));
 }
 public void TestMoveTo(){
     String filename = "gfi-move.txt";
     String filename2 = "gfi-move.txt2";
     GridFile gf = new GridFile(DB,"gfmove");
     GridFileInfo gfi = new GridFileInfo(DB,"gfmove", filename);
     gfi.Create();
     gfi.MoveTo(filename2);
     Assert.IsFalse(gf.Exists(filename), "File should have been moved.");
     Assert.IsTrue(gf.Exists(filename2), "File wasn't");
     Assert.AreEqual(filename2, gfi.FileName, "Filename wasn't set in GridFileInfo");
 }
 public void TestModeCreateNew(){
     Object id;
     string filename = "createnew.txt";
     GridFileInfo gfi = new GridFileInfo(DB,"gfcreate", filename);
     using(GridFileStream gfs = gfi.Create(FileMode.CreateNew)){
         id = gfs.GridFileInfo.Id;
         TextWriter tw = new StreamWriter(gfs);
         tw.WriteLine("test");
         tw.Close();
     }
     Assert.AreEqual(1, CountChunks("gfcreate", id));
 }
Пример #12
0
        public void TestCreateNonExisting()
        {
            String       filename = "newfile.txt";
            GridFile     gf       = new GridFile(DB, "gfcreate");
            GridFileInfo gfi      = new GridFileInfo(DB, "gfcreate", filename);

            Assert.AreEqual(filename, gfi.FileName);
            GridFileStream gfs = gfi.Create();

            Assert.AreEqual(filename, gfi.FileName, "Filename got erased?");
            Assert.IsTrue(gf.Exists(gfi.FileName));
        }
Пример #13
0
        public void TestDelete()
        {
            String         filename = "gfi-delete.txt";
            GridFile       gf       = new GridFile(DB, "gfdelete");
            GridFileInfo   gfi      = new GridFileInfo(DB, "gfdelete", filename);
            var            id       = gfi.Id;
            GridFileStream gfs      = gfi.Create(); //TODO Expand Test to make sure that chunks for the file got deleted too.

            gfi.Delete();
            Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
            Assert.IsTrue(0 == gf.Chunks.Count(new Document("_id", id)));
        }
Пример #14
0
        public void TestMoveTo()
        {
            String       filename  = "gfi-move.txt";
            String       filename2 = "gfi-move.txt2";
            GridFile     gf        = new GridFile(DB, "gfmove");
            GridFileInfo gfi       = new GridFileInfo(DB, "gfmove", filename);

            gfi.Create();
            gfi.MoveTo(filename2);
            Assert.IsFalse(gf.Exists(filename), "File should have been moved.");
            Assert.IsTrue(gf.Exists(filename2), "File wasn't");
            Assert.AreEqual(filename2, gfi.FileName, "Filename wasn't set in GridFileInfo");
        }
Пример #15
0
        protected Object CreateDummyFile(string filename, int size, int chunksize, int initialOffset)
        {
            GridFileInfo gfi = new GridFileInfo(DB, "gfstream", filename);

            gfi.ChunkSize = chunksize;
            GridFileStream gfs = gfi.Create();
            Object         id  = gfs.GridFileInfo.Id;

            byte[] buff = CreateIntBuffer(size);
            gfs.Write(buff, initialOffset, buff.Length - initialOffset);
            gfs.Close();

            return(id);
        }
Пример #16
0
        public void TestModeCreateNew()
        {
            Object       id;
            string       filename = "createnew.txt";
            GridFileInfo gfi      = new GridFileInfo(DB, "gfcreate", filename);

            using (GridFileStream gfs = gfi.Create(FileMode.CreateNew)){
                id = gfs.GridFileInfo.Id;
                TextWriter tw = new StreamWriter(gfs);
                tw.WriteLine("test");
                tw.Close();
            }
            Assert.AreEqual(1, CountChunks("gfcreate", id));
        }
Пример #17
0
        public void TestOpenNonExistentFails()
        {
            string       filename = "gfi-opennothere.txt";
            GridFile     gf       = new GridFile(DB, "gfopen");
            GridFileInfo gfi      = new GridFileInfo(DB, "gfopen", filename);
            bool         thrown   = false;

            try{
                GridFileStream gfs = gfi.OpenRead();
            }catch (DirectoryNotFoundException dnfe) {
                Assert.AreEqual(gf.Name + Path.VolumeSeparatorChar + filename, dnfe.Message);
                thrown = true;
            }
            Assert.IsTrue(thrown);
        }
Пример #18
0
 public void TestCreateExisting()
 {
     String filename = "existing.txt";
     GridFile gf = new GridFile(db["tests"],"gfcreate");
     GridFileInfo gfi = new GridFileInfo(db["tests"],"gfcreate", filename);
     GridFileStream gfs = gfi.Create();
     bool thrown = false;
     try{
         gfi = new GridFileInfo(db["tests"],"create", filename);
         gfi.Create();
     }catch(IOException){
         thrown = true;
     }
     Assert.IsTrue(thrown, "Shouldn't be able to create the same file twice.");
 }
Пример #19
0
        public void TestSetLengthBigger()
        {
            string         filename = "setlengthbigger.txt";
            GridFileStream gfs      = fs.Create(filename);
            Object         id       = gfs.GridFileInfo.Id;
            long           length   = 256 * 1024 * 5;

            gfs.WriteByte(1);
            gfs.SetLength(length);
            gfs.WriteByte(2);
            gfs.Close();
            GridFileInfo gfi = new GridFileInfo(DB, filesystem, filename);

            Assert.AreEqual(length + 1, gfi.Length);
            Assert.AreEqual(6, CountChunks(filesystem, id));
        }
Пример #20
0
        public void TestCreateExisting()
        {
            String         filename = "existing.txt";
            GridFile       gf       = new GridFile(db["tests"], "gfcreate");
            GridFileInfo   gfi      = new GridFileInfo(db["tests"], "gfcreate", filename);
            GridFileStream gfs      = gfi.Create();
            bool           thrown   = false;

            try{
                gfi = new GridFileInfo(db["tests"], "create", filename);
                gfi.Create();
            }catch (IOException) {
                thrown = true;
            }
            Assert.IsTrue(thrown, "Shouldn't be able to create the same file twice.");
        }
Пример #21
0
 public GridFileStream(GridFileInfo gridfileinfo,IMongoCollection files, IMongoCollection chunks, FileAccess access)
 {
     switch (access){
         case FileAccess.Read:
             canRead = true;
             break;
         case FileAccess.ReadWrite:
             canRead = true;
             canWrite = true;
             break;
         case FileAccess.Write:
             canWrite = true;
         break;
     }
     this.gridFileInfo = gridfileinfo;
     this.files = files;
     this.chunks = chunks;
     this.buffer = new byte[gridFileInfo.ChunkSize];
     this.blankBuffer = new byte[gridFileInfo.ChunkSize];
     this.highestPosWritten = this.gridFileInfo.Length;
     this.MoveTo(0);
 }
Пример #22
0
        protected Object CreateDummyFile(string filename, int size, int chunksize, int initialOffset)
        {
            GridFileInfo gfi = new GridFileInfo(DB, "gfstream", filename);
            gfi.ChunkSize = chunksize;
            GridFileStream gfs = gfi.Create();
            Object id = gfs.GridFileInfo.Id;
            byte[] buff = CreateIntBuffer(size);
            gfs.Write(buff,initialOffset,buff.Length - initialOffset);
            gfs.Close();

            return id;
        }
Пример #23
0
        public void TestSetLengthBigger()
        {
            string filename = "setlengthbigger.txt";
            GridFileStream gfs = fs.Create(filename);
            Object id = gfs.GridFileInfo.Id;
            long length = 256 * 1024 * 5;

            gfs.WriteByte(1);
            gfs.SetLength(length);
            gfs.WriteByte(2);
            gfs.Close();
            GridFileInfo gfi = new GridFileInfo(DB,filesystem,filename);

            Assert.AreEqual(length + 1, gfi.Length);
            Assert.AreEqual(6, CountChunks(filesystem,id));
        }
Пример #24
0
        public GridFileStream OpenWrite(String filename)
        {
            GridFileInfo gfi = new GridFileInfo(this.db, this.name, filename);

            return(gfi.OpenWrite());
        }
Пример #25
0
 public void TestMoveTo()
 {
     String filename = "gfi-move.txt";
     String filename2 = "gfi-move.txt2";
     GridFile gf = new GridFile(db["tests"],"gfmove");
     GridFileInfo gfi = new GridFileInfo(db["tests"],"gfmove", filename);
     gfi.Create();
     gfi.MoveTo(filename2);
     Assert.IsFalse(gf.Exists(filename), "File should have been moved.");
     Assert.IsTrue(gf.Exists(filename2), "File wasn't");
 }
Пример #26
0
        public void TestUpdateInfo()
        {
            string filename = "gfi-meta.txt";
            string fs = "gfinfo";

            Object id;
            GridFileInfo gfi = new GridFileInfo(db["tests"],fs, filename);
            using(GridFileStream gfs = gfi.Create(FileMode.CreateNew)){
                id = gfs.GridFileInfo.Id;
                gfi.ContentType = "text/sam";
                Assert.AreEqual(gfi.ContentType, gfs.GridFileInfo.ContentType, "gridfileinfos don't point to the same object");
                TextWriter tw = new StreamWriter(gfs);
                tw.WriteLine("test");
                tw.Close();
            }
            gfi.Aliases = new String[]{"file1"};
            GridFileInfo gfi2 = new GridFileInfo(db["tests"],fs, filename);
            Assert.IsTrue(gfi2.Exists, "Couldn't find " + filename);
            Assert.AreEqual("text/sam", gfi2.ContentType);
            Assert.AreNotEqual(gfi2.Aliases, gfi.Aliases);
            gfi.UpdateInfo();
            gfi2.Refresh();
            Assert.AreEqual(gfi2.Aliases, gfi.Aliases);
        }
Пример #27
0
 public void TestOpenNonExistentFails()
 {
     string filename = "gfi-opennothere.txt";
     GridFile gf = new GridFile(db["tests"], "gfopen");
     GridFileInfo gfi = new GridFileInfo(db["tests"], "gfopen", filename);
     bool thrown = false;
     try{
         GridFileStream gfs = gfi.OpenRead();
     }catch(DirectoryNotFoundException dnfe){
         Assert.AreEqual(gf.Name + Path.VolumeSeparatorChar + filename, dnfe.Message);
         thrown = true;
     }
     Assert.IsTrue(thrown);
 }
Пример #28
0
 public GridFileStream OpenWrite(String filename)
 {
     GridFileInfo gfi = new GridFileInfo(this.db, this.name, filename);
     return gfi.OpenWrite();
 }
Пример #29
0
 public GridFileStream Create(String filename, FileMode mode, FileAccess access)
 {
     //Create is delegated to a GridFileInfo because the stream needs access to the gfi and it
     //is easier to do it this way and only write the implementation once.
     GridFileInfo gfi = new GridFileInfo(this.db,this.name,filename);
     return gfi.Create(mode,access);
 }