Exemplo n.º 1
0
        public override bool FolderExists(string folderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNull("folderPath", folderPath);
            Requires.NotNull("folderMapping", folderMapping);

            return(DirectoryWrapper.Instance.Exists(PathUtils.Instance.GetPhysicalPath(folderMapping.PortalID, folderPath)));
        }
        public override bool FolderExists(string folderPath, FolderMappingInfo folderMapping)
        {
            Requires.PropertyNotNull("folderPath", folderPath);
            Requires.NotNull("folderMapping", folderMapping);

            return(DirectoryWrapper.Instance.Exists(GetActualPath(folderMapping, folderPath)));
        }
Exemplo n.º 3
0
        public override bool FolderExists(string folderPath, FolderMappingInfo folderMapping)
        {
            Requires.PropertyNotNull("folderPath", folderPath);
            Requires.NotNull("folderMapping", folderMapping);

            return(FolderManager.Instance.GetFolder(folderMapping.PortalID, folderPath) != null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Moves the folder and files at the specified folder path to the new folder path.
        /// </summary>
        public virtual void MoveFolder(string folderPath, string newFolderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNullOrEmpty("folderPath", folderPath);
            Requires.NotNullOrEmpty("newFolderPath", newFolderPath);
            Requires.NotNull("folderMapping", folderMapping);

            var folderProvider = Instance(folderMapping.FolderProviderType);

            AddFolderAndMoveFiles(folderPath, newFolderPath, folderMapping);

            var folderManager = new FolderManager();
            var subFolders    = folderManager.GetFolderMappingFoldersRecursive(folderMapping, folderPath).Skip(1).Reverse();

            foreach (var subFolderPath in subFolders.Select(s => s.Key))
            {
                var newSubFolderPath = newFolderPath + subFolderPath.Substring(folderPath.Length);
                AddFolderAndMoveFiles(subFolderPath, newSubFolderPath, folderMapping);

                folderProvider.DeleteFolder(new FolderInfo {
                    FolderPath = subFolderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.FolderMappingID
                });
            }

            folderProvider.DeleteFolder(new FolderInfo {
                FolderPath = folderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID
            });
        }
Exemplo n.º 5
0
        private static void MoveFiles(IFolderInfo folder, IFolderInfo newFolder, FolderMappingInfo folderMapping)
        {
            var folderProvider = Instance(folderMapping.FolderProviderType);
            var files          = folderProvider.GetFiles(folder);

            foreach (var file in files)
            {
                using (var fileContent = folderProvider.GetFileStream(folder, file))
                {
                    if (!fileContent.CanSeek)
                    {
                        using (var seekableStream = FileManager.Instance.GetSeekableStream(fileContent))
                        {
                            folderProvider.AddFile(newFolder, file, seekableStream);
                        }
                    }
                    else
                    {
                        folderProvider.AddFile(newFolder, file, fileContent);
                    }
                }
                folderProvider.DeleteFile(new FileInfo {
                    FileName = file, Folder = folder.FolderPath, FolderMappingID = folderMapping.FolderMappingID, PortalId = folderMapping.PortalID
                });
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Copies the specified file to the destination folder.
        /// </summary>
        public virtual void CopyFile(string folderPath, string fileName, string newFolderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNull("folderPath", folderPath);
            Requires.NotNullOrEmpty("fileName", fileName);
            Requires.NotNull("newFolderPath", newFolderPath);
            Requires.NotNull("folderMapping", folderMapping);

            if (folderPath == newFolderPath) return;

            var sourceFolder = new FolderInfo { FolderPath = folderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID };
            var destinationFolder = new FolderInfo { FolderPath = newFolderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID };

            using (var fileContent = GetFileStream(sourceFolder, fileName))
            {
                if (!fileContent.CanSeek)
                {
                    using (var seekableStream = FileManager.Instance.GetSeekableStream(fileContent))
                    {
                        AddFile(destinationFolder, fileName, seekableStream);
                    }
                }
                else
                {
                    AddFile(destinationFolder, fileName, fileContent);
                }
            }
        }
Exemplo n.º 7
0
        public override bool FolderExists(string folderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNull("folderPath", folderPath);
            Requires.NotNull("folderMapping", folderMapping);

            return(DataProvider.Instance().GetFolder(folderMapping.PortalID, folderPath).Read());
        }
        public override IEnumerable <string> GetSubFolders(string folderPath, FolderMappingInfo folderMapping)
        {
            Requires.PropertyNotNull("folderPath", folderPath);
            Requires.NotNull("folderMapping", folderMapping);

            return(DirectoryWrapper.Instance.GetDirectories(GetActualPath(folderMapping, folderPath))
                   .Select(directory => GetRelativePath(folderMapping, directory)));
        }
Exemplo n.º 9
0
        public override IEnumerable <string> GetSubFolders(string folderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNull("folderPath", folderPath);
            Requires.NotNull("folderMapping", folderMapping);

            return(DirectoryWrapper.Instance.GetDirectories(PathUtils.Instance.GetPhysicalPath(folderMapping.PortalID, folderPath))
                   .Select(directory => PathUtils.Instance.GetRelativePath(folderMapping.PortalID, directory)));
        }
Exemplo n.º 10
0
        private static void UpdateFolderMappingSettings(FolderMappingInfo objFolderMapping)
        {
            foreach (string sKey in objFolderMapping.FolderMappingSettings.Keys)
            {
                UpdateFolderMappingSetting(objFolderMapping.FolderMappingID, sKey, Convert.ToString(objFolderMapping.FolderMappingSettings[sKey]));
            }

            ClearFolderMappingSettingsCache(objFolderMapping.FolderMappingID);
        }
Exemplo n.º 11
0
        public void UpdateFolderMapping(FolderMappingInfo objFolderMapping)
        {
            dataProvider.UpdateFolderMapping(objFolderMapping.FolderMappingID,
                                             objFolderMapping.MappingName,
                                             objFolderMapping.Priority,
                                             UserController.Instance.GetCurrentUserInfo().UserID);

            ClearFolderMappingCache(objFolderMapping.PortalID);
            UpdateFolderMappingSettings(objFolderMapping);
        }
Exemplo n.º 12
0
        public override IEnumerable <string> GetSubFolders(string folderPath, FolderMappingInfo folderMapping)
        {
            Requires.PropertyNotNull("folderPath", folderPath);
            Requires.NotNull("folderMapping", folderMapping);

            var folderManager = FolderManager.Instance;

            var folder = folderManager.GetFolder(folderMapping.PortalID, folderPath);

            return(folderManager.GetFolders(folder).Select(subfolder => subfolder.FolderPath));
        }
Exemplo n.º 13
0
        public int AddFolderMapping(FolderMappingInfo objFolderMapping)
        {
            objFolderMapping.FolderMappingID = dataProvider.AddFolderMapping(objFolderMapping.PortalID,
                                                                             objFolderMapping.MappingName,
                                                                             objFolderMapping.FolderProviderType,
                                                                             UserController.Instance.GetCurrentUserInfo().UserID);

            UpdateFolderMappingSettings(objFolderMapping);

            ClearFolderMappingCache(objFolderMapping.PortalID);

            return(objFolderMapping.FolderMappingID);
        }
Exemplo n.º 14
0
        public override void CopyFile(string folderPath, string fileName, string newFolderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNull("folderPath", folderPath);
            Requires.NotNullOrEmpty("fileName", fileName);
            Requires.NotNull("newFolderPath", newFolderPath);
            Requires.NotNull("folderMapping", folderMapping);

            if (folderPath == newFolderPath) return;

            var filePath = GetActualPath(folderMapping, folderPath, fileName);
            var newFilePath = GetActualPath(folderMapping, newFolderPath, fileName);

            if (FileWrapper.Instance.Exists(filePath))
            {
                FileWrapper.Instance.Copy(filePath, newFilePath, true);
            }
        }
        public void DeleteFile_Calls_FolderProviderDeleteFile()
        {
            //Arrange
            var fileInfo = new FileInfoBuilder().Build();
            _fileVersionController.Setup(fv => fv.DeleteAllUnpublishedVersions(fileInfo, false));

            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };
            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);
            
            _mockData.Setup(md => md.DeleteFile(It.IsAny<int>(), It.IsAny<string>(), It.IsAny<int>()));

            _mockFolderProvider.Setup(mf => mf.DeleteFile(fileInfo)).Verifiable();

            string someString;
            _mockFileLockingController.Setup(mflc => mflc.IsFileLocked(fileInfo, out someString)).Returns(false);

            //Act
            FileDeletionController.Instance.DeleteFile(fileInfo);

            //Assert
            _mockFolderProvider.Verify();
        }
 /// <summary>
 /// Get the path relative to the root of the FolderMapping
 /// </summary>
 /// <param name="folderMapping">Path is relative to this</param>
 /// <param name="path">The path</param>
 /// <returns>A relative path</returns>
 protected virtual string GetRelativePath(FolderMappingInfo folderMapping, string path)
 {
     return(PathUtils.Instance.GetRelativePath(folderMapping.PortalID, path));
 }
Exemplo n.º 17
0
        public void ExistsFolder_Returns_False_When_Folder_Does_Not_Exist()
        {
            var folderMapping = new FolderMappingInfo { PortalID = Constants.CONTENT_ValidPortalId };

            _pathUtils.Setup(pu => pu.GetPhysicalPath(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderRelativePath)).Returns(Constants.FOLDER_ValidFolderPath);

            _directoryWrapper.Setup(dw => dw.Exists(Constants.FOLDER_ValidFolderPath)).Returns(false);

            var result = _sfp.FolderExists(Constants.FOLDER_ValidFolderRelativePath, folderMapping);

            Assert.IsFalse(result);
        }
Exemplo n.º 18
0
        public void GetSubFolders_Throws_On_Null_FolderPath()
        {
            var folderMapping = new FolderMappingInfo();

            _sfp.GetSubFolders(null, folderMapping).ToList();
        }
        /// <summary>
        /// Get actual path to a file
        /// </summary>
        /// <param name="folderMapping">Folder Mapping of the folder</param>
        /// <param name="folderPath">Folder Path where the file is contained</param>
        /// <param name="fileName">Name of the file</param>
        /// <returns>A windows supported path to the file</returns>
        protected virtual string GetActualPath(FolderMappingInfo folderMapping, string folderPath, string fileName)
        {
            var actualFolderPath = GetActualPath(folderMapping, folderPath);

            return(Path.Combine(actualFolderPath, fileName));
        }
Exemplo n.º 20
0
 public override void AddFolder(string folderPath, FolderMappingInfo folderMapping)
 {
 }
 public override void AddFolder(string folderPath, FolderMappingInfo folderMapping)
 {
 }
Exemplo n.º 22
0
        public void MoveFile_Calls_DeleteFile_When_A_File_With_The_Same_Name_Exists_On_The_Destination_Folder()
        {
            _fileInfo.Setup(fi => fi.FileName).Returns(Constants.FOLDER_ValidFileName);
            _fileInfo.Setup(fi => fi.PortalId).Returns(Constants.CONTENT_ValidPortalId);
            _fileInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);
            _fileInfo.Setup(fi => fi.FolderId).Returns(Constants.FOLDER_ValidFolderId);
            _fileInfo.Setup(fi => fi.StartDate).Returns(DateTime.Parse(Constants.FOLDER_FileStartDate));

            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);
            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.FolderID).Returns(Constants.FOLDER_OtherValidFolderId);

            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            var fileContent = new MemoryStream();

            _mockFileManager.Setup(mfm => mfm.GetFileContent(_fileInfo.Object)).Returns(fileContent);
            string someString;
            _mockFileLockingController.Setup(mflc => mflc.IsFileLocked(_fileInfo.Object, out someString)).Returns(false);
            _mockFileManager.Setup(mfm => mfm.MoveVersions(_fileInfo.Object, It.IsAny<IFolderInfo>(), It.IsAny<FolderProvider>(), It.IsAny<FolderProvider>()));

            var existingFile = new FileInfo();
            _mockFileManager.Setup(mfm => mfm.GetFile(_folderInfo.Object, Constants.FOLDER_ValidFileName, It.IsAny<bool>())).Returns(existingFile);

            _mockFileManager.Setup(mfm => mfm.DeleteFile(existingFile)).Verifiable();

            _mockFileManager.Object.MoveFile(_fileInfo.Object, _folderInfo.Object);

            _mockFileManager.Verify();
        }
