56 lines
1.3 KiB
C#
56 lines
1.3 KiB
C#
using BeWo.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.ServiceModel.Channels;
|
|
using System.ServiceModel;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Xml;
|
|
using System.ServiceModel.Dispatcher;
|
|
using BeWo.Service.Core;
|
|
|
|
namespace BeWo.Service.ServiceBehavior
|
|
{
|
|
public class AdminMultitenancyContextInitializer : ICallContextInitializer
|
|
{
|
|
public void AfterInvoke(object pCorrelationState)
|
|
{
|
|
if (pCorrelationState is MultitenancyOperationContextExt)
|
|
{
|
|
OperationContext.Current.Extensions.Remove((MultitenancyOperationContextExt)pCorrelationState);
|
|
}
|
|
}
|
|
|
|
public object BeforeInvoke(InstanceContext pInstanceContext, IClientChannel pChannel, Message pMessage)
|
|
{
|
|
string lTenant = null;
|
|
|
|
try
|
|
{
|
|
if (pMessage.Properties?.Via is Uri uri)
|
|
{
|
|
var query = HttpUtility.ParseQueryString(uri.Query);
|
|
var tenant = query["tenant"];
|
|
|
|
lTenant = tenant;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(lTenant))
|
|
{
|
|
var lExt = new MultitenancyOperationContextExt { Tenant = lTenant };
|
|
OperationContext.Current.Extensions.Add(lExt);
|
|
return lExt;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw Utils.CreateBeWoFaultException(e);
|
|
}
|
|
}
|
|
}
|
|
}
|