Exemple #1
0
        public void Rename(IFile file, string newName)
        {
            var callLog = Log.Call();

            try
            {
                var path = Path.Combine(_oqtServerPaths.FullContentPath(AdamContext.Site.ContentPath), file.Path);

                var currentFilePath = Path.Combine(path, file.FullName);
                if (TryToRenameFile(newName, currentFilePath, path))
                {
                    return;
                }

                var dnnFile = FileRepository.GetFile(file.AsOqt().SysId);
                dnnFile.Name = newName;
                FileRepository.UpdateFile(dnnFile);
                Log.Add($"VirtualFile {dnnFile.FileId} renamed to {dnnFile.Name}");

                callLog("ok");
            }
            catch (Exception e)
            {
                callLog($"Error:{e.Message}; {e.InnerException}");
            }
        }
Exemple #2
0
 private string PathOnDrive(string path)
 {
     if (path.Contains(".."))
     {
         throw new ArgumentException("path may not contain ..", nameof(path));
     }
     // check if it already has the root path attached, otherwise add
     path = path.StartsWith(AdamContext.Site.ContentPath) ? path : Path.Combine(AdamContext.Site.ContentPath, path);
     path = path.Replace("//", "/").Replace("\\\\", "\\");
     return(_serverPaths.FullContentPath(path));
 }
Exemple #3
0
        public string PhysicalPath(string path)
        {
            ThrowIfPathContainsDotDot(path);

            // check if it's already a physical path
            if (Path.IsPathRooted(path))
            {
                return(path);
            }

            // check if it already has the root path attached, otherwise add
            path = path.StartsWith(AdamManager.Site.ContentPath) ? path : Path.Combine(AdamManager.Site.ContentPath, path);
            return(_serverPaths.FullContentPath(path.Backslash()));
        }
Exemple #4
0
        public void Rename(IFile file, string newName)
        {
            var callLog = Log.Call();

            try
            {
                var path = Path.Combine(_oqtServerPaths.FullContentPath(AdamContext.Site.ContentPath), file.Path);

                var currentFilePath = Path.Combine(path, file.FullName);
                if (!System.IO.File.Exists(currentFilePath))
                {
                    callLog($"Can't rename because source file do not exists {currentFilePath}");
                    return;
                }

                var newFilePath = Path.Combine(path, newName);
                if (!System.IO.File.Exists(newFilePath))
                {
                    callLog($"Can't rename because file with new name already exists {newFilePath}");
                    return;
                }

                System.IO.File.Move(currentFilePath, newFilePath);
                Log.Add($"File renamed {currentFilePath} to {newFilePath}");

                var dnnFile = FileRepository.GetFile(file.AsOqt().SysId);
                dnnFile.Name = newName;
                FileRepository.UpdateFile(dnnFile);
                Log.Add($"VirtualFile {dnnFile.FileId} renamed to {dnnFile.Name}");

                callLog("ok");
            }
            catch (Exception e)
            {
                callLog($"Error:{e.Message}; {e.InnerException}");
            }
        }