mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Handle tenants config on Azure
--HG-- branch : dev
This commit is contained in:
@@ -4,6 +4,7 @@ using NUnit.Framework;
|
|||||||
using Orchard.Azure.Storage;
|
using Orchard.Azure.Storage;
|
||||||
using Microsoft.WindowsAzure;
|
using Microsoft.WindowsAzure;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
|
|
||||||
namespace Orchard.Azure.Tests.Storage {
|
namespace Orchard.Azure.Tests.Storage {
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
@@ -15,7 +16,7 @@ namespace Orchard.Azure.Tests.Storage {
|
|||||||
CloudStorageAccount devAccount;
|
CloudStorageAccount devAccount;
|
||||||
CloudStorageAccount.TryParse("UseDevelopmentStorage=true", out devAccount);
|
CloudStorageAccount.TryParse("UseDevelopmentStorage=true", out devAccount);
|
||||||
|
|
||||||
_azureBlobStorageProvider = new AzureBlobStorageProvider("default", devAccount);
|
_azureBlobStorageProvider = new AzureBlobStorageProvider(new ShellSettings { Name = "default" }, devAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
|
@@ -11,19 +11,19 @@ namespace Orchard.Azure {
|
|||||||
public string ContainerName { get; protected set; }
|
public string ContainerName { get; protected set; }
|
||||||
|
|
||||||
private readonly CloudStorageAccount _storageAccount;
|
private readonly CloudStorageAccount _storageAccount;
|
||||||
private readonly string _shellName;
|
private readonly string _root;
|
||||||
public CloudBlobClient BlobClient { get; private set; }
|
public CloudBlobClient BlobClient { get; private set; }
|
||||||
public CloudBlobContainer Container { get; private set; }
|
public CloudBlobContainer Container { get; private set; }
|
||||||
|
|
||||||
public AzureFileSystem(string containerName, string shellName, bool isPrivate)
|
public AzureFileSystem(string containerName, string root, bool isPrivate)
|
||||||
: this(containerName, shellName, isPrivate, CloudStorageAccount.FromConfigurationSetting("DataConnectionString")) {
|
: this(containerName, root, isPrivate, CloudStorageAccount.FromConfigurationSetting("DataConnectionString")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AzureFileSystem(string containerName, string shellName, bool isPrivate, CloudStorageAccount storageAccount) {
|
public AzureFileSystem(string containerName, string root, bool isPrivate, CloudStorageAccount storageAccount) {
|
||||||
// Setup the connection to custom storage accountm, e.g. Development Storage
|
// Setup the connection to custom storage accountm, e.g. Development Storage
|
||||||
_storageAccount = storageAccount;
|
_storageAccount = storageAccount;
|
||||||
ContainerName = containerName;
|
ContainerName = containerName;
|
||||||
_shellName = shellName;
|
_root = String.IsNullOrEmpty(root) || root == "/" ? String.Empty : root + "/";
|
||||||
|
|
||||||
BlobClient = _storageAccount.CreateCloudBlobClient();
|
BlobClient = _storageAccount.CreateCloudBlobClient();
|
||||||
// Get and create the container if it does not exist
|
// Get and create the container if it does not exist
|
||||||
@@ -47,20 +47,20 @@ namespace Orchard.Azure {
|
|||||||
|
|
||||||
public IStorageFile GetFile(string path) {
|
public IStorageFile GetFile(string path) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
path = String.Concat(_shellName, "/", path);
|
path = String.Concat(_root, path);
|
||||||
Container.EnsureBlobExists(path);
|
Container.EnsureBlobExists(path);
|
||||||
return new AzureBlobFileStorage(Container.GetBlockBlobReference(path));
|
return new AzureBlobFileStorage(Container.GetBlockBlobReference(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FileExists(string path) {
|
public bool FileExists(string path) {
|
||||||
path = String.Concat(_shellName, "/", path);
|
path = String.Concat(_root, path);
|
||||||
return Container.BlobExists(path);
|
return Container.BlobExists(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IStorageFile> ListFiles(string path) {
|
public IEnumerable<IStorageFile> ListFiles(string path) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
|
|
||||||
string prefix = String.Concat(Container.Name, "/", _shellName, "/", path);
|
string prefix = String.Concat(Container.Name, "/", _root, path);
|
||||||
if ( !prefix.EndsWith("/") )
|
if ( !prefix.EndsWith("/") )
|
||||||
prefix += "/";
|
prefix += "/";
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ namespace Orchard.Azure {
|
|||||||
|
|
||||||
public IEnumerable<IStorageFolder> ListFolders(string path) {
|
public IEnumerable<IStorageFolder> ListFolders(string path) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
path = String.Concat(_shellName, "/", path);
|
path = String.Concat(_root, path);
|
||||||
|
|
||||||
if ( !Container.DirectoryExists(path) ) {
|
if ( !Container.DirectoryExists(path) ) {
|
||||||
try {
|
try {
|
||||||
@@ -91,7 +91,7 @@ namespace Orchard.Azure {
|
|||||||
|
|
||||||
public void CreateFolder(string path) {
|
public void CreateFolder(string path) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
path = String.Concat(_shellName, "/", path);
|
path = String.Concat(_root, path);
|
||||||
|
|
||||||
Container.EnsureDirectoryDoesNotExist(path);
|
Container.EnsureDirectoryDoesNotExist(path);
|
||||||
Container.GetDirectoryReference(path);
|
Container.GetDirectoryReference(path);
|
||||||
@@ -99,7 +99,7 @@ namespace Orchard.Azure {
|
|||||||
|
|
||||||
public void DeleteFolder(string path) {
|
public void DeleteFolder(string path) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
path = String.Concat(_shellName, "/", path);
|
path = String.Concat(_root, path);
|
||||||
|
|
||||||
Container.EnsureDirectoryExists(path);
|
Container.EnsureDirectoryExists(path);
|
||||||
foreach ( var blob in Container.GetDirectoryReference(path).ListBlobs() ) {
|
foreach ( var blob in Container.GetDirectoryReference(path).ListBlobs() ) {
|
||||||
@@ -107,7 +107,7 @@ namespace Orchard.Azure {
|
|||||||
( (CloudBlob)blob ).Delete();
|
( (CloudBlob)blob ).Delete();
|
||||||
|
|
||||||
if ( blob is CloudBlobDirectory )
|
if ( blob is CloudBlobDirectory )
|
||||||
DeleteFolder(blob.Uri.ToString().Substring(Container.Uri.ToString().Length + 2 + _shellName.Length));
|
DeleteFolder(blob.Uri.ToString().Substring(Container.Uri.ToString().Length + 1 + _root.Length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ namespace Orchard.Azure {
|
|||||||
if ( !newPath.EndsWith("/") )
|
if ( !newPath.EndsWith("/") )
|
||||||
newPath += "/";
|
newPath += "/";
|
||||||
|
|
||||||
foreach ( var blob in Container.GetDirectoryReference(_shellName + "/" + path).ListBlobs() ) {
|
foreach ( var blob in Container.GetDirectoryReference(_root + path).ListBlobs() ) {
|
||||||
if ( blob is CloudBlob ) {
|
if ( blob is CloudBlob ) {
|
||||||
string filename = Path.GetFileName(blob.Uri.ToString());
|
string filename = Path.GetFileName(blob.Uri.ToString());
|
||||||
string source = String.Concat(path, filename);
|
string source = String.Concat(path, filename);
|
||||||
@@ -142,7 +142,7 @@ namespace Orchard.Azure {
|
|||||||
|
|
||||||
public void DeleteFile(string path) {
|
public void DeleteFile(string path) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
path = String.Concat(_shellName, "/", path);
|
path = String.Concat(_root, path);
|
||||||
|
|
||||||
Container.EnsureBlobExists(path);
|
Container.EnsureBlobExists(path);
|
||||||
var blob = Container.GetBlockBlobReference(path);
|
var blob = Container.GetBlockBlobReference(path);
|
||||||
@@ -151,10 +151,10 @@ namespace Orchard.Azure {
|
|||||||
|
|
||||||
public void RenameFile(string path, string newPath) {
|
public void RenameFile(string path, string newPath) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
path = String.Concat(_shellName, "/", path);
|
path = String.Concat(_root, path);
|
||||||
|
|
||||||
EnsurePathIsRelative(newPath);
|
EnsurePathIsRelative(newPath);
|
||||||
newPath = String.Concat(_shellName, "/", newPath);
|
newPath = String.Concat(_root, newPath);
|
||||||
|
|
||||||
Container.EnsureBlobExists(path);
|
Container.EnsureBlobExists(path);
|
||||||
Container.EnsureBlobDoesNotExist(newPath);
|
Container.EnsureBlobDoesNotExist(newPath);
|
||||||
@@ -167,7 +167,7 @@ namespace Orchard.Azure {
|
|||||||
|
|
||||||
public IStorageFile CreateFile(string path) {
|
public IStorageFile CreateFile(string path) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
path = String.Concat(_shellName, "/", path);
|
path = String.Concat(_root, path);
|
||||||
|
|
||||||
if ( Container.BlobExists(path) ) {
|
if ( Container.BlobExists(path) ) {
|
||||||
throw new ArgumentException("File " + path + " already exists");
|
throw new ArgumentException("File " + path + " already exists");
|
||||||
@@ -180,7 +180,7 @@ namespace Orchard.Azure {
|
|||||||
|
|
||||||
public string GetPublicUrl(string path) {
|
public string GetPublicUrl(string path) {
|
||||||
EnsurePathIsRelative(path);
|
EnsurePathIsRelative(path);
|
||||||
path = String.Concat(_shellName, "/", path);
|
path = String.Concat(_root, path);
|
||||||
Container.EnsureBlobExists(path);
|
Container.EnsureBlobExists(path);
|
||||||
return Container.GetBlockBlobReference(path).Uri.ToString();
|
return Container.GetBlockBlobReference(path).Uri.ToString();
|
||||||
}
|
}
|
||||||
|
@@ -9,8 +9,8 @@ namespace Orchard.Azure.Environment.Configuration {
|
|||||||
|
|
||||||
private readonly AzureFileSystem _fs;
|
private readonly AzureFileSystem _fs;
|
||||||
|
|
||||||
public AzureAppDataFolder(string shellName) {
|
public AzureAppDataFolder() {
|
||||||
_fs = new AzureFileSystem("appdata", shellName, true);
|
_fs = new AzureFileSystem("appdata", null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateFile(string path, string content) {
|
public void CreateFile(string path, string content) {
|
||||||
|
@@ -16,17 +16,11 @@
|
|||||||
<component instance-scope="single-instance"
|
<component instance-scope="single-instance"
|
||||||
type="Orchard.Azure.Storage.AzureBlobStorageProvider, Orchard.Azure"
|
type="Orchard.Azure.Storage.AzureBlobStorageProvider, Orchard.Azure"
|
||||||
service="Orchard.Storage.IStorageProvider">
|
service="Orchard.Storage.IStorageProvider">
|
||||||
<parameters>
|
|
||||||
<parameter name="shellName" value="Default" />
|
|
||||||
</parameters>
|
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
<component instance-scope="single-instance"
|
<component instance-scope="single-instance"
|
||||||
type="Orchard.Azure.Environment.Configuration.AzureAppDataFolder, Orchard.Azure"
|
type="Orchard.Azure.Environment.Configuration.AzureAppDataFolder, Orchard.Azure"
|
||||||
service="Orchard.Environment.Configuration.IAppDataFolder">
|
service="Orchard.Environment.Configuration.IAppDataFolder">
|
||||||
<parameters>
|
|
||||||
<parameter name="shellName" value="Default" />
|
|
||||||
</parameters>
|
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,15 +1,16 @@
|
|||||||
using Microsoft.WindowsAzure;
|
using Microsoft.WindowsAzure;
|
||||||
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Storage;
|
using Orchard.Storage;
|
||||||
|
|
||||||
namespace Orchard.Azure.Storage {
|
namespace Orchard.Azure.Storage {
|
||||||
|
|
||||||
public class AzureBlobStorageProvider : AzureFileSystem, IStorageProvider {
|
public class AzureBlobStorageProvider : AzureFileSystem, IStorageProvider {
|
||||||
|
|
||||||
public AzureBlobStorageProvider(string shellName)
|
public AzureBlobStorageProvider(ShellSettings shellSettings)
|
||||||
: this(shellName, CloudStorageAccount.FromConfigurationSetting("DataConnectionString")) {
|
: this(shellSettings, CloudStorageAccount.FromConfigurationSetting("DataConnectionString")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AzureBlobStorageProvider(string shellName, CloudStorageAccount storageAccount) : base("media", shellName, false, storageAccount) { }
|
public AzureBlobStorageProvider(ShellSettings shellSettings, CloudStorageAccount storageAccount) : base("media", shellSettings.Name, false, storageAccount) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user