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
- Vector.cs
- DynamicExpression.cs
- ImageMetadata.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- MultipleViewProviderWrapper.cs
- ExtractCollection.cs
- OperatingSystem.cs
- GeneralTransform.cs
- OleAutBinder.cs
- CallbackHandler.cs
- ApplicationActivator.cs
- HttpHandlersSection.cs
- FormsAuthentication.cs
- PreviewPageInfo.cs
- BasicHttpMessageCredentialType.cs
- HttpRequestCacheValidator.cs
- DataSourceExpressionCollection.cs
- SHA512.cs
- MergePropertyDescriptor.cs
- ZipIOExtraFieldZip64Element.cs
- TextFormatterContext.cs
- LineGeometry.cs
- ScalarType.cs
- CqlGenerator.cs
- ErrorsHelper.cs
- DragStartedEventArgs.cs
- FlowDocumentPageViewerAutomationPeer.cs
- CollectionViewGroup.cs
- AspNetCompatibilityRequirementsAttribute.cs
- DesignColumn.cs
- DataGridTextBoxColumn.cs
- Point3DKeyFrameCollection.cs
- SingleKeyFrameCollection.cs
- FormViewInsertEventArgs.cs
- SqlConnectionHelper.cs
- HScrollProperties.cs
- Positioning.cs
- CodeObjectCreateExpression.cs
- GeometryGroup.cs
- ShutDownListener.cs
- ModelPropertyImpl.cs
- ChtmlCommandAdapter.cs
- OdbcConnection.cs
- DocumentOrderComparer.cs
- TraceSection.cs
- BidPrivateBase.cs
- GridViewColumnHeader.cs
- DeploymentSection.cs
- WeakReferenceList.cs
- TableCell.cs
- XmlWrappingWriter.cs
- ButtonColumn.cs
- ContextDataSourceContextData.cs
- ApplicationCommands.cs
- BufferedReadStream.cs
- WindowVisualStateTracker.cs
- Image.cs
- DBDataPermission.cs
- TripleDES.cs
- TreeNodeConverter.cs
- CodeDomDecompiler.cs
- WindowsSlider.cs
- FileClassifier.cs
- ScriptDescriptor.cs
- TextTreeUndo.cs
- ContentValidator.cs
- AtomMaterializerLog.cs
- MailAddressCollection.cs
- EventBuilder.cs
- JsonReader.cs
- RegexCompilationInfo.cs
- CompilerError.cs
- UnsafeNativeMethods.cs
- Point3DCollection.cs
- AbsoluteQuery.cs
- DataObjectMethodAttribute.cs
- LambdaCompiler.ControlFlow.cs
- CommandID.cs
- PublisherMembershipCondition.cs
- ScrollChrome.cs
- WebPartChrome.cs
- CodeMemberProperty.cs
- WebPartVerbsEventArgs.cs
- Pair.cs
- TreeViewCancelEvent.cs
- WebServiceClientProxyGenerator.cs
- ResourceDescriptionAttribute.cs
- SecurityPermission.cs
- XmlAttributeAttribute.cs
- XmlCDATASection.cs
- BamlLocalizer.cs
- StylusButton.cs
- ManagementQuery.cs
- ButtonChrome.cs
- ScrollableControl.cs
- RawMouseInputReport.cs
- WebPartConnectVerb.cs
- Soap.cs
- XPathScanner.cs
- NoneExcludedImageIndexConverter.cs