Exemplo n.º 23
0
 /// <inheritdoc/>
 protected override string GetActualPath(FolderMappingInfo folderMapping, string folderPath, string fileName)
 {
     return(base.GetActualPath(folderMapping, folderPath, fileName) + this.ProtectedExtension);
 }
Exemplo n.º 24
0
        public void MoveFile_Calls_FolderProvider_AddFile_And_DeleteFile_And_FileManager_UpdateFile()
        {
            _fileInfo.Setup(fi => fi.FileName).Returns(Constants.FOLDER_ValidFileName);
            _fileInfo.Setup(fi => fi.PortalId).Returns(Constants.CONTENT_ValidPortalId);
            _fileInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);
            _fileInfo.Setup(fi => fi.FolderId).Returns(Constants.FOLDER_ValidFolderId);

            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);
            _folderInfo.Setup(fi => fi.FolderID).Returns(Constants.FOLDER_OtherValidFolderId);
            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);

            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            var fileContent = new MemoryStream();

            _mockFileManager.Setup(mfm => mfm.GetFileContent(_fileInfo.Object)).Returns(fileContent);
            string someString;
            _mockFileLockingController.Setup(mflc => mflc.IsFileLocked(_fileInfo.Object, out someString)).Returns(false);
            _mockFileManager.Setup(mfm => mfm.MoveVersions(_fileInfo.Object, It.IsAny<IFolderInfo>(), It.IsAny<FolderProvider>(), It.IsAny<FolderProvider>()));

            _mockFolder.Setup(mf => mf.AddFile(_folderInfo.Object, Constants.FOLDER_ValidFileName, fileContent)).Verifiable();
            _mockFolder.Setup(mf => mf.DeleteFile(_fileInfo.Object)).Verifiable();

            _mockFileManager.Setup(mfm => mfm.UpdateFile(_fileInfo.Object)).Verifiable();

            _mockFileManager.Object.MoveFile(_fileInfo.Object, _folderInfo.Object);

            _mockFolder.Verify();
            _mockFileManager.Verify();
        }
