You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@ -0,0 +1,146 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using System.ServiceModel.Activation;
|
||||
using System.ServiceModel.Diagnostics;
|
||||
using System.Runtime;
|
||||
using System.Runtime.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
abstract class BaseAppDomainProtocolHandler : AppDomainProtocolHandler
|
||||
{
|
||||
public readonly static TimeSpan DefaultStopTimeout = TimeSpan.FromSeconds(30);
|
||||
|
||||
string protocolId;
|
||||
IListenerChannelCallback listenerChannelCallback;
|
||||
protected ListenerChannelContext listenerChannelContext;
|
||||
object syncRoot = new object();
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
protected BaseAppDomainProtocolHandler(string protocolId)
|
||||
: base()
|
||||
{
|
||||
this.protocolId = protocolId;
|
||||
}
|
||||
|
||||
object ThisLock
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.syncRoot;
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnMessageReceived()
|
||||
{
|
||||
try
|
||||
{
|
||||
IListenerChannelCallback callback = this.listenerChannelCallback;
|
||||
if (callback != null)
|
||||
{
|
||||
callback.ReportMessageReceived();
|
||||
}
|
||||
}
|
||||
catch (COMException exception)
|
||||
{
|
||||
DiagnosticUtility.TraceHandledException(exception, TraceEventType.Warning);
|
||||
// The listener adapter might have gone away. Ignore the error.
|
||||
}
|
||||
}
|
||||
|
||||
// Start per-process listening for messages
|
||||
public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback)
|
||||
{
|
||||
Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel()");
|
||||
if (listenerChannelCallback == null)
|
||||
{
|
||||
DiagnosticUtility.DebugAssert("listenerChannelCallback is null");
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false);
|
||||
}
|
||||
|
||||
this.listenerChannelCallback = listenerChannelCallback;
|
||||
|
||||
int listenerChannelDataLength = listenerChannelCallback.GetBlobLength();
|
||||
byte[] listenerChannelData = new byte[listenerChannelDataLength];
|
||||
listenerChannelCallback.GetBlob(listenerChannelData, ref listenerChannelDataLength);
|
||||
Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() GetBlob() contains " + listenerChannelDataLength + " bytes");
|
||||
|
||||
listenerChannelContext = ListenerChannelContext.Hydrate(listenerChannelData);
|
||||
|
||||
Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() calling OnStart()");
|
||||
#if DEBUG
|
||||
// Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() waiting for you to attach the debugger to " + Process.GetCurrentProcess().ProcessName + " Pid: " + Process.GetCurrentProcess().Id);
|
||||
// for (int sleepCount = 0; sleepCount < 30 && !Debugger.IsAttached && !ListenerUnsafeNativeMethods.IsDebuggerPresent(); sleepCount++) { Thread.Sleep(500); } Debugger.Break();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
OnStart();
|
||||
|
||||
listenerChannelCallback.ReportStarted();
|
||||
Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() called ReportStarted()");
|
||||
}
|
||||
catch (CommunicationException exception)
|
||||
{
|
||||
Debug.Print("BaseAppDomainProtocolHandler.StartListenerChannel() failed in OnStart():\r\n" + exception);
|
||||
DiagnosticUtility.EventLog.LogEvent(TraceEventType.Error,
|
||||
(ushort)System.Runtime.Diagnostics.EventLogCategory.WebHost,
|
||||
(uint)System.Runtime.Diagnostics.EventLogEventId.WebHostFailedToListen,
|
||||
listenerChannelContext.AppKey,
|
||||
this.protocolId,
|
||||
TraceUtility.CreateSourceString(this),
|
||||
exception.ToString());
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnStart() { }
|
||||
protected virtual void OnStop() { }
|
||||
|
||||
public override void StopProtocol(bool immediate)
|
||||
{
|
||||
Debug.Print("BaseAppDomainProtocolHandler.StopProtocol() immediate: " + immediate + " calling ReportStopped()");
|
||||
|
||||
Stop();
|
||||
HostingEnvironment.UnregisterObject(this);
|
||||
}
|
||||
|
||||
public override void StopListenerChannel(int listenerChannelId, bool immediate)
|
||||
{
|
||||
Debug.Print("BaseAppDomainProtocolHandler.StopListenerChannel() listenerChannelId: " + listenerChannelId + " immediate: " + immediate + " calling ReportStopped()");
|
||||
if (listenerChannelId != listenerChannelContext.ListenerChannelId)
|
||||
{
|
||||
DiagnosticUtility.DebugAssert("Invalid ListenerChannel ID!");
|
||||
throw DiagnosticUtility.ExceptionUtility.ThrowHelperInternal(false);
|
||||
}
|
||||
|
||||
Stop();
|
||||
}
|
||||
|
||||
void Stop()
|
||||
{
|
||||
lock (ThisLock)
|
||||
{
|
||||
if (this.listenerChannelCallback != null)
|
||||
{
|
||||
OnStop();
|
||||
this.listenerChannelCallback.ReportStopped(0);
|
||||
this.listenerChannelCallback = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.ServiceModel;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Activation;
|
||||
using System.Runtime;
|
||||
|
||||
abstract class BaseProcessProtocolHandler : ProcessProtocolHandler
|
||||
{
|
||||
string protocolId;
|
||||
IAdphManager adphManager;
|
||||
|
||||
// Mapping from listenerChannelId->listenerChannelContext (i.e. IAdphManager, appId)
|
||||
Dictionary<int, ListenerChannelContext> listenerChannelIdMapping = new Dictionary<int, ListenerChannelContext>();
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUncalledPrivateCode,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
protected BaseProcessProtocolHandler(string protocolId)
|
||||
: base()
|
||||
{
|
||||
this.protocolId = protocolId;
|
||||
}
|
||||
|
||||
internal virtual void HandleStartListenerChannelError(IListenerChannelCallback listenerChannelCallback, Exception ex)
|
||||
{
|
||||
// This is the workaround to let WAS know that the LC is started and then gracefully stopped.
|
||||
listenerChannelCallback.ReportStarted();
|
||||
listenerChannelCallback.ReportStopped(0);
|
||||
}
|
||||
|
||||
// Start per-process listening for messages
|
||||
public override void StartListenerChannel(IListenerChannelCallback listenerChannelCallback, IAdphManager adphManager)
|
||||
{
|
||||
DiagnosticUtility.DebugAssert(listenerChannelCallback != null, "The listenerChannelCallback parameter must not be null");
|
||||
DiagnosticUtility.DebugAssert(adphManager != null, "The adphManager parameter must not be null");
|
||||
|
||||
int channelId = listenerChannelCallback.GetId();
|
||||
ListenerChannelContext listenerChannelContext;
|
||||
lock (this.listenerChannelIdMapping)
|
||||
{
|
||||
if (!listenerChannelIdMapping.TryGetValue(channelId, out listenerChannelContext))
|
||||
{
|
||||
int listenerChannelDataLength = listenerChannelCallback.GetBlobLength();
|
||||
byte[] listenerChannelData = new byte[listenerChannelDataLength];
|
||||
listenerChannelCallback.GetBlob(listenerChannelData, ref listenerChannelDataLength);
|
||||
Debug.Print("BaseProcessProtocolHandler.StartListenerChannel() GetBlob() contains " + listenerChannelDataLength + " bytes");
|
||||
listenerChannelContext = ListenerChannelContext.Hydrate(listenerChannelData);
|
||||
this.listenerChannelIdMapping.Add(channelId, listenerChannelContext);
|
||||
Debug.Print("BaseProcessProtocolHandler.StartListenerChannel() listenerChannelContext.ListenerChannelId: " + listenerChannelContext.ListenerChannelId);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.adphManager == null)
|
||||
{
|
||||
this.adphManager = adphManager;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// wether or not a previous AppDomain was running, we're going to start a new one now:
|
||||
Debug.Print("BaseProcessProtocolHandler.StartListenerChannel() calling StartAppDomainProtocolListenerChannel(appKey:" + listenerChannelContext.AppKey + " protocolId:" + protocolId + ")");
|
||||
adphManager.StartAppDomainProtocolListenerChannel(listenerChannelContext.AppKey, protocolId, listenerChannelCallback);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (Fx.IsFatal(ex))
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
DiagnosticUtility.TraceHandledException(ex, TraceEventType.Error);
|
||||
|
||||
HandleStartListenerChannelError(listenerChannelCallback, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public override void StopProtocol(bool immediate)
|
||||
{
|
||||
Debug.Print("BaseProcessProtocolHandler.StopProtocol(protocolId:" + protocolId + ", immediate:" + immediate + ")");
|
||||
}
|
||||
|
||||
public override void StopListenerChannel(int listenerChannelId, bool immediate)
|
||||
{
|
||||
Debug.Print("BaseProcessProtocolHandler.StopListenerChannel(protocolId:" + protocolId + ", listenerChannelId:" + listenerChannelId + ", immediate:" + immediate + ")");
|
||||
ListenerChannelContext listenerChannelContext = this.listenerChannelIdMapping[listenerChannelId];
|
||||
adphManager.StopAppDomainProtocolListenerChannel(listenerChannelContext.AppKey, protocolId, listenerChannelId, immediate);
|
||||
|
||||
lock (this.listenerChannelIdMapping)
|
||||
{
|
||||
// Remove the channel id.
|
||||
this.listenerChannelIdMapping.Remove(listenerChannelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Activation;
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUninstantiatedInternalClasses,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
class MsmqAppDomainProtocolHandler : BaseAppDomainProtocolHandler
|
||||
{
|
||||
public MsmqAppDomainProtocolHandler()
|
||||
: base(MsmqUri.NetMsmqAddressTranslator.Scheme)
|
||||
{ }
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
MsmqHostedTransportConfiguration configuration = HostedTransportConfigurationManager.GetConfiguration(MsmqUri.NetMsmqAddressTranslator.Scheme) as MsmqHostedTransportConfiguration;
|
||||
configuration.TransportManager.Start(OnMessageReceived);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Activation;
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUninstantiatedInternalClasses,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
class MsmqIntegrationAppDomainProtocolHandler : BaseAppDomainProtocolHandler
|
||||
{
|
||||
public MsmqIntegrationAppDomainProtocolHandler()
|
||||
: base(MsmqUri.FormatNameAddressTranslator.Scheme)
|
||||
{ }
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
MsmqHostedTransportConfiguration configuration = HostedTransportConfigurationManager.GetConfiguration(MsmqUri.FormatNameAddressTranslator.Scheme) as MsmqHostedTransportConfiguration;
|
||||
configuration.TransportManager.Start(OnMessageReceived);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Activation;
|
||||
using System.Web.Hosting;
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUninstantiatedInternalClasses,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
class MsmqIntegrationProcessProtocolHandler : BaseProcessProtocolHandler
|
||||
{
|
||||
public MsmqIntegrationProcessProtocolHandler()
|
||||
: base(MsmqUri.FormatNameAddressTranslator.Scheme)
|
||||
{ }
|
||||
|
||||
internal override void HandleStartListenerChannelError(IListenerChannelCallback listenerChannelCallback, Exception ex)
|
||||
{
|
||||
listenerChannelCallback.ReportStarted();
|
||||
listenerChannelCallback.ReportStopped(Marshal.GetHRForException(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Activation;
|
||||
using System.Web.Hosting;
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUninstantiatedInternalClasses,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
class MsmqProcessProtocolHandler : BaseProcessProtocolHandler
|
||||
{
|
||||
public MsmqProcessProtocolHandler()
|
||||
: base(MsmqUri.NetMsmqAddressTranslator.Scheme)
|
||||
{ }
|
||||
|
||||
internal override void HandleStartListenerChannelError(IListenerChannelCallback listenerChannelCallback, Exception ex)
|
||||
{
|
||||
listenerChannelCallback.ReportStarted();
|
||||
listenerChannelCallback.ReportStopped(System.Runtime.InteropServices.Marshal.GetHRForException(ex));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel.Activation;
|
||||
using System.ServiceModel.Channels;
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUninstantiatedInternalClasses,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
class NamedPipeAppDomainProtocolHandler : BaseAppDomainProtocolHandler
|
||||
{
|
||||
HostedNamedPipeTransportManager transportManager;
|
||||
|
||||
public NamedPipeAppDomainProtocolHandler()
|
||||
: base(Uri.UriSchemeNetPipe)
|
||||
{ }
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
NamedPipeHostedTransportConfiguration configuration =
|
||||
HostedTransportConfigurationManager.GetConfiguration(Uri.UriSchemeNetPipe) as NamedPipeHostedTransportConfiguration;
|
||||
transportManager = configuration.TransportManager as HostedNamedPipeTransportManager;
|
||||
transportManager.Start(listenerChannelContext.ListenerChannelId, listenerChannelContext.Token, OnMessageReceived);
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
if (transportManager != null)
|
||||
{
|
||||
transportManager.Stop(DefaultStopTimeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel.Channels;
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUninstantiatedInternalClasses,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
class NamedPipeProcessProtocolHandler : BaseProcessProtocolHandler
|
||||
{
|
||||
public NamedPipeProcessProtocolHandler()
|
||||
: base(Uri.UriSchemeNetPipe)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel.Activation;
|
||||
using System.ServiceModel.Channels;
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUninstantiatedInternalClasses,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
class TcpAppDomainProtocolHandler : BaseAppDomainProtocolHandler
|
||||
{
|
||||
HostedTcpTransportManager transportManager;
|
||||
public TcpAppDomainProtocolHandler()
|
||||
: base(Uri.UriSchemeNetTcp)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
TcpHostedTransportConfiguration configuration = HostedTransportConfigurationManager.GetConfiguration(Uri.UriSchemeNetTcp) as TcpHostedTransportConfiguration;
|
||||
transportManager = configuration.TransportManager as HostedTcpTransportManager;
|
||||
transportManager.Start(listenerChannelContext.ListenerChannelId, listenerChannelContext.Token, OnMessageReceived);
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
if (transportManager != null)
|
||||
{
|
||||
transportManager.Stop(DefaultStopTimeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
namespace System.ServiceModel.WasHosting
|
||||
{
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
using System.ServiceModel.Channels;
|
||||
|
||||
[SuppressMessage(FxCop.Category.Performance, FxCop.Rule.AvoidUninstantiatedInternalClasses,
|
||||
Justification = "Instantiated by ASP.NET")]
|
||||
class TcpProcessProtocolHandler : BaseProcessProtocolHandler
|
||||
{
|
||||
public TcpProcessProtocolHandler()
|
||||
: base(Uri.UriSchemeNetTcp)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user