mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-19 01:31:17 -10:00
Adding reference source for System.Data System.Data.DataSetExtensions System.Data.Entity System.Data.Entity.Design System.Data.Linq System.Data.SqlXml System.ServiceModel System.ServiceModel.Activation System.ServiceModel.Activities System.ServiceModel.Channels System.ServiceModel.Discovery System.ServiceModel.Internals System.ServiceModel.Routing System.ServiceModel.WasHosting System.ServiceModel.Web System.Web System.Web.ApplicationServices System.Web.DynamicData System.Web.Entity System.Web.Entity.Design System.Web.Extensions System.Web.Mobile System.Web.Routing System.Web.Services System.Xml System.Xml.Linq
123 lines
3.3 KiB
C#
123 lines
3.3 KiB
C#
//------------------------------------------------------------
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
//------------------------------------------------------------
|
|
|
|
namespace System.ServiceModel
|
|
{
|
|
using System.Collections.Generic;
|
|
using System.Runtime;
|
|
using System.ServiceModel.Channels;
|
|
using System.ServiceModel.Diagnostics.Application;
|
|
|
|
sealed class ChannelFactoryRef<TChannel>
|
|
where TChannel : class
|
|
{
|
|
ChannelFactory<TChannel> channelFactory;
|
|
int refCount = 1;
|
|
|
|
public ChannelFactoryRef(ChannelFactory<TChannel> channelFactory)
|
|
{
|
|
this.channelFactory = channelFactory;
|
|
}
|
|
|
|
public void AddRef()
|
|
{
|
|
this.refCount++;
|
|
}
|
|
|
|
// The caller should call Close/Abort when the return value is true.
|
|
public bool Release()
|
|
{
|
|
--this.refCount;
|
|
Fx.Assert(this.refCount >= 0, "RefCount should not be less than zero.");
|
|
|
|
if (this.refCount == 0)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void Close(TimeSpan timeout)
|
|
{
|
|
this.channelFactory.Close(timeout);
|
|
}
|
|
|
|
public void Abort()
|
|
{
|
|
this.channelFactory.Abort();
|
|
}
|
|
|
|
public ChannelFactory<TChannel> ChannelFactory
|
|
{
|
|
get
|
|
{
|
|
return this.channelFactory;
|
|
}
|
|
}
|
|
}
|
|
|
|
class ChannelFactoryRefCache<TChannel> : MruCache<EndpointTrait<TChannel>, ChannelFactoryRef<TChannel>>
|
|
where TChannel : class
|
|
{
|
|
static EndpointTraitComparer DefaultEndpointTraitComparer = new EndpointTraitComparer();
|
|
readonly int watermark;
|
|
|
|
class EndpointTraitComparer : IEqualityComparer<EndpointTrait<TChannel>>
|
|
{
|
|
public bool Equals(EndpointTrait<TChannel> x, EndpointTrait<TChannel> y)
|
|
{
|
|
if (x != null)
|
|
{
|
|
if (y != null)
|
|
return x.Equals(y);
|
|
|
|
return false;
|
|
}
|
|
|
|
if (y != null)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public int GetHashCode(EndpointTrait<TChannel> obj)
|
|
{
|
|
if (obj == null)
|
|
return 0;
|
|
|
|
return obj.GetHashCode();
|
|
}
|
|
}
|
|
|
|
public ChannelFactoryRefCache(int watermark)
|
|
: base(watermark * 4 / 5, watermark, DefaultEndpointTraitComparer)
|
|
{
|
|
this.watermark = watermark;
|
|
}
|
|
|
|
protected override void OnSingleItemRemoved(ChannelFactoryRef<TChannel> item)
|
|
{
|
|
// Remove from cache.
|
|
if (item.Release())
|
|
{
|
|
item.Abort();
|
|
}
|
|
|
|
if (TD.ClientBaseCachedChannelFactoryCountIsEnabled())
|
|
{
|
|
TD.ClientBaseCachedChannelFactoryCount(this.Count, this.watermark, this);
|
|
}
|
|
}
|
|
|
|
protected override void OnItemAgedOutOfCache(ChannelFactoryRef<TChannel> item)
|
|
{
|
|
if (TD.ClientBaseChannelFactoryAgedOutofCacheIsEnabled())
|
|
{
|
|
TD.ClientBaseChannelFactoryAgedOutofCache(this.watermark, this);
|
|
}
|
|
}
|
|
}
|
|
}
|