Exemplo n.º 25
0
        public void MoveFile_Updates_FolderId_And_Folder()
        {
            _fileInfo.Setup(fi => fi.FileName).Returns(Constants.FOLDER_ValidFileName);
            _fileInfo.Setup(fi => fi.PortalId).Returns(Constants.CONTENT_ValidPortalId);
            _fileInfo.Setup(fi => fi.FolderId).Returns(Constants.FOLDER_ValidFolderId);
            _fileInfo.Setup(fi => fi.Folder).Returns(Constants.FOLDER_ValidFolderRelativePath);
            _fileInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);
            _fileInfo.Setup(fi => fi.StartDate).Returns(DateTime.Parse(Constants.FOLDER_FileStartDate));

            _folderInfo.Setup(fi => fi.FolderID).Returns(Constants.FOLDER_OtherValidFolderId);
            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.FolderPath).Returns(Constants.FOLDER_OtherValidFolderRelativePath);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);

            _fileInfo.SetupSet(fi => fi.FolderId = Constants.FOLDER_OtherValidFolderId).Verifiable();
            _fileInfo.SetupSet(fi => fi.Folder = Constants.FOLDER_OtherValidFolderRelativePath).Verifiable();

            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            var fileContent = new MemoryStream();

            _mockFileManager.Setup(mfm => mfm.GetFileContent(_fileInfo.Object)).Returns(fileContent);
            string someString;
            _mockFileLockingController.Setup(mflc => mflc.IsFileLocked(_fileInfo.Object, out someString)).Returns(false);
            _mockFileManager.Setup(mfm => mfm.MoveVersions(_fileInfo.Object, It.IsAny<IFolderInfo>(), It.IsAny<FolderProvider>(), It.IsAny<FolderProvider>()));
            _mockFileManager.Object.MoveFile(_fileInfo.Object, _folderInfo.Object);

            _fileInfo.Verify();
        }
