Ejemplo n.º 1
0
        public virtual string OnRenameFolder(string virtualPath)
        {
            string returnValue = string.Empty;

            try
            {
                returnValue = Check_CanAddToFolder(FileSystemValidation.GetDestinationFolder(virtualPath));
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                returnValue = Check_CanDeleteFolder(virtualPath);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }
            }
            catch (Exception ex)
            {
                return(LogUnknownError(ex, virtualPath));
            }

            return(returnValue);
        }
Ejemplo n.º 2
0
        public override string MoveDirectory(string path, string newPath)
        {
            try
            {
                var virtualPath            = FileSystemValidation.ToVirtualPath(path);
                var virtualNewPath         = FileSystemValidation.ToVirtualPath(newPath);
                var virtualDestinationPath = FileSystemValidation.GetDestinationFolder(virtualNewPath);

                string returnValue;
                var    isRename = FileSystemValidation.GetDestinationFolder(virtualPath) == virtualDestinationPath;
                if (isRename)
                {
                    //rename directory
                    returnValue = DNNValidator.OnRenameFolder(virtualPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }
                else
                {
                    //move directory
                    returnValue = DNNValidator.OnMoveFolder(virtualPath, virtualDestinationPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }

                //Are all items visible to user?
                FolderInfo folder = DNNValidator.GetUserFolder(virtualPath);
                if (!(CheckAllChildrenVisible(ref folder)))
                {
                    return(DNNValidator.LogDetailError(ErrorCodes.CannotMoveFolder_ChildrenVisible));
                }

                if (isRename)
                {
                    var dnnFolderToRename = FolderManager.Instance.GetFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(virtualPath));
                    var newFolderName     = virtualNewPath.TrimEnd('/').Split('/').LastOrDefault();
                    FolderManager.Instance.RenameFolder(dnnFolderToRename, newFolderName);
                }
                else             // move
                {
                    var dnnFolderToMove      = FolderManager.Instance.GetFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(virtualPath));
                    var dnnDestinationFolder = FolderManager.Instance.GetFolder(PortalSettings.PortalId, FileSystemValidation.ToDBPath(virtualDestinationPath));
                    FolderManager.Instance.MoveFolder(dnnFolderToMove, dnnDestinationFolder);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
        public override string MoveDirectory(string path, string newPath)
        {
            try
            {
                string virtualPath            = (string)(string)FileSystemValidation.ToVirtualPath(path);
                string virtualNewPath         = (string)(string)FileSystemValidation.ToVirtualPath(newPath);
                string virtualDestinationPath = FileSystemValidation.GetDestinationFolder(virtualNewPath);

                string returnValue = string.Empty;
                if (FileSystemValidation.GetDestinationFolder(virtualPath) == virtualDestinationPath)
                {
                    //rename directory
                    returnValue = DNNValidator.OnRenameFolder(virtualPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }
                else
                {
                    //move directory
                    returnValue = DNNValidator.OnMoveFolder(virtualPath, virtualDestinationPath);
                    if (!(string.IsNullOrEmpty(returnValue)))
                    {
                        return(returnValue);
                    }
                }

                //Are all items visible to user?
                FolderInfo folder = DNNValidator.GetUserFolder(virtualPath);
                if (!(CheckAllChildrenVisible(ref folder)))
                {
                    return(DNNValidator.LogDetailError(ErrorCodes.CannotMoveFolder_ChildrenVisible));
                }

                //Returns errors or empty string when successful (ie: Cannot create a file when that file already exists)
                returnValue = TelerikContent.MoveDirectory(virtualPath, virtualNewPath);

                if (string.IsNullOrEmpty(returnValue))
                {
                    //make sure folder name is being updated in database
                    DNNValidator.OnFolderRenamed(virtualPath, virtualNewPath);
                    //Sync to remove old folder & files
                    FileSystemUtils.SynchronizeFolder(PortalSettings.PortalId, HttpContext.Current.Request.MapPath(virtualPath), FileSystemValidation.ToDBPath(virtualPath), true, true, true);
                    //Sync to add new folder & files
                    FileSystemUtils.SynchronizeFolder(PortalSettings.PortalId, HttpContext.Current.Request.MapPath(virtualNewPath), FileSystemValidation.ToDBPath(virtualNewPath), true, true, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }
Ejemplo n.º 4
0
        public override string CopyDirectory(string path, string newPath)
        {
            try
            {
                string virtualPath            = FileSystemValidation.ToVirtualPath(path);
                string virtualNewPath         = FileSystemValidation.ToVirtualPath(newPath);
                string virtualDestinationPath = FileSystemValidation.GetDestinationFolder(virtualNewPath);

                string returnValue = DNNValidator.OnCopyFolder(virtualPath, virtualDestinationPath);
                if (!(string.IsNullOrEmpty(returnValue)))
                {
                    return(returnValue);
                }

                //Are all items visible to user?
                //todo: copy visible files and folders only?
                FolderInfo folder = DNNValidator.GetUserFolder(virtualPath);
                if (!(CheckAllChildrenVisible(ref folder)))
                {
                    return(DNNValidator.LogDetailError(ErrorCodes.CannotCopyFolder_ChildrenVisible));
                }

                returnValue = TelerikContent.CopyDirectory(virtualPath, virtualNewPath);

                if (string.IsNullOrEmpty(returnValue))
                {
                    //Sync to add new folder & files
                    FileSystemUtils.SynchronizeFolder(PortalSettings.PortalId, HttpContext.Current.Request.MapPath(virtualNewPath), FileSystemValidation.ToDBPath(virtualNewPath), true, true, true);
                }

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(DNNValidator.LogUnknownError(ex, path, newPath));
            }
        }