From b0ab1f5decd7d3cfdb81336e0d2b801e728b62e6 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 2 Dec 2011 12:54:39 -0800 Subject: [PATCH] #18257: Fixing HttpContent encapsulation while enumerating files Work Item: 18257 --HG-- branch : 1.x --- .../Media/AzureBlobStorageProviderTests.cs | 14 ++++++++++++++ src/Orchard.Azure/AzureFileSystem.cs | 15 +++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs b/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs index 0ce78d3b1..41b1c8c59 100644 --- a/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs +++ b/src/Orchard.Azure.Tests/FileSystems/Media/AzureBlobStorageProviderTests.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Web; using NUnit.Framework; using Orchard.Azure.FileSystems.Media; using Microsoft.WindowsAzure; @@ -243,5 +244,18 @@ namespace Orchard.Azure.Tests.FileSystems.Media { Assert.That(content, Is.EqualTo("fo")); } + + [Test] + public void HttpContextWeaverShouldBeDisposed() + { + _azureBlobStorageProvider.CreateFile("foo1.txt"); + _azureBlobStorageProvider.CreateFile("foo2.txt"); + _azureBlobStorageProvider.CreateFile("foo3.txt"); + + foreach(var f in _azureBlobStorageProvider.ListFiles("")) + { + Assert.That(HttpContext.Current, Is.Null); + }; + } } } \ No newline at end of file diff --git a/src/Orchard.Azure/AzureFileSystem.cs b/src/Orchard.Azure/AzureFileSystem.cs index 1697ba9d3..06b57bdbc 100644 --- a/src/Orchard.Azure/AzureFileSystem.cs +++ b/src/Orchard.Azure/AzureFileSystem.cs @@ -108,14 +108,13 @@ namespace Orchard.Azure { if ( !prefix.EndsWith("/") ) prefix += "/"; - using ( new HttpContextWeaver() ) { - foreach (var blobItem in BlobClient.ListBlobsWithPrefix(prefix).OfType()) { - // ignore directory entries - if(blobItem.Uri.AbsoluteUri.EndsWith(FolderEntry)) - continue; - - yield return new AzureBlobFileStorage(blobItem, _absoluteRoot); - } + using (new HttpContextWeaver()) { + return BlobClient + .ListBlobsWithPrefix(prefix) + .OfType() + .Where(blobItem => !blobItem.Uri.AbsoluteUri.EndsWith(FolderEntry)) + .Select(blobItem => new AzureBlobFileStorage(blobItem, _absoluteRoot)) + .ToArray(); } }