mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Removing HttpContextWeaver from Azure solution
No more needed as internal bug has been fixed
This commit is contained in:
@@ -33,8 +33,6 @@ namespace Orchard.Azure {
|
||||
_root = String.IsNullOrEmpty(root) ? "" : root + "/";
|
||||
_absoluteRoot = Combine(Combine(_storageAccount.BlobEndpoint.AbsoluteUri, containerName), root);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
|
||||
BlobClient = _storageAccount.CreateCloudBlobClient();
|
||||
// Get and create the container if it does not exist
|
||||
// The container is named with DNS naming restrictions (i.e. all lower case)
|
||||
@@ -45,7 +43,6 @@ namespace Orchard.Azure {
|
||||
Container.SetPermissions(isPrivate
|
||||
? new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Off }
|
||||
: new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -92,23 +89,17 @@ namespace Orchard.Azure {
|
||||
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureBlobExists(String.Concat(_root, path));
|
||||
return new AzureBlobFileStorage(Container.GetBlockBlobReference(String.Concat(_root, path)), _absoluteRoot);
|
||||
}
|
||||
}
|
||||
|
||||
public bool FileExists(string path) {
|
||||
using (new HttpContextWeaver()) {
|
||||
return Container.BlobExists(String.Concat(_root, path));
|
||||
}
|
||||
}
|
||||
|
||||
public bool FolderExists(string path) {
|
||||
using (new HttpContextWeaver()) {
|
||||
return Container.DirectoryExists(String.Concat(_root, path));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IStorageFile> ListFiles(string path) {
|
||||
|
||||
@@ -120,7 +111,6 @@ namespace Orchard.Azure {
|
||||
if (!prefix.EndsWith("/"))
|
||||
prefix += "/";
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
return BlobClient
|
||||
.ListBlobsWithPrefix(prefix)
|
||||
.OfType<CloudBlockBlob>()
|
||||
@@ -128,15 +118,12 @@ namespace Orchard.Azure {
|
||||
.Select(blobItem => new AzureBlobFileStorage(blobItem, _absoluteRoot))
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IStorageFolder> ListFolders(string path) {
|
||||
|
||||
path = path ?? String.Empty;
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
|
||||
// return root folders
|
||||
if (String.Concat(_root, path) == String.Empty) {
|
||||
return Container.ListBlobs()
|
||||
@@ -161,7 +148,6 @@ namespace Orchard.Azure {
|
||||
.Select<CloudBlobDirectory, IStorageFolder>(d => new AzureBlobFolderStorage(d, _absoluteRoot))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryCreateFolder(string path) {
|
||||
try {
|
||||
@@ -180,7 +166,6 @@ namespace Orchard.Azure {
|
||||
|
||||
public void CreateFolder(string path) {
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureDirectoryDoesNotExist(String.Concat(_root, path));
|
||||
|
||||
// Creating a virtually hidden file to make the directory an existing concept
|
||||
@@ -194,12 +179,10 @@ namespace Orchard.Azure {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFolder(string path) {
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureDirectoryExists(String.Concat(_root, path));
|
||||
foreach (var blob in Container.GetDirectoryReference(String.Concat(_root, path)).ListBlobs()) {
|
||||
if (blob is CloudBlob)
|
||||
@@ -209,7 +192,6 @@ namespace Orchard.Azure {
|
||||
DeleteFolder(blob.Uri.ToString().Substring(Container.Uri.ToString().Length + 1 + _root.Length));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RenameFolder(string path, string newPath) {
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
@@ -220,7 +202,6 @@ namespace Orchard.Azure {
|
||||
|
||||
if (!newPath.EndsWith("/"))
|
||||
newPath += "/";
|
||||
using (new HttpContextWeaver()) {
|
||||
foreach (var blob in Container.GetDirectoryReference(_root + path).ListBlobs()) {
|
||||
if (blob is CloudBlob) {
|
||||
string filename = Path.GetFileName(blob.Uri.ToString());
|
||||
@@ -237,23 +218,19 @@ namespace Orchard.Azure {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFile(string path) {
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureBlobExists(Combine(_root, path));
|
||||
var blob = Container.GetBlockBlobReference(Combine(_root, path));
|
||||
blob.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
public void RenameFile(string path, string newPath) {
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
newPath = ConvertToRelativeUriPath(newPath);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureBlobExists(String.Concat(_root, path));
|
||||
Container.EnsureBlobDoesNotExist(String.Concat(_root, newPath));
|
||||
|
||||
@@ -262,7 +239,6 @@ namespace Orchard.Azure {
|
||||
newBlob.CopyFromBlob(blob);
|
||||
blob.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
public IStorageFile CreateFile(string path) {
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
@@ -293,11 +269,9 @@ namespace Orchard.Azure {
|
||||
public string GetPublicUrl(string path) {
|
||||
path = ConvertToRelativeUriPath(path);
|
||||
|
||||
using (new HttpContextWeaver()) {
|
||||
Container.EnsureBlobExists(String.Concat(_root, path));
|
||||
return Container.GetBlockBlobReference(String.Concat(_root, path)).Uri.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the mime-type of the specified file path, looking into IIS configuration and the Registry
|
||||
@@ -411,27 +385,21 @@ namespace Orchard.Azure {
|
||||
}
|
||||
|
||||
public string GetPath() {
|
||||
using (new HttpContextWeaver()) {
|
||||
return _blob.Uri.ToString().Substring(_rootPath.Length).Trim('/');
|
||||
}
|
||||
}
|
||||
|
||||
public long GetSize() {
|
||||
using (new HttpContextWeaver()) {
|
||||
return GetDirectorySize(_blob);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime GetLastUpdated() {
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
|
||||
public IStorageFolder GetParent() {
|
||||
using (new HttpContextWeaver()) {
|
||||
if (_blob.Parent != null) {
|
||||
return new AzureBlobFolderStorage(_blob.Parent, _rootPath);
|
||||
}
|
||||
}
|
||||
throw new ArgumentException("Directory " + _blob.Uri + " does not have a parent directory");
|
||||
}
|
||||
|
||||
|
@@ -11,11 +11,8 @@ namespace Orchard.Azure {
|
||||
throw new ArgumentException("Path can't be empty");
|
||||
|
||||
try {
|
||||
using ( new HttpContextWeaver() )
|
||||
{
|
||||
var blob = container.GetBlockBlobReference(path);
|
||||
blob.FetchAttributes();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch ( StorageClientException e ) {
|
||||
|
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.IO;
|
||||
|
||||
namespace Orchard.Azure {
|
||||
/// <summary>
|
||||
/// THIS IS A HACK
|
||||
/// There is a bug in ASP.NET 4.0 in HttpEncoder.Current, which prevents some calls to HttpUtiliy.Decode/Encode
|
||||
/// from Application_Start, on IIS or Azure. This hack will be removed when the bug is corrected.
|
||||
/// This is fired by the assembly Microsoft.WindowsAzure.StorageClient. Should be corrected in .NET4 SP1
|
||||
/// </summary>
|
||||
public class HttpContextWeaver : IDisposable {
|
||||
private readonly HttpContext _current;
|
||||
|
||||
public HttpContextWeaver()
|
||||
{
|
||||
_current = HttpContext.Current;
|
||||
HttpContext.Current = new HttpContext(new HttpRequest(String.Empty, "http://localhost", String.Empty), new HttpResponse(new StringWriter()));
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
HttpContext.Current = _current;
|
||||
}
|
||||
}
|
||||
}
|
@@ -84,7 +84,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CloudBlobContainerExtensions.cs" />
|
||||
<Compile Include="HttpContextWeaver.cs" />
|
||||
<Compile Include="Environment\Configuration\AzureShellSettingsManager.cs" />
|
||||
<Compile Include="FileSystems\Media\AzureBlobStorageProvider.cs" />
|
||||
<Compile Include="Logging\AzureAppender.cs" />
|
||||
|
Reference in New Issue
Block a user