Exemplo n.º 26
0
        public void ExistsFile_Returns_False_When_File_Does_Not_Exist()
        {
            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.FolderID).Returns(Constants.FOLDER_ValidFolderId);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);

            _mockFileManager.Setup(mfm => mfm.GetFile(_folderInfo.Object, Constants.FOLDER_ValidFileName, It.IsAny<bool>())).Returns(_fileInfo.Object);

            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            _mockFolder.Setup(mf => mf.FileExists(_folderInfo.Object, Constants.FOLDER_ValidFileName)).Returns(false);

            var result = _mockFileManager.Object.FileExists(_folderInfo.Object, Constants.FOLDER_ValidFileName);

            Assert.IsFalse(result);
        }
Exemplo n.º 27
0
        public void ExistsFile_Calls_FolderProvider_ExistsFile()
        {
            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.FolderID).Returns(Constants.FOLDER_ValidFolderId);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);

            _mockFileManager.Setup(mfm => mfm.GetFile(_folderInfo.Object, Constants.FOLDER_ValidFileName, It.IsAny<bool>())).Returns(_fileInfo.Object);

            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            _mockFolder.Setup(mf => mf.FileExists(_folderInfo.Object, Constants.FOLDER_ValidFileName)).Returns(true).Verifiable();

            _mockFileManager.Object.FileExists(_folderInfo.Object, Constants.FOLDER_ValidFileName);

            _mockFolder.Verify();
        }
Exemplo n.º 28
0
        public void AddFile_Does_Not_Call_FolderProvider_AddFile_When_Not_Overwritting_And_File_Exists()
        {
            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.FolderID).Returns(Constants.FOLDER_ValidFolderId);
            _folderInfo.Setup(fi => fi.PhysicalPath).Returns(Constants.FOLDER_ValidFolderPath);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);
            _folderInfo.Setup(fi => fi.WorkflowID).Returns(Null.NullInteger);

            var fileContent = new MemoryStream();

            _portalController.Setup(pc => pc.HasSpaceAvailable(Constants.CONTENT_ValidPortalId, fileContent.Length)).Returns(true);

            _globals.Setup(g => g.GetSubFolderPath(Constants.FOLDER_ValidFilePath, Constants.CONTENT_ValidPortalId)).Returns(Constants.FOLDER_ValidFolderRelativePath);

            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            _mockFolder.Setup(mf => mf.FileExists(_folderInfo.Object, Constants.FOLDER_ValidFileName)).Returns(true);
            _mockFolder.Setup(mf => mf.AddFile(_folderInfo.Object, Constants.FOLDER_ValidFileName, fileContent));

            _mockFileManager.Setup(mfm => mfm.IsAllowedExtension(Constants.FOLDER_ValidFileName)).Returns(true);
            _mockFileManager.Setup(mfm => mfm.UpdateFile(It.IsAny<IFileInfo>(), It.IsAny<Stream>()));
            _mockFileManager.Setup(mfm => mfm.CreateFileContentItem()).Returns(new ContentItem());

            _contentWorkflowController.Setup(wc => wc.GetWorkflowByID(It.IsAny<int>())).Returns((ContentWorkflow)null);

            _mockData.Setup(
                md =>
                md.AddFile(It.IsAny<int>(),
                           It.IsAny<Guid>(),
                           It.IsAny<Guid>(),
                           It.IsAny<string>(),
                           It.IsAny<string>(),
                           It.IsAny<long>(),
                           It.IsAny<int>(),
                           It.IsAny<int>(),
                           It.IsAny<string>(),
                           It.IsAny<string>(),
                           It.IsAny<int>(),
                           It.IsAny<int>(),
                           It.IsAny<string>(),
                           It.IsAny<DateTime>(),
                           It.IsAny<string>(),
                           It.IsAny<DateTime>(),
                           It.IsAny<DateTime>(),
                           It.IsAny<bool>(),
                           It.IsAny<int>()))
               .Returns(Constants.FOLDER_ValidFileId);
            
            _mockData.Setup(md => md.UpdateFileLastModificationTime(It.IsAny<int>(), It.IsAny<DateTime>()));

            _mockFileManager.Object.AddFile(_folderInfo.Object, Constants.FOLDER_ValidFileName, fileContent, false, false, Constants.CONTENTTYPE_ValidContentType);

            _mockFolder.Verify(mf => mf.AddFile(It.IsAny<IFolderInfo>(), It.IsAny<string>(), It.IsAny<Stream>()), Times.Never());
        }
