Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / NamedPipeConnectionPool.cs / 1 / NamedPipeConnectionPool.cs
//----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Net.Sockets;
using System.IO;
class NamedPipeConnectionPoolRegistry : ConnectionPoolRegistry
{
public NamedPipeConnectionPoolRegistry()
: base()
{
}
protected override ConnectionPool CreatePool(IConnectionOrientedTransportChannelFactorySettings settings)
{
return new NamedPipeConnectionPool(settings);
}
class NamedPipeConnectionPool : ConnectionPool
{
PipeNameCache pipeNameCache;
public NamedPipeConnectionPool(IConnectionOrientedTransportChannelFactorySettings settings)
: base(settings, TimeSpan.MaxValue)
{
this.pipeNameCache = new PipeNameCache();
}
protected override EndpointConnectionPool CreateEndpointConnectionPool(string key)
{
return new NamedPipeEndpointConnectionPool(this, key);
}
protected override string GetPoolKey(EndpointAddress address, Uri via)
{
string result;
lock (base.ThisLock)
{
if (!this.pipeNameCache.TryGetValue(via, out result))
{
result = PipeConnectionInitiator.GetPipeName(via);
this.pipeNameCache.Add(via, result);
}
}
return result;
}
protected override void OnClosed()
{
base.OnClosed();
this.pipeNameCache.Clear();
}
void OnConnectionAborted(string pipeName)
{
// the underlying pipe name may have changed; purge the old one from the cache
lock (base.ThisLock)
{
this.pipeNameCache.Purge(pipeName);
}
}
protected class NamedPipeEndpointConnectionPool : IdleTimeoutEndpointConnectionPool
{
NamedPipeConnectionPool parent;
public NamedPipeEndpointConnectionPool(NamedPipeConnectionPool parent, string key)
: base(parent, key)
{
this.parent = parent;
}
protected override void OnConnectionAborted()
{
parent.OnConnectionAborted(this.Key);
}
}
}
// not thread-safe
class PipeNameCache
{
Dictionary forwardTable = new Dictionary();
Dictionary> reverseTable = new Dictionary>();
public void Add(Uri uri, string pipeName)
{
this.forwardTable.Add(uri, pipeName);
ICollection uris;
if (!this.reverseTable.TryGetValue(pipeName, out uris))
{
uris = new Collection();
this.reverseTable.Add(pipeName, uris);
}
uris.Add(uri);
}
public void Clear()
{
this.forwardTable.Clear();
this.reverseTable.Clear();
}
public void Purge(string pipeName)
{
ICollection uris;
if (this.reverseTable.TryGetValue(pipeName, out uris))
{
this.reverseTable.Remove(pipeName);
foreach (Uri uri in uris)
{
this.forwardTable.Remove(uri);
}
}
}
public bool TryGetValue(Uri uri, out string pipeName)
{
return this.forwardTable.TryGetValue(uri, out pipeName);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TimeoutValidationAttribute.cs
- UIElement.cs
- XmlQueryTypeFactory.cs
- ImageField.cs
- TextTreeInsertElementUndoUnit.cs
- ProcessThread.cs
- FtpWebResponse.cs
- GenericAuthenticationEventArgs.cs
- StreamGeometryContext.cs
- QueryTaskGroupState.cs
- AttributeData.cs
- ProxyAssemblyNotLoadedException.cs
- TranslateTransform3D.cs
- DesignerActionListCollection.cs
- DoubleLink.cs
- GradientStop.cs
- TextEffectResolver.cs
- PrintEvent.cs
- UriSection.cs
- DebugView.cs
- ScriptingRoleServiceSection.cs
- PageThemeParser.cs
- BamlStream.cs
- XmlAttributeOverrides.cs
- ToolStripProgressBar.cs
- EmptyEnumerator.cs
- LeftCellWrapper.cs
- CngAlgorithmGroup.cs
- COM2Enum.cs
- ItemCollection.cs
- PropertiesTab.cs
- recordstatescratchpad.cs
- SymmetricAlgorithm.cs
- Environment.cs
- LessThan.cs
- SqlCacheDependency.cs
- SourceElementsCollection.cs
- ITreeGenerator.cs
- NumberAction.cs
- XsltQilFactory.cs
- LoginViewDesigner.cs
- CqlLexerHelpers.cs
- DeviceContext.cs
- WebBrowserEvent.cs
- DataGridViewAccessibleObject.cs
- ImpersonationContext.cs
- OleDbFactory.cs
- FloatSumAggregationOperator.cs
- DataGridViewElement.cs
- parserscommon.cs
- ellipse.cs
- TransformerTypeCollection.cs
- ExpiredSecurityTokenException.cs
- PersonalizationState.cs
- QilTypeChecker.cs
- ColorTransformHelper.cs
- PropertyGrid.cs
- RectangleConverter.cs
- ByteStack.cs
- AffineTransform3D.cs
- ErrorHandler.cs
- TypeForwardedToAttribute.cs
- SqlUdtInfo.cs
- MethodImplAttribute.cs
- EditableTreeList.cs
- OleDbConnection.cs
- StringInfo.cs
- DeflateStream.cs
- FontConverter.cs
- LineInfo.cs
- ScrollEventArgs.cs
- ObjectNotFoundException.cs
- WebHostUnsafeNativeMethods.cs
- XmlAnyElementAttributes.cs
- BaseTreeIterator.cs
- IdleTimeoutMonitor.cs
- OracleParameter.cs
- Win32PrintDialog.cs
- KeyValuePair.cs
- HttpRawResponse.cs
- Utilities.cs
- TextTreeUndo.cs
- XDeferredAxisSource.cs
- InvalidDocumentContentsException.cs
- KeyValuePairs.cs
- UserCancellationException.cs
- XmlCDATASection.cs
- PointAnimationUsingPath.cs
- ResolveNameEventArgs.cs
- XPathParser.cs
- mansign.cs
- CryptoSession.cs
- WebPartManagerDesigner.cs
- XamlToRtfWriter.cs
- bindurihelper.cs
- SecurityRuntime.cs
- XmlTypeAttribute.cs
- TypeSchema.cs
- StreamWithDictionary.cs
- EventBuilder.cs