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
- CheckPair.cs
- DocumentXmlWriter.cs
- InvariantComparer.cs
- DescendentsWalkerBase.cs
- HitTestResult.cs
- COM2ComponentEditor.cs
- TemplateParser.cs
- Encoder.cs
- ToolboxItemSnapLineBehavior.cs
- Transform3D.cs
- odbcmetadatacollectionnames.cs
- WmfPlaceableFileHeader.cs
- DefaultProxySection.cs
- DataGridItemAttachedStorage.cs
- GridItemPattern.cs
- Timeline.cs
- MarginsConverter.cs
- SessionStateModule.cs
- FacetValueContainer.cs
- RegexBoyerMoore.cs
- SecureConversationServiceCredential.cs
- DirectionalAction.cs
- CloudCollection.cs
- CorePropertiesFilter.cs
- Binding.cs
- PersistenceProviderFactory.cs
- CodeDomLocalizationProvider.cs
- ObjectSet.cs
- GeometryHitTestParameters.cs
- DataGridViewRowStateChangedEventArgs.cs
- oledbmetadatacollectionnames.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- PerformanceCountersElement.cs
- TreeView.cs
- OracleBoolean.cs
- DataGridViewTopRowAccessibleObject.cs
- ObjectItemAttributeAssemblyLoader.cs
- ClientCultureInfo.cs
- LayoutUtils.cs
- MsmqChannelFactoryBase.cs
- InputProcessorProfilesLoader.cs
- SQLBoolean.cs
- RichTextBox.cs
- ProcessHost.cs
- Processor.cs
- Pair.cs
- BatchServiceHost.cs
- XamlHostingSection.cs
- EasingFunctionBase.cs
- WebEventTraceProvider.cs
- BitmapCache.cs
- PermissionSetEnumerator.cs
- Byte.cs
- FrameworkTextComposition.cs
- EntityDataSourceConfigureObjectContext.cs
- PropertyDescriptorGridEntry.cs
- QilExpression.cs
- BulletDecorator.cs
- CodeSnippetCompileUnit.cs
- RequestTimeoutManager.cs
- XmlDataCollection.cs
- GlobalizationSection.cs
- ObjectTypeMapping.cs
- UnsafeNativeMethods.cs
- AttributeProviderAttribute.cs
- RepeatInfo.cs
- PrefixQName.cs
- Splitter.cs
- ResourceExpressionEditorSheet.cs
- RefreshEventArgs.cs
- DesignTimeVisibleAttribute.cs
- StreamUpdate.cs
- WorkflowViewStateService.cs
- EmbeddedMailObject.cs
- COSERVERINFO.cs
- LogicalExpr.cs
- ThreadNeutralSemaphore.cs
- TraceContextEventArgs.cs
- RegistryConfigurationProvider.cs
- DbConnectionPoolGroupProviderInfo.cs
- XsltLoader.cs
- path.cs
- CapacityStreamGeometryContext.cs
- DeploymentSection.cs
- SafeTimerHandle.cs
- RowToParametersTransformer.cs
- FontStyleConverter.cs
- UnsafeNativeMethods.cs
- ControlPaint.cs
- HttpModulesSection.cs
- _SafeNetHandles.cs
- TableLayoutPanelCodeDomSerializer.cs
- StyleSelector.cs
- ColumnBinding.cs
- HttpCookie.cs
- ImmutableCommunicationTimeouts.cs
- TextRangeEdit.cs
- XamlReaderHelper.cs
- InfiniteIntConverter.cs
- CacheChildrenQuery.cs