moved from SVN to git
This commit is contained in:
21
Service/UnitOfWork/HibernateSessionBehaviorExtension.cs
Normal file
21
Service/UnitOfWork/HibernateSessionBehaviorExtension.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.ServiceModel.Configuration;
|
||||
|
||||
namespace BeWo.Service.UnitOfWork
|
||||
{
|
||||
public class HibernateSessionBehaviorExtension : BehaviorExtensionElement
|
||||
{
|
||||
public override Type BehaviorType
|
||||
{
|
||||
get
|
||||
{
|
||||
return typeof(HibernateSessionEndpointBehavior);
|
||||
}
|
||||
}
|
||||
|
||||
protected override object CreateBehavior()
|
||||
{
|
||||
return new HibernateSessionEndpointBehavior();
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Service/UnitOfWork/HibernateSessionContextInitializer.cs
Normal file
42
Service/UnitOfWork/HibernateSessionContextInitializer.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Dispatcher;
|
||||
|
||||
using BeWo.Data;
|
||||
|
||||
namespace BeWo.Service.UnitOfWork
|
||||
{
|
||||
public class HibernateSessionContextInitializer : ICallContextInitializer
|
||||
{
|
||||
public void AfterInvoke(object pCorrelationState)
|
||||
{
|
||||
if (pCorrelationState != null)
|
||||
{
|
||||
WCFHibernateSessionManager.CloseSession();
|
||||
OperationContext.Current.Extensions.Remove((SessionOperationContextExt)pCorrelationState);
|
||||
}
|
||||
}
|
||||
|
||||
public object BeforeInvoke(InstanceContext pInstanceContext, IClientChannel pChannel, Message pMessage)
|
||||
{
|
||||
try
|
||||
{
|
||||
//System.Threading.Monitor.Enter
|
||||
SessionOperationContextExt lExt = new SessionOperationContextExt();
|
||||
//int c = OperationContext.Current.Extensions.Count;
|
||||
//if (c > 0)
|
||||
//{
|
||||
// int te st = 0;
|
||||
//}
|
||||
OperationContext.Current.Extensions.Add(lExt);
|
||||
WCFHibernateSessionManager.OpenSession();
|
||||
return lExt;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Service/UnitOfWork/HibernateSessionEndpointBehavior.cs
Normal file
29
Service/UnitOfWork/HibernateSessionEndpointBehavior.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.ServiceModel.Channels;
|
||||
using System.ServiceModel.Description;
|
||||
using System.ServiceModel.Dispatcher;
|
||||
|
||||
namespace BeWo.Service.UnitOfWork
|
||||
{
|
||||
public class HibernateSessionEndpointBehavior : IEndpointBehavior
|
||||
{
|
||||
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
|
||||
{
|
||||
}
|
||||
|
||||
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
|
||||
{
|
||||
}
|
||||
|
||||
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
|
||||
{
|
||||
foreach (DispatchOperation iOperation in endpointDispatcher.DispatchRuntime.Operations)
|
||||
{
|
||||
iOperation.CallContextInitializers.Add(new HibernateSessionContextInitializer());
|
||||
}
|
||||
}
|
||||
|
||||
public void Validate(ServiceEndpoint endpoint)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user