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
- OrderedDictionaryStateHelper.cs
- RequestCachingSection.cs
- XmlObjectSerializer.cs
- sqlcontext.cs
- SqlFactory.cs
- PublisherIdentityPermission.cs
- UIElementHelper.cs
- TextBoxRenderer.cs
- EditingCoordinator.cs
- AssemblySettingAttributes.cs
- HandleExceptionArgs.cs
- DescendentsWalker.cs
- XmlHierarchicalDataSourceView.cs
- FillRuleValidation.cs
- XmlCDATASection.cs
- HostExecutionContextManager.cs
- Iis7Helper.cs
- CommandConverter.cs
- XmlHelper.cs
- ComponentDispatcher.cs
- XmlUtil.cs
- ObjectConverter.cs
- ViewSimplifier.cs
- DateTimeUtil.cs
- ErrorHandlingReceiver.cs
- GridViewPageEventArgs.cs
- XamlWriter.cs
- ConsoleCancelEventArgs.cs
- PropagatorResult.cs
- SqlFileStream.cs
- SqlCacheDependencyDatabaseCollection.cs
- ComboBoxAutomationPeer.cs
- Marshal.cs
- WebServiceResponse.cs
- ReliableRequestSessionChannel.cs
- Visitors.cs
- XmlConvert.cs
- DesignTimeParseData.cs
- PhoneCall.cs
- ErrorWrapper.cs
- DataRecordInternal.cs
- DtcInterfaces.cs
- CompilerWrapper.cs
- PerformanceCounterManager.cs
- ChangeConflicts.cs
- EdmItemError.cs
- TextSpanModifier.cs
- CharacterMetricsDictionary.cs
- WithStatement.cs
- ToolStripGripRenderEventArgs.cs
- CustomAttributeSerializer.cs
- xamlnodes.cs
- MenuAutomationPeer.cs
- InvokeMethodActivityDesigner.cs
- PEFileReader.cs
- Hyperlink.cs
- Maps.cs
- indexingfiltermarshaler.cs
- EmptyElement.cs
- SiteIdentityPermission.cs
- ReachFixedPageSerializer.cs
- RequestCacheValidator.cs
- EntityTypeBase.cs
- SiteMapDataSource.cs
- CompilerResults.cs
- ObjectViewFactory.cs
- SplitterEvent.cs
- CodeTypeParameterCollection.cs
- StylusEditingBehavior.cs
- WebPartCollection.cs
- _Connection.cs
- AuthenticationSection.cs
- Odbc32.cs
- GPRECTF.cs
- BuildProviderCollection.cs
- RuntimeEnvironment.cs
- SelectionHighlightInfo.cs
- DataGridView.cs
- WorkerRequest.cs
- DataSourceHelper.cs
- DetailsViewUpdateEventArgs.cs
- WebPageTraceListener.cs
- DataPagerFieldCommandEventArgs.cs
- DesignTimeHTMLTextWriter.cs
- OperatingSystem.cs
- FontFamily.cs
- MetaModel.cs
- ListViewDeleteEventArgs.cs
- IDQuery.cs
- PlaceHolder.cs
- MDIWindowDialog.cs
- __FastResourceComparer.cs
- BaseInfoTable.cs
- CalendarAutoFormat.cs
- GregorianCalendarHelper.cs
- NetworkAddressChange.cs
- MachineKeySection.cs
- HostedTransportConfigurationBase.cs
- Attributes.cs
- EditorZoneAutoFormat.cs