Exemplo n.º 29
0
        public override void CopyFile(string folderPath, string fileName, string newFolderPath, FolderMappingInfo folderMapping)
        {
            Requires.PropertyNotNull("folderPath", folderPath);
            Requires.NotNullOrEmpty("fileName", fileName);
            Requires.PropertyNotNull("newFolderPath", newFolderPath);
            Requires.NotNull("folderMapping", folderMapping);

            if (folderPath == newFolderPath)
            {
                return;
            }

            var sourceFolder      = FolderManager.Instance.GetFolder(folderMapping.PortalID, folderPath);
            var destinationFolder = FolderManager.Instance.GetFolder(folderMapping.PortalID, newFolderPath);

            Requires.NotNull("sourceFolder", sourceFolder);
            Requires.NotNull("destinationFolder", destinationFolder);

            using (var fileContent = this.GetFileStream(sourceFolder, fileName))
            {
                if (!fileContent.CanSeek)
                {
                    using (var seekableStream = FileManager.Instance.GetSeekableStream(fileContent))
                    {
                        this.AddFile(destinationFolder, fileName, seekableStream);
                    }
                }
                else
                {
                    this.AddFile(destinationFolder, fileName, fileContent);
                }
            }
        }
Exemplo n.º 30
0
        public void RenameFile_Calls_FolderProvider_RenameFile_When_FileNames_Are_Distinct_And_NewFileName_Does_Not_Exist()
        {
            _fileInfo.Setup(fi => fi.FileName).Returns(Constants.FOLDER_ValidFileName);
            _fileInfo.Setup(fi => fi.PortalId).Returns(Constants.CONTENT_ValidPortalId);
            _fileInfo.Setup(fi => fi.FolderId).Returns(Constants.FOLDER_ValidFolderId);
            _fileInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);

            _folderManager.Setup(fm => fm.GetFolder(Constants.FOLDER_ValidFolderId)).Returns(_folderInfo.Object);

            _mockFileManager.Setup(mfm => mfm.FileExists(_folderInfo.Object, Constants.FOLDER_OtherValidFileName, It.IsAny<bool>())).Returns(false);
            _mockFileManager.Setup(mfm => mfm.UpdateFile(_fileInfo.Object));

            var folderMapping = new FolderMappingInfo();
            folderMapping.FolderProviderType = Constants.FOLDER_ValidFolderProviderType;

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            _mockFileManager.Object.RenameFile(_fileInfo.Object, Constants.FOLDER_OtherValidFileName);

            _mockFolder.Verify(mf => mf.RenameFile(_fileInfo.Object, Constants.FOLDER_OtherValidFileName), Times.Once());
        }
Exemplo n.º 31
0
 /// <summary>
 ///   Gets the list of subfolders for the specified folder.
 /// </summary>
 public abstract IEnumerable<string> GetSubFolders(string folderPath, FolderMappingInfo folderMapping);
Exemplo n.º 32
0
        public void RenameFile_Throws_When_FolderProvider_Throws()
        {
            _fileInfo.Setup(fi => fi.FileName).Returns(Constants.FOLDER_ValidFileName);
            _fileInfo.Setup(fi => fi.PortalId).Returns(Constants.CONTENT_ValidPortalId);
            _fileInfo.Setup(fi => fi.FolderId).Returns(Constants.FOLDER_ValidFolderId);
            _fileInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);

            _folderManager.Setup(fm => fm.GetFolder(Constants.FOLDER_ValidFolderId)).Returns(_folderInfo.Object);

            _mockFileManager.Setup(mfm => mfm.FileExists(_folderInfo.Object, Constants.FOLDER_OtherValidFileName, It.IsAny<bool>())).Returns(false);
            _mockFileManager.Setup(mfm => mfm.UpdateFile(_fileInfo.Object));

            var folderMapping = new FolderMappingInfo();
            folderMapping.FolderProviderType = Constants.FOLDER_ValidFolderProviderType;

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            _mockFolder.Setup(mf => mf.RenameFile(_fileInfo.Object, Constants.FOLDER_OtherValidFileName)).Throws<Exception>();

            _mockFileManager.Object.RenameFile(_fileInfo.Object, Constants.FOLDER_OtherValidFileName);
        }
Exemplo n.º 33
0
        public void AddFile_Checks_Space_For_Stream_Length()
        {
            //Arrange
            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.FolderID).Returns(Constants.FOLDER_ValidFolderId);
            _folderInfo.Setup(fi => fi.PhysicalPath).Returns(Constants.FOLDER_ValidFolderPath);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);
            _folderInfo.Setup(fi => fi.WorkflowID).Returns(Null.NullInteger);

            var fileContent = new MemoryStream(Encoding.ASCII.GetBytes("some data here"));

            _portalController.Setup(pc => pc.HasSpaceAvailable(It.IsAny<int>(), It.IsAny<long>())).Returns(true);

            _globals.Setup(g => g.GetSubFolderPath(Constants.FOLDER_ValidFilePath, Constants.CONTENT_ValidPortalId)).Returns(Constants.FOLDER_ValidFolderRelativePath);


            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            _mockFolder.Setup(mf => mf.FileExists(_folderInfo.Object, Constants.FOLDER_ValidFileName)).Returns(false);
            _mockFolder.Setup(mf => mf.AddFile(_folderInfo.Object, Constants.FOLDER_ValidFileName, fileContent)).Verifiable();

            _mockFileManager.Setup(mfm => mfm.IsAllowedExtension(Constants.FOLDER_ValidFileName)).Returns(true);
            _mockFileManager.Setup(mfm => mfm.CreateFileContentItem()).Returns(new ContentItem());

            _contentWorkflowController.Setup(wc => wc.GetWorkflowByID(It.IsAny<int>())).Returns((ContentWorkflow)null);

            //Act
            _mockFileManager.Object.AddFile(_folderInfo.Object, Constants.FOLDER_ValidFileName, fileContent, true, false, Constants.CONTENTTYPE_ValidContentType);

            //Assert
            _portalController.Verify(pc => pc.HasSpaceAvailable(Constants.CONTENT_ValidPortalId, fileContent.Length));
        }
        public void DeleteFile_Throws_WhenFolderProviderThrows()
        {
            //Arrange
            var fileInfo = new FileInfoBuilder().Build();
            
            _fileVersionController.Setup(fv => fv.DeleteAllUnpublishedVersions(fileInfo, false));

            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            string someString;
            _mockFileLockingController.Setup(mflc => mflc.IsFileLocked(fileInfo, out someString)).Returns(false);

            _mockFolderProvider.Setup(mf => mf.DeleteFile(fileInfo)).Throws<Exception>();

            
            FileDeletionController.Instance.DeleteFile(fileInfo);
        }
