コード例 #1
0
        public bool Rename(RenameOprationInfo renameInfo)
        {
            var rootPath = HostingEnvironment.ApplicationHost.GetPhysicalPath();
            var tempPath = _fileSystemManager.RelativeToAbsolutePath(Config.ThumbnailPath);

            if (tempPath == null)
            {
                throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.PathNotFound, Config.ThumbnailPath));
            }

            var thumbnailRootPath = tempPath.ToLower();

            var oldPath = _fileSystemManager.RelativeToAbsolutePath(AuthorizeManager.AuthorizeActionOnPath(renameInfo.OldPath, ActionKey.ReadFromDisk));
            var newPath = _fileSystemManager.RelativeToAbsolutePath(AuthorizeManager.AuthorizeActionOnPath(renameInfo.NewPath, ActionKey.WriteToDisk));

            if (oldPath == null)
            {
                throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.PathNotFound, renameInfo.OldPath));
            }

            if (newPath == null)
            {
                throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.PathNotFound, renameInfo.NewPath));
            }


            var thumbnailOldPath = oldPath.Substring(rootPath.Length);
            var thumbnailNewPath = newPath.Substring(rootPath.Length);



            if (!renameInfo.IsDirectory)
            {
                _fileSystemManager.RenameFile(oldPath, newPath);
                if (_fileSystemManager.FileExist(thumbnailRootPath + thumbnailOldPath))
                {
                    _fileSystemManager.RenameFile(thumbnailRootPath + thumbnailOldPath, thumbnailRootPath + thumbnailNewPath);
                }
            }
            else
            {
                _fileSystemManager.RenameDirectory(oldPath, newPath);
                if (_fileSystemManager.DirectoryExists(thumbnailRootPath + thumbnailOldPath))
                {
                    _fileSystemManager.RenameDirectory(thumbnailRootPath + thumbnailOldPath, thumbnailRootPath + thumbnailNewPath);
                }
            }
            return(true);
        }
コード例 #2
0
 public bool Rename(RenameOprationInfo renameInfo)
 {
     return(_fileSystemBiz.Rename(renameInfo));
 }