Esempio n. 1
0
        /// <summary>
        /// <see cref="IFileObject.CopyFrom"/>
        /// </summary>
        public virtual void CopyFrom(IFileObject srcFile)
        {
            // raise 'before copy'
            LocalFs.OnFileCopying(this, srcFile);

            try {
                if (srcFile.Type == FileType.File)
                {
                    using (Stream inputStream = srcFile.Content.GetStream(FileAccess.Read)) {
                        CopyFrom(inputStream);
                    }
                }
                if (srcFile.Type == FileType.Folder)
                {
                    CopyFrom(srcFile.GetChildren());
                }
            } catch (Exception ex) {
                // raise 'error'
                LocalFs.OnFileError(this, ex);
                throw new FileSystemException(ex.Message, this, ex);
            }

            // raise 'after copy'
            LocalFs.OnFileCopied(this, srcFile);
        }
Esempio n. 2
0
 public virtual void CopyFrom(IFileObject srcFile)
 {
     if (srcFile.Type == FileType.File)
     {
         using (Stream inputStream = srcFile.Content.GetStream(FileAccess.Read)) {
             CopyFrom(inputStream);
         }
     }
     if (srcFile.Type == FileType.Folder)
     {
         CopyFrom(srcFile.GetChildren());
     }
 }
Esempio n. 3
0
    protected void RenderFile(StringBuilder sb, IFileObject file, bool renderChildren, bool renderFile, bool extraInfo, string filesystemName)
    {
        var filePath = file.Name.Replace("\\", "/");
        var fileName = Path.GetFileName(file.Name);

        if (fileName == String.Empty)
        {
            fileName = "Root";
        }
        switch (file.Type)
        {
        case FileType.File:
            var ext = Path.GetExtension(file.Name);
            if (ext != null && ext.Length > 1)
            {
                ext = ext.Substring(1);
            }
            if (renderFile)
            {
                sb.AppendFormat("<li class=\"file ext_{0} {4}\">{3}<a class='file' href=\"javascript:void(0)\" rel=\"{1}\" filename=\"{2}\" fileurl=\"{5}\"><span class='name'>{2}</span></a></li>",
                                ext, filePath, fileName,
                                extraInfo ? RenderFileInfo(file) : "",
                                extraInfo ? "fileInfo" : "",
                                HttpUtility.HtmlAttributeEncode(VfsHelper.GetFileFullUrl(filesystemName, filePath)));
            }
            break;

        case FileType.Folder:
            if (renderFile)
            {
                sb.AppendFormat("<li class=\"directory {2}\"><a class='directory' href=\"#\" rel=\"{0}/\" filename=\"{1}\"><span class='name'>{1}</span></a>",
                                filePath, fileName, (filePath != "" ? (renderChildren ? "expanded" : "collapsed") : ""));
            }
            if (renderChildren)
            {
                sb.Append("<ul class=\"jqueryFileTree\" style=\"display: none;\">");
                var folders     = new List <IFileObject>();
                var files       = new List <IFileObject>();
                var folderFiles = file.GetChildren();
                Array.Sort(folderFiles, delegate(IFileObject x, IFileObject y) { return(x.Name.CompareTo(y.Name)); });
                foreach (var f in folderFiles)
                {
                    if (f.Type == FileType.Folder)
                    {
                        folders.Add(f);
                    }
                    else
                    {
                        files.Add(f);
                    }
                }
                foreach (var f in folders)
                {
                    RenderFile(sb, f, false, true, extraInfo, filesystemName);
                }
                foreach (var f in files)
                {
                    RenderFile(sb, f, false, true, extraInfo, filesystemName);
                }
                sb.Append("</ul>");
            }
            sb.Append("</li>");
            break;
        }
    }
Esempio n. 4
0
        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");
            }
        }