Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / BodyWriter.cs / 1 / BodyWriter.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System.Xml; using System.Diagnostics; public abstract class BodyWriter { bool isBuffered; bool canWrite; object thisLock; protected BodyWriter(bool isBuffered) { this.isBuffered = isBuffered; this.canWrite = true; if (!this.isBuffered) { this.thisLock = new object(); } } public bool IsBuffered { get { return this.isBuffered; } } internal virtual bool IsEmpty { get { return false; } } internal virtual bool IsFault { get { return false; } } public BodyWriter CreateBufferedCopy(int maxBufferSize) { if (maxBufferSize < 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxBufferSize", maxBufferSize, SR.GetString(SR.ValueMustBeNonNegative))); if (this.isBuffered) { return this; } else { lock (this.thisLock) { if (!this.canWrite) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.BodyWriterCanOnlyBeWrittenOnce))); this.canWrite = false; } BodyWriter bodyWriter = OnCreateBufferedCopy(maxBufferSize); if (!bodyWriter.IsBuffered) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.BodyWriterReturnedIsNotBuffered))); return bodyWriter; } } protected virtual BodyWriter OnCreateBufferedCopy(int maxBufferSize) { return OnCreateBufferedCopy(maxBufferSize, XmlDictionaryReaderQuotas.Max); } internal BodyWriter OnCreateBufferedCopy(int maxBufferSize, XmlDictionaryReaderQuotas quotas) { XmlBuffer buffer = new XmlBuffer(maxBufferSize); using (XmlDictionaryWriter writer = buffer.OpenSection(quotas)) { writer.WriteStartElement("a"); OnWriteBodyContents(writer); writer.WriteEndElement(); } buffer.CloseSection(); buffer.Close(); return new BufferedBodyWriter(buffer); } protected abstract void OnWriteBodyContents(XmlDictionaryWriter writer); public void WriteBodyContents(XmlDictionaryWriter writer) { if (writer == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); if (!this.isBuffered) { lock (this.thisLock) { if (!this.canWrite) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.BodyWriterCanOnlyBeWrittenOnce))); this.canWrite = false; } } OnWriteBodyContents(writer); } class BufferedBodyWriter : BodyWriter { XmlBuffer buffer; public BufferedBodyWriter(XmlBuffer buffer) : base(true) { this.buffer = buffer; } protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { XmlDictionaryReader reader = this.buffer.GetReader(0); using (reader) { reader.ReadStartElement(); while (reader.NodeType != XmlNodeType.EndElement) { writer.WriteNode(reader, false); } reader.ReadEndElement(); } } } } } // 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
- MostlySingletonList.cs
- ActivityStateQuery.cs
- SqlDataSourceQueryConverter.cs
- FontConverter.cs
- CompositeCollectionView.cs
- DefaultMemberAttribute.cs
- DynamicMetaObject.cs
- CanonicalizationDriver.cs
- PeerService.cs
- EventLogPermission.cs
- DbConnectionPool.cs
- PointLight.cs
- DataSourceHelper.cs
- ToolStripItemEventArgs.cs
- CanonicalFontFamilyReference.cs
- ISCIIEncoding.cs
- DataGridColumn.cs
- SQLDecimal.cs
- StorageTypeMapping.cs
- AuthenticatedStream.cs
- FolderLevelBuildProviderCollection.cs
- StringConcat.cs
- ArraySegment.cs
- RepeaterItem.cs
- FilteredSchemaElementLookUpTable.cs
- PointHitTestParameters.cs
- DocumentReferenceCollection.cs
- Types.cs
- PropertyGrid.cs
- BitmapMetadataBlob.cs
- TraceEventCache.cs
- LogLogRecordHeader.cs
- FolderBrowserDialog.cs
- TemplateManager.cs
- GreaterThan.cs
- Win32.cs
- NetDataContractSerializer.cs
- User.cs
- IndicFontClient.cs
- WindowsAltTab.cs
- StoreAnnotationsMap.cs
- BamlBinaryWriter.cs
- BitmapVisualManager.cs
- CommonProperties.cs
- CultureMapper.cs
- LambdaSerializationException.cs
- ProcessRequestArgs.cs
- RectAnimationClockResource.cs
- Merger.cs
- ScrollEvent.cs
- CodePrimitiveExpression.cs
- namescope.cs
- StreamWithDictionary.cs
- OleCmdHelper.cs
- CaseExpr.cs
- OleAutBinder.cs
- DispatcherExceptionFilterEventArgs.cs
- Frame.cs
- Inline.cs
- DataGridViewCellConverter.cs
- WindowsComboBox.cs
- CheckBoxField.cs
- keycontainerpermission.cs
- Int16KeyFrameCollection.cs
- PriorityChain.cs
- ParameterExpression.cs
- Stack.cs
- DataGridTextBoxColumn.cs
- DSASignatureFormatter.cs
- LinkLabel.cs
- WebContentFormatHelper.cs
- CookieParameter.cs
- HTMLTagNameToTypeMapper.cs
- PackUriHelper.cs
- ToolStripContentPanel.cs
- AutomationProperties.cs
- HttpPostedFile.cs
- CreateUserWizardStep.cs
- UInt64Converter.cs
- Error.cs
- MeshGeometry3D.cs
- DeadCharTextComposition.cs
- GraphicsPath.cs
- VerificationAttribute.cs
- WeakHashtable.cs
- XamlBuildTaskServices.cs
- MessageQueuePermission.cs
- XPathEmptyIterator.cs
- TextDecoration.cs
- ProfileInfo.cs
- ScrollChrome.cs
- PhotoPrintingIntent.cs
- ControlCodeDomSerializer.cs
- StrokeSerializer.cs
- UnhandledExceptionEventArgs.cs
- ActivityStateQuery.cs
- TextEvent.cs
- DefaultObjectMappingItemCollection.cs
- DataGridHeaderBorder.cs
- XmlKeywords.cs