Use NonDisposableStream instead of using MemoryStream.ToArray()

This commit is contained in:
Pranav K 2015-08-12 15:45:33 -07:00
parent 39ab9badde
commit 9a5ebf1497
1 changed files with 10 additions and 8 deletions

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.AspNet.Mvc.Razor.Compilation;
using Microsoft.AspNet.Mvc.Razor.Directives;
using Microsoft.AspNet.Mvc.Razor.Internal;
@ -92,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
var file = filesToProcess[index];
PrecompilationCacheEntry cacheEntry;
if(!PreCompilationCache.TryGetValue(file.RelativePath, out cacheEntry))
if (!PreCompilationCache.TryGetValue(file.RelativePath, out cacheEntry))
{
cacheEntry = GetCacheEntry(file);
PreCompilationCache.Set(
@ -163,10 +164,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
}
else
{
assemblyStream.Position = 0;
var assemblyBytes = assemblyStream.ToArray();
var assemblyResource = new ResourceDescription(assemblyResourceName,
() => new MemoryStream(assemblyBytes),
() => GetNonDisposableStream(assemblyStream),
isPublic: true);
CompileContext.Resources.Add(assemblyResource);
@ -174,11 +173,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
if (pdbStream != null)
{
symbolsResourceName = resourcePrefix + ".pdb";
pdbStream.Position = 0;
var pdbBytes = pdbStream.ToArray();
var pdbResource = new ResourceDescription(symbolsResourceName,
() => new MemoryStream(pdbBytes),
() => GetNonDisposableStream(pdbStream),
isPublic: true);
CompileContext.Resources.Add(pdbResource);
@ -279,6 +275,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
}
}
private static Stream GetNonDisposableStream(Stream stream)
{
stream.Position = 0;
return new NonDisposableStream(stream);
}
private class PrecompileRazorFileInfoCollection : RazorFileInfoCollection
{
public PrecompileRazorFileInfoCollection(string assemblyResourceName,