Exemplo n.º 35
0
 private FolderMappingViewModel GetFolderMappingViewModel(FolderMappingInfo folderMapping)
 {
     return new FolderMappingViewModel
     {
         Id = folderMapping.FolderMappingID,
         FolderTypeName = folderMapping.FolderProviderType,
         Name = folderMapping.MappingName
     };
 }
Exemplo n.º 36
0
 /// <summary>
 ///   Checks the existence of the specified folder in the underlying system.
 /// </summary>
 public abstract bool FolderExists(string folderPath, FolderMappingInfo folderMapping);
Exemplo n.º 37
0
        public void GetSubFolders_Calls_DirectoryWrapper_GetDirectories()
        {
            var folderMapping = new FolderMappingInfo { PortalID = Constants.CONTENT_ValidPortalId };

            _pathUtils.Setup(pu => pu.GetPhysicalPath(folderMapping.PortalID, Constants.FOLDER_ValidFolderRelativePath)).Returns(Constants.FOLDER_ValidFolderPath);

            _sfp.GetSubFolders(Constants.FOLDER_ValidFolderRelativePath, folderMapping).ToList();

            _directoryWrapper.Verify(dw => dw.GetDirectories(Constants.FOLDER_ValidFolderPath), Times.Once());
        }
Exemplo n.º 38
0
        /// <summary>
        /// Copies the specified file to the destination folder.
        /// </summary>
        public virtual void CopyFile(string folderPath, string fileName, string newFolderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNull("folderPath", folderPath);
            Requires.NotNullOrEmpty("fileName", fileName);
            Requires.NotNull("newFolderPath", newFolderPath);
            Requires.NotNull("folderMapping", folderMapping);

            if (folderPath == newFolderPath)
            {
                return;
            }

            var sourceFolder = new FolderInfo {
                FolderPath = folderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID
            };
            var destinationFolder = new FolderInfo {
                FolderPath = newFolderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID
            };

            using (var fileContent = GetFileStream(sourceFolder, fileName))
            {
                if (!fileContent.CanSeek)
                {
                    using (var seekableStream = FileManager.Instance.GetSeekableStream(fileContent))
                    {
                        AddFile(destinationFolder, fileName, seekableStream);
                    }
                }
                else
                {
                    AddFile(destinationFolder, fileName, fileContent);
                }
            }
        }
 public override void MoveFolder(string folderPath, string newFolderPath, FolderMappingInfo folderMapping)
 {
     // The folder has already been moved in filesystem
 }
Exemplo n.º 40
0
        public void GetSubFolders_Returns_Valid_SubFolders_When_Folder_Is_Not_Empty()
        {
            var expectedSubFolders = new[] {
                Constants.FOLDER_ValidSubFolderRelativePath,
                Constants.FOLDER_OtherValidSubFolderRelativePath
            };

            var folderMapping = new FolderMappingInfo { PortalID = Constants.CONTENT_ValidPortalId };

            _pathUtils.Setup(pu => pu.GetPhysicalPath(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderRelativePath)).Returns(Constants.FOLDER_ValidFolderPath);
            _pathUtils.Setup(pu => pu.GetRelativePath(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidSubFolderPath)).Returns(Constants.FOLDER_ValidSubFolderRelativePath);
            _pathUtils.Setup(pu => pu.GetRelativePath(Constants.CONTENT_ValidPortalId, Constants.FOLDER_OtherValidSubFolderPath)).Returns(Constants.FOLDER_OtherValidSubFolderRelativePath);

            var subFolders = new[] {
                Constants.FOLDER_ValidSubFolderPath,
                Constants.FOLDER_OtherValidSubFolderPath
            };

            _directoryWrapper.Setup(dw => dw.GetDirectories(Constants.FOLDER_ValidFolderPath)).Returns(subFolders);

            var result = _sfp.GetSubFolders(Constants.FOLDER_ValidFolderRelativePath, folderMapping).ToList();

            CollectionAssert.AreEqual(expectedSubFolders, result);
        }
 /// <summary>
 /// Get actual path to a folder in the specified folder mapping
 /// </summary>
 /// <param name="folderMapping">The folder mapping</param>
 /// <param name="folderPath">The folder path</param>
 /// <returns>A windows supported path to the folder</returns>
 protected virtual string GetActualPath(FolderMappingInfo folderMapping, string folderPath)
 {
     return(PathUtils.Instance.GetPhysicalPath(folderMapping.PortalID, folderPath));
 }
