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
- NavigationProperty.cs
- TransactionChannelListener.cs
- TextFormatterImp.cs
- ChtmlPageAdapter.cs
- GACMembershipCondition.cs
- LayoutExceptionEventArgs.cs
- ColorConvertedBitmap.cs
- PasswordTextNavigator.cs
- PopupEventArgs.cs
- SerializationStore.cs
- LinearKeyFrames.cs
- QueryIntervalOp.cs
- AmbientValueAttribute.cs
- ReflectionUtil.cs
- MatrixValueSerializer.cs
- DateTimeStorage.cs
- RadioButton.cs
- PathGeometry.cs
- HttpTransportSecurity.cs
- URI.cs
- ClientData.cs
- COM2ComponentEditor.cs
- Throw.cs
- SemanticResolver.cs
- ResourceContainer.cs
- OutputCacheSettingsSection.cs
- StorageMappingFragment.cs
- TemplateBuilder.cs
- FileVersionInfo.cs
- RuntimeEnvironment.cs
- ListMarkerLine.cs
- SettingsPropertyNotFoundException.cs
- JsonServiceDocumentSerializer.cs
- CodeSnippetCompileUnit.cs
- UriParserTemplates.cs
- EntityContainerEntitySetDefiningQuery.cs
- LongPath.cs
- ToolStripRendererSwitcher.cs
- COM2PropertyBuilderUITypeEditor.cs
- ExtensibleClassFactory.cs
- DropSource.cs
- SelectorAutomationPeer.cs
- RenderOptions.cs
- SerialPinChanges.cs
- XmlSchemaCollection.cs
- HandlerFactoryCache.cs
- InputDevice.cs
- HttpWebRequest.cs
- MenuItemStyleCollection.cs
- ColumnWidthChangingEvent.cs
- ReadOnlyCollectionBase.cs
- FillErrorEventArgs.cs
- HMACSHA1.cs
- RNGCryptoServiceProvider.cs
- ApplicationInfo.cs
- MimeObjectFactory.cs
- SchemaElementDecl.cs
- StreamUpdate.cs
- FixedTextPointer.cs
- TextParagraph.cs
- BindingList.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- ResolveNameEventArgs.cs
- ColumnPropertiesGroup.cs
- BaseTreeIterator.cs
- SqlTrackingService.cs
- ProtocolsConfigurationHandler.cs
- ProcessInfo.cs
- BufferedReadStream.cs
- ApplicationGesture.cs
- GetPageNumberCompletedEventArgs.cs
- EventWaitHandle.cs
- XmlAttributeOverrides.cs
- PropertyConverter.cs
- PathData.cs
- XmlSerializerFormatAttribute.cs
- TargetException.cs
- EventlogProvider.cs
- DataServiceBehavior.cs
- GeneralTransformGroup.cs
- XslCompiledTransform.cs
- TemplatePartAttribute.cs
- ValidatedControlConverter.cs
- SapiRecoContext.cs
- SymmetricCryptoHandle.cs
- GuidelineCollection.cs
- BaseTreeIterator.cs
- X509SecurityToken.cs
- CompensationParticipant.cs
- KnownTypes.cs
- SystemIcons.cs
- XmlChoiceIdentifierAttribute.cs
- GlyphsSerializer.cs
- ResourceManager.cs
- DataMemberConverter.cs
- NativeMethodsCLR.cs
- SimpleNameService.cs
- GridViewUpdatedEventArgs.cs
- TokenFactoryBase.cs
- SafeFileHandle.cs