Create() public method

Creates the file named FileName and returns the GridFileStream
If the file already exists
public Create ( ) : GridFileStream
return GridFileStream
示例#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);
        }
 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);
 }
示例#3
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));
        }
 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 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));
 }
示例#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 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");
 }
示例#10
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)));
        }
 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 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");
        }
示例#14
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));
        }
示例#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 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.");
 }
示例#17
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.");
        }
        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;
        }
示例#19
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");
 }
示例#20
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);
 }
示例#21
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);
        }