Exemplo n.º 42
0
 public override void MoveFolder(string folderPath, string newFolderPath, FolderMappingInfo folderMapping)
 {
     // The folder has already been moved in filesystem
 }
        public override void CopyFile(string folderPath, string fileName, string newFolderPath, FolderMappingInfo folderMapping)
        {
            Requires.PropertyNotNull("folderPath", folderPath);
            Requires.NotNullOrEmpty("fileName", fileName);
            Requires.PropertyNotNull("newFolderPath", newFolderPath);
            Requires.NotNull("folderMapping", folderMapping);

            if (folderPath == newFolderPath)
            {
                return;
            }

            var filePath    = GetActualPath(folderMapping, folderPath, fileName);
            var newFilePath = GetActualPath(folderMapping, newFolderPath, fileName);

            if (FileWrapper.Instance.Exists(filePath))
            {
                FileWrapper.Instance.Copy(filePath, newFilePath, true);
            }
        }
Exemplo n.º 44
0
 /// <summary>
 /// Get actual path to a file
 /// </summary>
 /// <param name="folderMapping">Folder Mapping of the folder</param>
 /// <param name="folderPath">Folder Path where the file is contained</param>
 /// <param name="fileName">Name of the file</param>
 /// <returns>A windows supported path to the file</returns>
 protected virtual string GetActualPath(FolderMappingInfo folderMapping, string folderPath, string fileName)
 {
     var actualFolderPath = GetActualPath(folderMapping, folderPath);
     return Path.Combine(actualFolderPath, fileName);
 }
Exemplo n.º 45
0
        public void ExistsFolder_Throws_On_Null_FolderPath()
        {
            var folderMapping = new FolderMappingInfo();

            _sfp.FolderExists(null, folderMapping);
        }
Exemplo n.º 46
0
 /// <summary>
 /// Get actual path to a folder in the specified folder mapping
 /// </summary>
 /// <param name="folderMapping">The folder mapping</param>
 /// <param name="folderPath">The folder path</param>
 /// <returns>A windows supported path to the folder</returns>
 protected virtual string GetActualPath(FolderMappingInfo folderMapping, string folderPath)
 {
     return PathUtils.Instance.GetPhysicalPath(folderMapping.PortalID, folderPath);
 }
Exemplo n.º 47
0
 public virtual void AddFolder(string folderPath, FolderMappingInfo folderMapping, string mappedPath)
 {
     AddFolder(folderPath, folderMapping);
 }
Exemplo n.º 48
0
 /// <summary>
 /// Get the path relative to the root of the FolderMapping
 /// </summary>
 /// <param name="folderMapping">Path is relative to this</param>
 /// <param name="path">The path</param>
 /// <returns>A relative path</returns>
 protected virtual string GetRelativePath(FolderMappingInfo folderMapping, string path)
 {
     return PathUtils.Instance.GetRelativePath(folderMapping.PortalID, path);
 }
Exemplo n.º 49
0
        private static void AddFolderAndMoveFiles(string folderPath, string newFolderPath, FolderMappingInfo folderMapping)
        {
            var folderProvider = Instance(folderMapping.FolderProviderType);

            if (!folderProvider.FolderExists(newFolderPath, folderMapping))
            {
                folderProvider.AddFolder(newFolderPath, folderMapping);
            }

            var folder = new FolderInfo {
                FolderPath = folderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID
            };
            var newFolder = new FolderInfo {
                FolderPath = newFolderPath, FolderMappingID = folderMapping.FolderMappingID, PortalID = folderMapping.PortalID
            };

            MoveFiles(folder, newFolder, folderMapping);
        }
Exemplo n.º 50
0
        public void GetSubFolders_Count_Equals_DirectoryWrapper_GetDirectories_Count()
        {
            var folderMapping = new FolderMappingInfo { PortalID = Constants.CONTENT_ValidPortalId };

            _pathUtils.Setup(pu => pu.GetPhysicalPath(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderRelativePath)).Returns(Constants.FOLDER_ValidFolderPath);
            _pathUtils.Setup(pu => pu.GetRelativePath(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidSubFolderPath)).Returns(Constants.FOLDER_ValidSubFolderRelativePath);
            _pathUtils.Setup(pu => pu.GetRelativePath(Constants.CONTENT_ValidPortalId, Constants.FOLDER_OtherValidSubFolderPath)).Returns(Constants.FOLDER_OtherValidSubFolderRelativePath);

            var subFolders = new[] {
                Constants.FOLDER_ValidSubFolderPath,
                Constants.FOLDER_OtherValidSubFolderPath
            };

            _directoryWrapper.Setup(dw => dw.GetDirectories(Constants.FOLDER_ValidFolderPath)).Returns(subFolders);

            var result = _sfp.GetSubFolders(Constants.FOLDER_ValidFolderRelativePath, folderMapping).ToList();

            Assert.AreEqual(subFolders.Length, result.Count);
        }
Exemplo n.º 51
0
 /// <summary>
 ///   Adds a new folder to a specified parent folder.
 /// </summary>
 public abstract void AddFolder(string folderPath, FolderMappingInfo folderMapping);
