Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / ChannelFactoryRefCache.cs / 1 / ChannelFactoryRefCache.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- using System.ServiceModel.Channels; using System.Collections.Generic; namespace System.ServiceModel { sealed class EndpointTraitwhere TChannel : class { string endpointConfigurationName; EndpointAddress remoteAddress; InstanceContext callbackInstance; public EndpointTrait(string endpointConfigurationName, EndpointAddress remoteAddress, InstanceContext callbackInstance) { this.endpointConfigurationName = endpointConfigurationName; this.remoteAddress = remoteAddress; this.callbackInstance = callbackInstance; } public override bool Equals(object obj) { EndpointTrait trait1 = obj as EndpointTrait ; if (trait1 == null) return false; if (!object.ReferenceEquals(this.callbackInstance, trait1.callbackInstance)) return false; if (string.CompareOrdinal(this.endpointConfigurationName, trait1.endpointConfigurationName) != 0) { return false; } // EndpointAddress.Equals is used. if (this.remoteAddress != trait1.remoteAddress) return false; return true; } public override int GetHashCode() { int hashCode = 0; if (this.callbackInstance != null) { hashCode ^= this.callbackInstance.GetHashCode(); } hashCode ^= this.endpointConfigurationName.GetHashCode(); if (this.remoteAddress != null) hashCode ^= this.remoteAddress.GetHashCode(); return hashCode; } public ChannelFactory CreateChannelFactory() { if (this.callbackInstance != null) return CreateDuplexFactory(); return CreateSimplexFactory(); } DuplexChannelFactory CreateDuplexFactory() { if (this.remoteAddress != null) { return new DuplexChannelFactory (this.callbackInstance, this.endpointConfigurationName, this.remoteAddress); } return new DuplexChannelFactory (this.callbackInstance, this.endpointConfigurationName); } ChannelFactory CreateSimplexFactory() { if (this.remoteAddress != null) { return new ChannelFactory (this.endpointConfigurationName, this.remoteAddress); } return new ChannelFactory (this.endpointConfigurationName); } } sealed class ChannelFactoryRef where TChannel : class { ChannelFactory channelFactory; int refCount = 1; public ChannelFactoryRef(ChannelFactory 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; DiagnosticUtility.DebugAssert(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 ChannelFactory { get { return this.channelFactory; } } } class ChannelFactoryRefCache : MruCache , ChannelFactoryRef > where TChannel : class { static EndpointTraitComparer DefaultEndpointTraitComparer = new EndpointTraitComparer(); class EndpointTraitComparer : IEqualityComparer > { public bool Equals(EndpointTrait x, EndpointTrait y) { if (x != null) { if (y != null) return x.Equals(y); return false; } if (y != null) return false; return true; } public int GetHashCode(EndpointTrait obj) { if (obj == null) return 0; return obj.GetHashCode(); } } public ChannelFactoryRefCache(int watermark) : base(watermark * 4 / 5, watermark, DefaultEndpointTraitComparer) { } protected override void OnSingleItemRemoved(ChannelFactoryRef item) { // Remove from cache. if (item.Release()) { item.Abort(); } } } } // 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
- DefaultEventAttribute.cs
- GPRECT.cs
- TableLayoutSettingsTypeConverter.cs
- CheckedListBox.cs
- IDReferencePropertyAttribute.cs
- KeyInfo.cs
- Decorator.cs
- Message.cs
- SettingsPropertyValueCollection.cs
- ArrayWithOffset.cs
- ToolStripDesignerAvailabilityAttribute.cs
- HelpKeywordAttribute.cs
- Aes.cs
- TransformGroup.cs
- NavigateEvent.cs
- DesignerContextDescriptor.cs
- DisableDpiAwarenessAttribute.cs
- ParallelEnumerable.cs
- LambdaSerializationException.cs
- FormsAuthenticationUser.cs
- DeviceContext.cs
- CmsUtils.cs
- GeneratedCodeAttribute.cs
- DataMember.cs
- SQLString.cs
- _NegotiateClient.cs
- Image.cs
- CaseExpr.cs
- DirectoryNotFoundException.cs
- ProcessHostConfigUtils.cs
- CacheMemory.cs
- SmtpCommands.cs
- BrowserCapabilitiesFactoryBase.cs
- ConfigurationErrorsException.cs
- ToolStripSeparatorRenderEventArgs.cs
- DataGrid.cs
- ProcessModelSection.cs
- WindowExtensionMethods.cs
- MarshalByValueComponent.cs
- DataListCommandEventArgs.cs
- SoapFormatExtensions.cs
- TrackingRecord.cs
- SQLSingle.cs
- PeerApplication.cs
- HttpHeaderCollection.cs
- HtmlTableRowCollection.cs
- ISO2022Encoding.cs
- Content.cs
- RegexCompilationInfo.cs
- UnmanagedMemoryStreamWrapper.cs
- BaseDataListPage.cs
- path.cs
- WindowsListViewScroll.cs
- SubclassTypeValidator.cs
- GcHandle.cs
- WindowsScrollBarBits.cs
- TableSectionStyle.cs
- _UriTypeConverter.cs
- UnsafeNativeMethods.cs
- Clock.cs
- TableProvider.cs
- SchemaEntity.cs
- Volatile.cs
- XmlEntity.cs
- DefaultSerializationProviderAttribute.cs
- SqlFacetAttribute.cs
- SqlCommand.cs
- LineSegment.cs
- DataKeyArray.cs
- ObjectAnimationUsingKeyFrames.cs
- DescendantBaseQuery.cs
- GraphicsContext.cs
- FileReservationCollection.cs
- TableCell.cs
- IdnMapping.cs
- SubclassTypeValidatorAttribute.cs
- MessageDecoder.cs
- FlowDocumentPage.cs
- ClientTargetSection.cs
- SecureEnvironment.cs
- ApplicationTrust.cs
- CollectionViewSource.cs
- TypeLibConverter.cs
- DataBindingCollection.cs
- Int64Storage.cs
- SafeSecurityHandles.cs
- BasicExpandProvider.cs
- PlanCompiler.cs
- SoapObjectWriter.cs
- ReadWriteSpinLock.cs
- MessageDecoder.cs
- Comparer.cs
- SourceInterpreter.cs
- ArrayElementGridEntry.cs
- XmlWellformedWriter.cs
- PreservationFileReader.cs
- GlyphRunDrawing.cs
- XmlChoiceIdentifierAttribute.cs
- Rules.cs
- RuntimeConfig.cs