Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Channels / StreamBodyWriter.cs / 1305376 / StreamBodyWriter.cs
//---------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------------------- namespace System.ServiceModel.Channels { using System; using System.IO; using System.Runtime; using System.ServiceModel; using System.Xml; using DiagnosticUtility = System.ServiceModel.DiagnosticUtility; public abstract class StreamBodyWriter : BodyWriter { protected StreamBodyWriter(bool isBuffered) : base(isBuffered) { } internal static StreamBodyWriter CreateStreamBodyWriter(ActionstreamAction) { if (streamAction == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("actionOfStream"); } return new ActionOfStreamBodyWriter(streamAction); } protected abstract void OnWriteBodyContents(Stream stream); protected override BodyWriter OnCreateBufferedCopy(int maxBufferSize) { using (BufferManagerOutputStream bufferedStream = new BufferManagerOutputStream(SR2.MaxReceivedMessageSizeExceeded, maxBufferSize)) { this.OnWriteBodyContents(bufferedStream); int size; byte[] bytesArray = bufferedStream.ToArray(out size); return new BufferedBytesStreamBodyWriter(bytesArray, size); } } protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { using (XmlWriterBackedStream stream = new XmlWriterBackedStream(writer)) { OnWriteBodyContents(stream); } } class XmlWriterBackedStream : Stream { XmlWriter writer; public XmlWriterBackedStream(XmlWriter writer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } this.writer = writer; } public override bool CanRead { get { return false; } } public override bool CanSeek { get { return false; } } public override bool CanWrite { get { return true; } } public override void Flush() { this.writer.Flush(); } public override long Length { get { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamPropertyGetNotSupported, "Length"))); } } public override long Position { get { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamPropertyGetNotSupported, "Position"))); } set { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamPropertySetNotSupported, "Position"))); } } public override int Read(byte[] buffer, int offset, int count) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "Read"))); } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "BeginRead"))); } public override int EndRead(IAsyncResult asyncResult) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "EndRead"))); } public override int ReadByte() { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "ReadByte"))); } public override long Seek(long offset, SeekOrigin origin) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "Seek"))); } public override void SetLength(long value) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "SetLength"))); } public override void Write(byte[] buffer, int offset, int count) { this.writer.WriteBase64(buffer, offset, count); } } class BufferedBytesStreamBodyWriter : StreamBodyWriter { byte[] array; int size; public BufferedBytesStreamBodyWriter(byte[] array, int size) : base(true) { this.array = array; this.size = size; } protected override void OnWriteBodyContents(Stream stream) { stream.Write(this.array, 0, this.size); } } class ActionOfStreamBodyWriter : StreamBodyWriter { Action actionOfStream; public ActionOfStreamBodyWriter(Action actionOfStream) : base(false) { this.actionOfStream = actionOfStream; } protected override void OnWriteBodyContents(Stream stream) { actionOfStream(stream); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PagedDataSource.cs
- Normalization.cs
- CTreeGenerator.cs
- TypefaceMetricsCache.cs
- CodeObjectCreateExpression.cs
- WebPartCatalogCloseVerb.cs
- XamlSerializationHelper.cs
- MbpInfo.cs
- StyleHelper.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- QuerySetOp.cs
- UInt64.cs
- DataSourceConverter.cs
- FormViewDeletedEventArgs.cs
- TwoPhaseCommit.cs
- HwndStylusInputProvider.cs
- ToolStripContainer.cs
- TabItem.cs
- mactripleDES.cs
- ContentDisposition.cs
- MatrixStack.cs
- DisableDpiAwarenessAttribute.cs
- FontWeight.cs
- CustomSignedXml.cs
- CurrentChangingEventManager.cs
- TypedElement.cs
- BufferModeSettings.cs
- CodeDomLocalizationProvider.cs
- CodeSubDirectoriesCollection.cs
- EventLogInformation.cs
- ActivityWithResultConverter.cs
- X509ServiceCertificateAuthenticationElement.cs
- DefaultTextStoreTextComposition.cs
- WpfWebRequestHelper.cs
- ProfileSettingsCollection.cs
- TableRowGroupCollection.cs
- FtpWebRequest.cs
- WebBrowserUriTypeConverter.cs
- MergablePropertyAttribute.cs
- MessageSecurityOverMsmqElement.cs
- AVElementHelper.cs
- DocobjHost.cs
- AnnotationMap.cs
- XmlSchemaExporter.cs
- ProtocolViolationException.cs
- DtrList.cs
- CommandEventArgs.cs
- SatelliteContractVersionAttribute.cs
- CustomActivityDesigner.cs
- FacetDescriptionElement.cs
- newinstructionaction.cs
- AnnouncementEndpoint.cs
- TextTrailingWordEllipsis.cs
- InputReport.cs
- RoleManagerModule.cs
- ChannelManager.cs
- DeclaredTypeValidatorAttribute.cs
- WindowsTokenRoleProvider.cs
- StructuredProperty.cs
- AudioFormatConverter.cs
- DecoderExceptionFallback.cs
- HMACSHA256.cs
- ValuePattern.cs
- AppDomainUnloadedException.cs
- ReaderContextStackData.cs
- EncryptedKeyIdentifierClause.cs
- ProcessModule.cs
- SqlWebEventProvider.cs
- EventManager.cs
- Drawing.cs
- MetadataCache.cs
- FilteredAttributeCollection.cs
- RawStylusInputReport.cs
- ProcessInfo.cs
- DataGridViewCellMouseEventArgs.cs
- GridLength.cs
- Size.cs
- UdpDiscoveryEndpointElement.cs
- EndpointConfigContainer.cs
- TypeInformation.cs
- VariableValue.cs
- QueryRewriter.cs
- FixedSOMPage.cs
- FixedTextSelectionProcessor.cs
- Classification.cs
- EditorPartChrome.cs
- SafeViewOfFileHandle.cs
- ParallelRangeManager.cs
- DataBoundControl.cs
- WebPartsSection.cs
- ConstructorNeedsTagAttribute.cs
- ItemCheckEvent.cs
- PropertyPath.cs
- Documentation.cs
- Panel.cs
- Page.cs
- RemotingConfiguration.cs
- FilteredXmlReader.cs
- SimpleExpression.cs
- ObjectListSelectEventArgs.cs