Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / BufferedMessageData.cs / 1 / BufferedMessageData.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System.IO; using System.Xml; using System.Text; using System.Collections.Generic; abstract class BufferedMessageData : IBufferedMessageData { ArraySegmentbuffer; BufferManager bufferManager; int refCount; int outstandingReaders; bool multipleUsers; RecycledMessageState messageState; SynchronizedPool messageStatePool; public BufferedMessageData(SynchronizedPool messageStatePool) { this.messageStatePool = messageStatePool; } public ArraySegment Buffer { get { return buffer; } } public BufferManager BufferManager { get { return bufferManager; } } public virtual XmlDictionaryReaderQuotas Quotas { get { return XmlDictionaryReaderQuotas.Max; } } public abstract MessageEncoder MessageEncoder { get; } object ThisLock { get { return this; } } public void EnableMultipleUsers() { multipleUsers = true; } public void Close() { if (multipleUsers) { lock (ThisLock) { if (--this.refCount == 0) { DoClose(); } } } else { DoClose(); } } void DoClose() { bufferManager.ReturnBuffer(buffer.Array); if (outstandingReaders == 0) { bufferManager = null; buffer = new ArraySegment (); OnClosed(); } } public void DoReturnMessageState(RecycledMessageState messageState) { if (this.messageState == null) { this.messageState = messageState; } else { messageStatePool.Return(messageState); } } void DoReturnXmlReader(XmlDictionaryReader reader) { ReturnXmlReader(reader); outstandingReaders--; } public RecycledMessageState DoTakeMessageState() { RecycledMessageState messageState = this.messageState; if (messageState != null) { this.messageState = null; return messageState; } else { return messageStatePool.Take(); } } XmlDictionaryReader DoTakeXmlReader() { XmlDictionaryReader reader = TakeXmlReader(); outstandingReaders++; return reader; } public XmlDictionaryReader GetMessageReader() { if (multipleUsers) { lock (ThisLock) { return DoTakeXmlReader(); } } else { return DoTakeXmlReader(); } } public void OnXmlReaderClosed(XmlDictionaryReader reader) { if (multipleUsers) { lock (ThisLock) { DoReturnXmlReader(reader); } } else { DoReturnXmlReader(reader); } } protected virtual void OnClosed() { } public RecycledMessageState TakeMessageState() { if (multipleUsers) { lock (ThisLock) { return DoTakeMessageState(); } } else { return DoTakeMessageState(); } } protected abstract XmlDictionaryReader TakeXmlReader(); public void Open() { lock (ThisLock) { this.refCount++; } } public void Open(ArraySegment buffer, BufferManager bufferManager) { this.refCount = 1; this.bufferManager = bufferManager; this.buffer = buffer; multipleUsers = false; } protected abstract void ReturnXmlReader(XmlDictionaryReader xmlReader); public void ReturnMessageState(RecycledMessageState messageState) { if (multipleUsers) { lock (ThisLock) { DoReturnMessageState(messageState); } } else { DoReturnMessageState(messageState); } } } } // 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
- TypeGeneratedEventArgs.cs
- ButtonColumn.cs
- CapabilitiesRule.cs
- ControlsConfig.cs
- PassportAuthentication.cs
- EntityRecordInfo.cs
- CallContext.cs
- ByteAnimationUsingKeyFrames.cs
- HwndMouseInputProvider.cs
- RelationshipEndCollection.cs
- X509Utils.cs
- PKCS1MaskGenerationMethod.cs
- DataRowExtensions.cs
- ColorConvertedBitmap.cs
- MessageUtil.cs
- Graph.cs
- SQLDouble.cs
- TrackingMemoryStream.cs
- FlowDocumentReader.cs
- SynchronizedPool.cs
- TaiwanCalendar.cs
- SamlAdvice.cs
- DeviceFilterDictionary.cs
- TrustManagerPromptUI.cs
- CheckableControlBaseAdapter.cs
- XmlSchemaInfo.cs
- IPEndPointCollection.cs
- DataDesignUtil.cs
- XmlDocumentSchema.cs
- CompleteWizardStep.cs
- ApplicationServicesHostFactory.cs
- ExpandCollapseProviderWrapper.cs
- SystemPens.cs
- AuthenticationModulesSection.cs
- DesignUtil.cs
- WindowsImpersonationContext.cs
- BinaryReader.cs
- FloatUtil.cs
- DecoratedNameAttribute.cs
- _CommandStream.cs
- MatrixCamera.cs
- FrameworkContentElement.cs
- HandleCollector.cs
- WhitespaceSignificantCollectionAttribute.cs
- MediaSystem.cs
- RequestQueryProcessor.cs
- RawStylusInputCustomDataList.cs
- DataRowChangeEvent.cs
- LocalizabilityAttribute.cs
- Bezier.cs
- DataGridViewColumnConverter.cs
- EncoderExceptionFallback.cs
- KeyToListMap.cs
- QueryCacheManager.cs
- AQNBuilder.cs
- RelationshipEndMember.cs
- MethodCallConverter.cs
- QueryReaderSettings.cs
- RtfFormatStack.cs
- FormClosedEvent.cs
- ProfilePropertySettings.cs
- TagNameToTypeMapper.cs
- MenuItemCollection.cs
- MILUtilities.cs
- CodeGeneratorOptions.cs
- ModuleElement.cs
- TableParagraph.cs
- StorageModelBuildProvider.cs
- RecognizedPhrase.cs
- DeferredElementTreeState.cs
- CheckBoxPopupAdapter.cs
- CompoundFileStreamReference.cs
- WebHttpBindingCollectionElement.cs
- WindowsListViewSubItem.cs
- ICspAsymmetricAlgorithm.cs
- FileClassifier.cs
- _AcceptOverlappedAsyncResult.cs
- WebPartPersonalization.cs
- PingOptions.cs
- ChangeInterceptorAttribute.cs
- SafeThemeHandle.cs
- PersistenceTypeAttribute.cs
- __TransparentProxy.cs
- PeerNameRecord.cs
- FrameworkContentElement.cs
- GridViewRow.cs
- RtfFormatStack.cs
- Focus.cs
- UIElement.cs
- RootProfilePropertySettingsCollection.cs
- Socket.cs
- SchemaTableColumn.cs
- RpcCryptoRequest.cs
- CellTreeNodeVisitors.cs
- CodeExpressionStatement.cs
- SctClaimSerializer.cs
- TextBox.cs
- WebPartMenu.cs
- PasswordPropertyTextAttribute.cs
- EditingContext.cs