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
- MouseGestureValueSerializer.cs
- GuidConverter.cs
- XmlCodeExporter.cs
- DatagridviewDisplayedBandsData.cs
- XmlRawWriterWrapper.cs
- AssociationEndMember.cs
- PrivilegeNotHeldException.cs
- InheritablePropertyChangeInfo.cs
- UnsignedPublishLicense.cs
- WebBrowserHelper.cs
- ConfigXmlCDataSection.cs
- XPathParser.cs
- iisPickupDirectory.cs
- ValidationResult.cs
- ObjectConverter.cs
- ExtensionWindowResizeGrip.cs
- TypeBrowser.xaml.cs
- UrlRoutingHandler.cs
- ToolStripSettings.cs
- DuplexSecurityProtocolFactory.cs
- KnownTypesProvider.cs
- Quaternion.cs
- HttpListenerResponse.cs
- PersistenceTypeAttribute.cs
- WindowClosedEventArgs.cs
- ColumnWidthChangingEvent.cs
- WorkflowTerminatedException.cs
- ObjectQueryState.cs
- ThemeDirectoryCompiler.cs
- SmtpCommands.cs
- Compiler.cs
- XmlSchemaCollection.cs
- NullableFloatMinMaxAggregationOperator.cs
- FileDialog_Vista.cs
- TableLayoutCellPaintEventArgs.cs
- ObjectResult.cs
- DataSourceCacheDurationConverter.cs
- SqlDataSourceConfigureSortForm.cs
- DefaultTextStoreTextComposition.cs
- RecognizedWordUnit.cs
- TabControl.cs
- ToolStripButton.cs
- StringHelper.cs
- XPathScanner.cs
- CancellableEnumerable.cs
- WinEventWrap.cs
- SurrogateEncoder.cs
- GradientStop.cs
- ViewPort3D.cs
- AppearanceEditorPart.cs
- TextStore.cs
- Padding.cs
- SqlCharStream.cs
- OdbcError.cs
- PipelineComponent.cs
- AttributeCollection.cs
- RotateTransform3D.cs
- ChtmlTextWriter.cs
- FontUnitConverter.cs
- MultipartIdentifier.cs
- MetadataCache.cs
- OrthographicCamera.cs
- Menu.cs
- SkinIDTypeConverter.cs
- RangeContentEnumerator.cs
- CngAlgorithmGroup.cs
- Freezable.cs
- HandlerWithFactory.cs
- UndoManager.cs
- BaseCodeDomTreeGenerator.cs
- CodeParameterDeclarationExpressionCollection.cs
- ListControlConvertEventArgs.cs
- TemplateKey.cs
- XmlSchemaExporter.cs
- DetailsViewInsertEventArgs.cs
- MemberNameValidator.cs
- LocalBuilder.cs
- XmlQualifiedName.cs
- TabItemWrapperAutomationPeer.cs
- QueryComponents.cs
- XPathAxisIterator.cs
- StoryFragments.cs
- OverloadGroupAttribute.cs
- TableItemStyle.cs
- AnnouncementDispatcherAsyncResult.cs
- BindUriHelper.cs
- SQLBoolean.cs
- ColorConvertedBitmap.cs
- XmlNodeComparer.cs
- AsymmetricKeyExchangeFormatter.cs
- CopyNamespacesAction.cs
- ConfigurationValues.cs
- InstanceKeyCollisionException.cs
- BinaryUtilClasses.cs
- InProcStateClientManager.cs
- ServiceMemoryGates.cs
- ToolBar.cs
- ProjectedWrapper.cs
- UnsafeNativeMethods.cs
- ObjectSet.cs