Imported Upstream version 4.8.0.309

Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-11-10 13:04:39 +00:00
parent ee1447783b
commit 94b2861243
4912 changed files with 390737 additions and 49310 deletions

View File

@ -5,19 +5,21 @@
namespace System.ServiceModel
{
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime;
using System.Security.Claims;
using System.Security.Principal;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Security;
using System.Threading;
public sealed class OperationContext : IExtensibleObject<OperationContext>
{
[ThreadStatic]
static Holder currentContext;
static AsyncLocal<OperationContext> currentAsyncLocalContext = new AsyncLocal<OperationContext>();
ServiceChannel channel;
Message clientReply;
bool closeClientReply;
@ -33,6 +35,7 @@ namespace System.ServiceModel
MessageHeaders outgoingMessageHeaders;
MessageVersion outgoingMessageVersion;
EndpointDispatcher endpointDispatcher;
bool isAsyncFlowEnabled;
public event EventHandler OperationCompleted;
@ -92,12 +95,19 @@ namespace System.ServiceModel
{
get
{
return CurrentHolder.Context;
return ShouldUseAsyncLocalContext ? OperationContext.currentAsyncLocalContext.Value : CurrentHolder.Context;
}
set
{
CurrentHolder.Context = value;
if (ShouldUseAsyncLocalContext)
{
OperationContext.currentAsyncLocalContext.Value = value;
}
else
{
CurrentHolder.Context = value;
}
}
}
@ -115,6 +125,14 @@ namespace System.ServiceModel
}
}
private static bool ShouldUseAsyncLocalContext
{
get
{
return CurrentHolder.Context == null && OperationContext.currentAsyncLocalContext.Value != null && OperationContext.currentAsyncLocalContext.Value.isAsyncFlowEnabled;
}
}
public EndpointDispatcher EndpointDispatcher
{
get
@ -339,6 +357,21 @@ namespace System.ServiceModel
this.clientReply = null;
}
internal static void EnableAsyncFlow()
{
CurrentHolder.Context.isAsyncFlowEnabled = true;
currentAsyncLocalContext.Value = CurrentHolder.Context;
}
internal static void DisableAsyncFlow()
{
if (OperationContext.Current != null && OperationContext.Current.isAsyncFlowEnabled)
{
OperationContext.Current.isAsyncFlowEnabled = false;
currentAsyncLocalContext.Value = null;
}
}
internal void FireOperationCompleted()
{
try