fixes a locking issue and exception logging

This commit is contained in:
Shannon
2014-03-10 12:55:45 +11:00
parent 6a9a1d1547
commit c26b72bd10
2 changed files with 17 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ using System.Net.Http;
using System.Net.Http.Formatting; using System.Net.Http.Formatting;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Umbraco.Core.Logging;
namespace Umbraco.Web.WebApi namespace Umbraco.Web.WebApi
{ {
@@ -32,8 +33,16 @@ namespace Umbraco.Web.WebApi
using (var memStream = new MemoryStream()) using (var memStream = new MemoryStream())
{ {
//Let the base class do all the processing using our custom stream try
await base.WriteToStreamAsync(type, value, memStream, content, transportContext); {
//Let the base class do all the processing using our custom stream
await base.WriteToStreamAsync(type, value, memStream, content, transportContext);
}
catch (Exception ex)
{
LogHelper.Error<AngularJsonMediaTypeFormatter>("An error occurred writing to the output stream", ex);
throw;
}
memStream.Flush(); memStream.Flush();
memStream.Position = 0; memStream.Position = 0;

View File

@@ -28,11 +28,13 @@ namespace umbraco.cms.businesslogic.macro
internal static void EnsureInitialize() internal static void EnsureInitialize()
{ {
if (_isInitialized) using (var lck = new UpgradeableReadLock(Lock))
return;
using (new WriteLock(Lock))
{ {
if (_isInitialized)
return;
lck.UpgradeToWriteLock();
AllEngines.Clear(); AllEngines.Clear();
AllEngines.AddRange( AllEngines.AddRange(