Exemplo n.º 52
0
        public void AddFile_Throws_When_Portal_Has_No_Space_Available()
        {
            _folderInfo.Setup(fi => fi.PortalID).Returns(Constants.CONTENT_ValidPortalId);
            _folderInfo.Setup(fi => fi.PhysicalPath).Returns(Constants.FOLDER_ValidFolderPath);
            _folderInfo.Setup(fi => fi.PhysicalPath).Returns(Constants.FOLDER_ValidFolderPath);
            _folderInfo.Setup(fi => fi.FolderMappingID).Returns(Constants.FOLDER_ValidFolderMappingID);

            _mockData.Setup(c => c.GetProviderPath()).Returns(String.Empty);

            var fileContent = new MemoryStream();

            _globals.Setup(g => g.GetSubFolderPath(Constants.FOLDER_ValidFilePath, Constants.CONTENT_ValidPortalId)).Returns(Constants.FOLDER_ValidFolderRelativePath);

            var folderMapping = new FolderMappingInfo { FolderProviderType = Constants.FOLDER_ValidFolderProviderType };

            _folderMappingController.Setup(fmc => fmc.GetFolderMapping(Constants.CONTENT_ValidPortalId, Constants.FOLDER_ValidFolderMappingID)).Returns(folderMapping);

            _portalController.Setup(pc => pc.HasSpaceAvailable(Constants.CONTENT_ValidPortalId, fileContent.Length)).Returns(false);
            
            _mockFileManager.Setup(fm => fm.CreateFileContentItem()).Returns(new ContentItem());

            _mockFileManager.Object.AddFile(_folderInfo.Object, Constants.FOLDER_ValidFileName, fileContent, false, false, Constants.CONTENTTYPE_ValidContentType);
        }
Exemplo n.º 53
0
 /// <summary>
 ///   Gets the list of subfolders for the specified folder.
 /// </summary>
 public abstract IEnumerable <string> GetSubFolders(string folderPath, FolderMappingInfo folderMapping);
Exemplo n.º 54
0
        public override bool FolderExists(string folderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNull("folderPath", folderPath);
            Requires.NotNull("folderMapping", folderMapping);

            return DirectoryWrapper.Instance.Exists(GetActualPath(folderMapping, folderPath));
        }
        private void cmdUpdate_Click(object sender, EventArgs e)
        {
            Page.Validate("vgEditFolderMapping");

            if (!Page.IsValid) return;

            try
            {
                var folderMapping = new FolderMappingInfo();

                if (FolderMappingID != Null.NullInteger)
                {
                    folderMapping = _folderMappingController.GetFolderMapping(FolderMappingID) ?? new FolderMappingInfo();
                }

                folderMapping.FolderMappingID = FolderMappingID;
                folderMapping.MappingName = txtName.Text;
                folderMapping.FolderProviderType = cboFolderProviders.SelectedValue;
                folderMapping.PortalID = FolderPortalID;

                var originalSettings = folderMapping.FolderMappingSettings;

                try
                {
                    var folderMappingID = FolderMappingID;

                    if (folderMappingID == Null.NullInteger)
                    {
                        folderMappingID = _folderMappingController.AddFolderMapping(folderMapping);
                    }
                    else
                    {
                        _folderMappingController.UpdateFolderMapping(folderMapping);
                    }

                    if (phProviderSettings.Controls.Count > 0 && phProviderSettings.Controls[0] is FolderMappingSettingsControlBase)
                    {
                        var settingsControl = (FolderMappingSettingsControlBase)phProviderSettings.Controls[0];

                        try
                        {
                            settingsControl.UpdateSettings(folderMappingID);
                        }
                        catch
                        {
                            if (FolderMappingID == Null.NullInteger)
                            {
                                _folderMappingController.DeleteFolderMapping(FolderPortalID, folderMappingID);
                            }
                            return;
                        }
                    }

                    if (FolderMappingID != Null.NullInteger)
                    {
                        // Check if some setting has changed
                        var updatedSettings = _folderMappingController.GetFolderMappingSettings(FolderMappingID);

                        if (originalSettings.Keys.Cast<object>().Any(key => updatedSettings.ContainsKey(key) && !originalSettings[key].ToString().Equals(updatedSettings[key].ToString())))
                        {
                            // Re-synchronize folders using the existing mapping. It's important to synchronize them in descending order
                            var folders = FolderManager.Instance.GetFolders(FolderPortalID).Where(f => f.FolderMappingID == FolderMappingID).OrderByDescending(f => f.FolderPath);

                            foreach (var folder in folders)
                            {
                                FolderManager.Instance.Synchronize(FolderPortalID, folder.FolderPath, false, true);
                            }
                        }
                    }
                }
                catch
                {
                    UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("DuplicateMappingName", LocalResourceFile), ModuleMessage.ModuleMessageType.RedError);
                    return;
                }

                Response.Redirect(EditUrl("FolderMappings"));
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemplo n.º 56
0
        public override IEnumerable<string> GetSubFolders(string folderPath, FolderMappingInfo folderMapping)
        {
            Requires.NotNull("folderPath", folderPath);
            Requires.NotNull("folderMapping", folderMapping);

            return DirectoryWrapper.Instance.GetDirectories(GetActualPath(folderMapping, folderPath))
                .Select(directory => GetRelativePath(folderMapping, directory));
        }