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
- LinkedResourceCollection.cs
- PropertyMapper.cs
- IIS7WorkerRequest.cs
- ProcessThreadCollection.cs
- BindingFormattingDialog.cs
- DataListItemCollection.cs
- _SafeNetHandles.cs
- ListenerElementsCollection.cs
- ClientRuntimeConfig.cs
- MemberPath.cs
- SortedList.cs
- StringFreezingAttribute.cs
- CloudCollection.cs
- TextTreeObjectNode.cs
- WebDisplayNameAttribute.cs
- BStrWrapper.cs
- DaylightTime.cs
- MetadataCache.cs
- DataGridViewUtilities.cs
- Vector3DValueSerializer.cs
- XmlElementCollection.cs
- MethodBody.cs
- GeneralTransform3DCollection.cs
- ComplexBindingPropertiesAttribute.cs
- WebPartDisplayModeCancelEventArgs.cs
- PackWebRequest.cs
- ComplexTypeEmitter.cs
- WebUtil.cs
- CommandConverter.cs
- JsonGlobals.cs
- DecoratedNameAttribute.cs
- ImageSource.cs
- DataKeyArray.cs
- RadioButtonStandardAdapter.cs
- DataRow.cs
- BaseResourcesBuildProvider.cs
- ScriptControl.cs
- GiveFeedbackEvent.cs
- SecurityElement.cs
- HttpHandlersSection.cs
- TableRow.cs
- TextRangeEditTables.cs
- DateTimePicker.cs
- MailHeaderInfo.cs
- reliableinputsessionchannel.cs
- MemoryFailPoint.cs
- BaseCodePageEncoding.cs
- RadialGradientBrush.cs
- SystemIPGlobalProperties.cs
- DataSvcMapFile.cs
- MachineKeyConverter.cs
- Base64Decoder.cs
- EventlogProvider.cs
- TextOutput.cs
- SortableBindingList.cs
- InvalidEnumArgumentException.cs
- FragmentQueryKB.cs
- DocumentViewerHelper.cs
- SystemResources.cs
- DataControlCommands.cs
- BuildDependencySet.cs
- StringValidator.cs
- TraceUtility.cs
- ProjectionNode.cs
- Control.cs
- MonitorWrapper.cs
- COM2EnumConverter.cs
- ImageClickEventArgs.cs
- DataGridToolTip.cs
- DoubleIndependentAnimationStorage.cs
- ImageMap.cs
- HttpContextWrapper.cs
- LoginCancelEventArgs.cs
- ObjectIDGenerator.cs
- WebChannelFactory.cs
- CachedTypeface.cs
- GPPOINT.cs
- TypeInfo.cs
- Opcode.cs
- FileVersion.cs
- ImageIndexConverter.cs
- CompositeCollection.cs
- DataGridViewAccessibleObject.cs
- ValidationErrorCollection.cs
- EnumCodeDomSerializer.cs
- TreeNodeCollectionEditor.cs
- ConfigUtil.cs
- DbParameterCollection.cs
- FormsAuthenticationUser.cs
- Rectangle.cs
- TextTrailingWordEllipsis.cs
- ResourceAssociationType.cs
- Registry.cs
- ErrorRuntimeConfig.cs
- UriTemplateLiteralPathSegment.cs
- MemoryMappedViewStream.cs
- PropertyDescriptorGridEntry.cs
- BeginStoryboard.cs
- WebPartConnectVerb.cs
- mediapermission.cs