示例#1
0
 public virtual void CreateFile()
 {
     if (Type == FileType.Imaginary)
     {
         string fileParentLocalFolder = Path.GetDirectoryName(Name);
         if (fileParentLocalFolder.Length > 0)
         {
             IFileObject parentFolder = MemoryFs.ResolveFile(fileParentLocalFolder);
             parentFolder.CreateFolder();
         }
     }
     _Type = FileType.File;
     Content.LastModifiedTime = DateTime.Now;
     Close();
 }
示例#2
0
 public virtual void CreateFile()
 {
     if (Type == FileType.Imaginary)
     {
         if (ParentName.Length > 0)
         {
             IFileObject parentFolder = DalcFs.ResolveFile(ParentName);
             if (parentFolder.Type != FileType.Folder)
             {
                 parentFolder.CreateFolder();
             }
         }
     }
     _Type = FileType.File;
     Close();
 }
示例#3
0
文件: VfsTest.cs 项目: ruo2012/nicnet
        protected void prepeare(IFileSystem fileSystem)
        {
            // create folder
            IFileObject testFolder = fileSystem.ResolveFile("test");

            testFolder.CreateFolder();

            // create 10 files
            for (int i = 0; i < 10; i++)
            {
                string      fName    = String.Format("test/test{0}.{1}", i, i % 2 == 0 ? "txt" : "doc");
                IFileObject testFile = fileSystem.ResolveFile(fName);
                testFile.CreateFile();
                StreamWriter streamWr = new StreamWriter(testFile.Content.GetStream(FileAccess.Write));
                streamWr.Write("This is test content #" + i.ToString());
                streamWr.Close();
            }

            // GetChildren
            if (testFolder.GetChildren().Length != 10)
            {
                throw new Exception("GetChildren failed");
            }

            // create another dir with subdir
            IFileObject testTest2Folder = fileSystem.ResolveFile("test2/test/");

            testTest2Folder.CopyFrom(testFolder);
            testTest2Folder.Parent.CopyFrom(testFolder);


            // FindFiles
            IFileObject[] txtTest2Files = testTest2Folder.Parent.FindFiles(new MaskFileSelector("*.txt"));
            if (txtTest2Files.Length != 10)
            {
                throw new Exception("FindFiles failed");
            }

            foreach (IFileObject f in txtTest2Files)
            {
                f.Delete();
            }
            if (testTest2Folder.GetChildren().Length != 5)
            {
                throw new Exception("Delete failed");
            }

            // check copied file content
            IFileObject test1docFile = fileSystem.ResolveFile("test2/test/test1.doc");

            if (!test1docFile.Exists())
            {
                throw new Exception("ResolveFile failed");
            }
            StreamReader rdr     = new StreamReader(test1docFile.Content.GetStream(FileAccess.Read));
            string       content = rdr.ReadToEnd();

            rdr.Close();
            Assert.AreEqual("This is test content #1", content);

            // deep tree copy test
            IFileObject test3Folder = fileSystem.ResolveFile("test3");

            test3Folder.CopyFrom(fileSystem.ResolveFile("test2"));

            // count doc files
            if (fileSystem.Root.FindFiles(new MaskFileSelector("*.doc")).Length != 25)
            {
                throw new Exception("CopyFrom (subtree) or FindFiles failed");
            }
        }