mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -44,6 +44,18 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
|
||||
_azureBlobStorageProvider.DeleteFile("notexisting");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RootFolderAreNotCropped() {
|
||||
_azureBlobStorageProvider.CreateFolder("default");
|
||||
_azureBlobStorageProvider.CreateFolder("foo");
|
||||
|
||||
var folders = _azureBlobStorageProvider.ListFolders("");
|
||||
|
||||
Assert.That(folders.Count(), Is.EqualTo(2));
|
||||
Assert.That(folders.Any(f => f.GetName() == "default"), Is.True);
|
||||
Assert.That(folders.Any(f => f.GetName() == "foo"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateFileShouldReturnCorrectStorageFile() {
|
||||
var storageFile = _azureBlobStorageProvider.CreateFile("foo.txt");
|
||||
@@ -105,6 +117,17 @@ namespace Orchard.Azure.Tests.FileSystems.Media {
|
||||
Assert.AreEqual("folder", _azureBlobStorageProvider.ListFolders(null).First().GetPath());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateFolderWithSubFolder() {
|
||||
_azureBlobStorageProvider.CreateFolder("folder");
|
||||
Assert.AreEqual(0, _azureBlobStorageProvider.ListFolders("folder").Count());
|
||||
|
||||
_azureBlobStorageProvider.CreateFolder("folder/folder");
|
||||
Assert.AreEqual(1, _azureBlobStorageProvider.ListFolders("folder").Count());
|
||||
Assert.AreEqual(0, _azureBlobStorageProvider.ListFiles("folder/folder").Count());
|
||||
Assert.AreEqual("folder", _azureBlobStorageProvider.ListFolders("folder").First().GetName());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteFolderShouldDeleteFilesAlso() {
|
||||
_azureBlobStorageProvider.CreateFile("folder/foo1.txt");
|
||||
|
@@ -51,10 +51,42 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
private static void EnsurePathIsRelative(string path) {
|
||||
if (path.StartsWith("/") || path.StartsWith("http://"))
|
||||
if ( path.StartsWith("/") || path.StartsWith("http://") || path.StartsWith("https://") )
|
||||
throw new ArgumentException("Path must be relative");
|
||||
}
|
||||
|
||||
public string Combine(string path1, string path2) {
|
||||
if ( path1 == null) {
|
||||
throw new ArgumentNullException("path1");
|
||||
}
|
||||
|
||||
if ( path2 == null ) {
|
||||
throw new ArgumentNullException("path2");
|
||||
}
|
||||
|
||||
if ( String.IsNullOrEmpty(path2) ) {
|
||||
return path1;
|
||||
}
|
||||
|
||||
if ( String.IsNullOrEmpty(path1) ) {
|
||||
return path2;
|
||||
}
|
||||
|
||||
if ( path2.StartsWith("http://") || path2.StartsWith("https://") )
|
||||
{
|
||||
return path2;
|
||||
}
|
||||
|
||||
var ch = path1[path1.Length - 1];
|
||||
|
||||
if (ch != '/')
|
||||
{
|
||||
return (path1.TrimEnd('/') + '/' + path2.TrimStart('/'));
|
||||
}
|
||||
|
||||
return (path1 + path2);
|
||||
}
|
||||
|
||||
public IStorageFile GetFile(string path) {
|
||||
EnsurePathIsRelative(path);
|
||||
|
||||
@@ -75,7 +107,7 @@ namespace Orchard.Azure {
|
||||
|
||||
EnsurePathIsRelative(path);
|
||||
|
||||
string prefix = String.Concat(Container.Name, "/", _root, path);
|
||||
string prefix = String.Concat(Combine(Container.Name, _root), path);
|
||||
|
||||
if ( !prefix.EndsWith("/") )
|
||||
prefix += "/";
|
||||
@@ -121,7 +153,7 @@ namespace Orchard.Azure {
|
||||
Container.EnsureDirectoryDoesNotExist(String.Concat(_root, path));
|
||||
|
||||
// Creating a virtually hidden file to make the directory an existing concept
|
||||
CreateFile(path + "/" + FolderEntry);
|
||||
CreateFile(Combine(path, FolderEntry));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +256,7 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public string GetPath() {
|
||||
return _blob.Uri.ToString().Substring(_rootPath.Length+1);
|
||||
return _blob.Uri.ToString().Substring(_rootPath.Length).Trim('/');
|
||||
}
|
||||
|
||||
public string GetName() {
|
||||
@@ -263,11 +295,12 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public string GetName() {
|
||||
return Path.GetDirectoryName(GetPath() + "/");
|
||||
var path = GetPath();
|
||||
return path.Substring(path.LastIndexOf('/') +1 );
|
||||
}
|
||||
|
||||
public string GetPath() {
|
||||
return _blob.Uri.ToString().Substring(_rootPath.Length + 1).TrimEnd('/');
|
||||
return _blob.Uri.ToString().Substring(_rootPath.Length).Trim('/');
|
||||
}
|
||||
|
||||
public long GetSize() {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Orchard.Media.Models;
|
||||
|
||||
namespace Orchard.Media.Helpers {
|
||||
@@ -9,12 +10,12 @@ namespace Orchard.Media.Helpers {
|
||||
if (String.IsNullOrEmpty(mediaPath)) {
|
||||
return navigations;
|
||||
}
|
||||
if (!mediaPath.Contains("\\")) {
|
||||
if ( !mediaPath.Contains(Path.DirectorySeparatorChar.ToString()) && !mediaPath.Contains(Path.AltDirectorySeparatorChar.ToString()) ) {
|
||||
navigations.Add(new FolderNavigation { FolderName = mediaPath, FolderPath = mediaPath });
|
||||
return navigations;
|
||||
}
|
||||
|
||||
string[] navigationParts = mediaPath.Split(new[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] navigationParts = mediaPath.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries);
|
||||
string currentPath = String.Empty;
|
||||
foreach (string navigationPart in navigationParts) {
|
||||
currentPath = (string.IsNullOrEmpty(currentPath) ? navigationPart : currentPath + "\\" + navigationPart);
|
||||
|
@@ -66,7 +66,7 @@ namespace Orchard.Media.Services {
|
||||
_storageProvider.CreateFolder(name);
|
||||
return;
|
||||
}
|
||||
_storageProvider.CreateFolder(mediaPath + "\\" + name);
|
||||
_storageProvider.CreateFolder(_storageProvider.Combine(mediaPath, name));
|
||||
}
|
||||
|
||||
public void DeleteFolder(string name) {
|
||||
@@ -79,12 +79,12 @@ namespace Orchard.Media.Services {
|
||||
}
|
||||
|
||||
public void DeleteFile(string name, string folderName) {
|
||||
_storageProvider.DeleteFile(folderName + "\\" + name);
|
||||
_storageProvider.DeleteFile(_storageProvider.Combine(folderName, name));
|
||||
}
|
||||
|
||||
public void RenameFile(string name, string newName, string folderName) {
|
||||
if (FileAllowed(newName, false)) {
|
||||
_storageProvider.RenameFile(folderName + "\\" + name, folderName + "\\" + newName);
|
||||
_storageProvider.RenameFile(_storageProvider.Combine(folderName, name), _storageProvider.Combine(folderName, newName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,14 +193,14 @@ namespace Orchard.Media.Services {
|
||||
}
|
||||
}
|
||||
|
||||
private static string RenameFolderPath(string path, string newName) {
|
||||
var lastIndex = path.LastIndexOf("\\");
|
||||
private string RenameFolderPath(string path, string newName) {
|
||||
var lastIndex = Math.Max(path.LastIndexOf(Path.DirectorySeparatorChar), path.LastIndexOf(Path.AltDirectorySeparatorChar));
|
||||
|
||||
if (lastIndex == -1) {
|
||||
return newName;
|
||||
}
|
||||
|
||||
return path.Substring(0, lastIndex) + "\\" + newName;
|
||||
return _storageProvider.Combine(path.Substring(0, lastIndex), newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
<p>@Html.ActionLink(T("Media Folders").ToString(), "Index") >
|
||||
@foreach (FolderNavigation navigation in MediaHelpers.GetFolderNavigationHierarchy(Model.MediaPath)) {
|
||||
@Html.ActionLink(navigation.FolderName, "Edit",
|
||||
new {name = navigation.FolderName, mediaPath = navigation.FolderPath})
|
||||
new {name = navigation.FolderName, mediaPath = navigation.FolderPath}) <text>></text>
|
||||
|
||||
}
|
||||
@T("Folder Properties")</p>
|
||||
|
@@ -148,6 +148,10 @@ namespace Orchard.FileSystems.Media {
|
||||
File.Move(Map(path), Map(newPath));
|
||||
}
|
||||
|
||||
public string Combine(string path1, string path2) {
|
||||
return Path.Combine(path1, path2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private class FileSystemStorageFile : IStorageFile {
|
||||
|
@@ -12,5 +12,6 @@ namespace Orchard.FileSystems.Media {
|
||||
void DeleteFile(string path);
|
||||
void RenameFile(string path, string newPath);
|
||||
IStorageFile CreateFile(string path);
|
||||
string Combine(string path1, string path2);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user