Ejemplo n.º 1
0
        public void UploadFile(long folderId, string fileName, Stream fileContent)
        {
            DocumentItem folder = FindFolderById(folderId);
            var          file   = new DocumentItem()
            {
                Name          = fileName,
                Content       = CreateBinaryContent(fileContent),
                ContentSize   = fileContent.Length,
                ParentItem    = folder,
                CreationTime  = DateTime.UtcNow,
                LastWriteTime = DateTime.UtcNow,
                IsFolder      = false
            };

            DataContext.Documents.Add(file);
            SaveChanges();
        }
Ejemplo n.º 2
0
        public void SetDocumentContent(long id, byte[] data)
        {
            DocumentItem fileItem = GetDocumentById(id);

            // Put code here for saving previous Document content
            // SaveDocumentContentToHistory(id, fileItem.LastWriteTime, fileItem.Content.Data);
            // ...

            fileItem.Content.Data  = data;
            fileItem.ContentSize   = data.Length;
            fileItem.LastWriteTime = DateTime.UtcNow;

            // Clear preview Cache for RichText files
            Utils.ClearDocumentPreviewFilesById(fileItem.ID);

            SaveChanges();
        }
Ejemplo n.º 3
0
        void CopyFolderInternal(DocumentItem folder, DocumentItem newParentFolder)
        {
            DocumentItem copiedFolder = CopyItemInternal(folder, newParentFolder);

            List <DocumentItem> files = GetDocumentsInFolder(folder.ID).ToList();

            foreach (DocumentItem file in files)
            {
                CopyItemInternal(file, copiedFolder);
            }

            List <DocumentItem> subFolders = GetFolders(folder).ToList();

            foreach (DocumentItem subFolder in subFolders)
            {
                CopyFolderInternal(subFolder, copiedFolder);
            }
        }
Ejemplo n.º 4
0
        static void PopulateDbFromDirectoryRecursive(string directoryPath, DocumentsDb dataContext,
                                                     DocumentItem parentItem)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);
            DocumentItem  directoryItem = CreateItemFromFileSystemInfo(directoryInfo, true, parentItem);

            dataContext.Documents.Add(directoryItem);
            foreach (FileInfo fileInfo in directoryInfo.EnumerateFiles())
            {
                DocumentItem fileItem = CreateItemFromFileSystemInfo(fileInfo, false, directoryItem);
                fileItem.Content     = CreateBinaryContent(dataContext, fileInfo.FullName);
                fileItem.ContentSize = fileItem.Content.Data.Length;
                dataContext.Documents.Add(fileItem);
            }
            foreach (DirectoryInfo subDirectoryInfo in directoryInfo.EnumerateDirectories())
            {
                PopulateDbFromDirectoryRecursive(subDirectoryInfo.FullName, dataContext, directoryItem);
            }
        }
Ejemplo n.º 5
0
 IEnumerable <DocumentItem> GetFolders(DocumentItem parentFolder)
 {
     return(FolderCache.Values.Where(i => i.ParentItem == parentFolder && i.IsFolder));
 }
Ejemplo n.º 6
0
        public IEnumerable <DocumentItem> GetFolders(long?parentId, string parentRelativeName)
        {
            DocumentItem parentFolder = FindFolder(parentId, parentRelativeName);

            return(GetFolders(parentFolder));
        }
Ejemplo n.º 7
0
 public void RefreshFolderCache()
 {
     FolderCache = Items.Where(item => item.IsFolder).ToDictionary(item => item.ID);
     RootItem    = FolderCache.Values.First(item => item.IsRoot);
 }
Ejemplo n.º 8
0
        public Stream GetDocumentContent(long id)
        {
            DocumentItem fileItem = GetDocumentById(id);

            return(new MemoryStream(fileItem.Content.Data.ToArray()));
        }
Ejemplo n.º 9
0
 static DocumentItem CreateItemFromFileSystemInfo(FileSystemInfo fsi, bool isFolder, DocumentItem parentItem)
 {
     return(new DocumentItem()
     {
         ParentItem = parentItem,
         Name = fsi.Name,
         IsFolder = isFolder,
         CreationTime = fsi.CreationTimeUtc,
         LastWriteTime = fsi.LastWriteTimeUtc
     });
 }
Ejemplo n.º 10
0
 FileManagerFile CreateFileManagerFile(DocumentItem dataItem)
 {
     return(CreateFileManagerFile(dataItem, CreateParentFolder(dataItem)));
 }