Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / XmlBuffer.cs / 1 / XmlBuffer.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- #define BINARY namespace System.ServiceModel { using System.IO; using System.Xml; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.ServiceModel.Channels; class XmlBuffer { Listsections; byte[] buffer; int offset; BufferedOutputStream stream; BufferState bufferState; XmlDictionaryWriter writer; XmlDictionaryReaderQuotas quotas; enum BufferState { Created, Writing, Reading, } struct Section { int offset; int size; XmlDictionaryReaderQuotas quotas; public Section(int offset, int size, XmlDictionaryReaderQuotas quotas) { this.offset = offset; this.size = size; this.quotas = quotas; } public int Offset { get { return this.offset; } } public int Size { get { return this.size; } } public XmlDictionaryReaderQuotas Quotas { get { return this.quotas; } } } public XmlBuffer(int maxBufferSize) { if (maxBufferSize < 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("maxBufferSize", maxBufferSize, SR.GetString(SR.ValueMustBeNonNegative))); int initialBufferSize = Math.Min(512, maxBufferSize); stream = new BufferedOutputStream(SR.XmlBufferQuotaExceeded, initialBufferSize, maxBufferSize, BufferManager.CreateBufferManager(0, int.MaxValue)); sections = new List (1); } public int BufferSize { get { DiagnosticUtility.DebugAssert(bufferState == BufferState.Reading, "Buffer size shuold only be retrieved during Reading state"); return buffer.Length; } } public int SectionCount { get { return this.sections.Count; } } public XmlDictionaryWriter OpenSection(XmlDictionaryReaderQuotas quotas) { if (bufferState != BufferState.Created) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidStateException()); bufferState = BufferState.Writing; this.quotas = new XmlDictionaryReaderQuotas(); quotas.CopyTo(this.quotas); if (this.writer == null) { this.writer = XmlDictionaryWriter.CreateBinaryWriter(stream, XD.Dictionary, null, true); } else { ((IXmlBinaryWriterInitializer)this.writer).SetOutput(stream, XD.Dictionary, null, true); } return this.writer; } public void CloseSection() { if (bufferState != BufferState.Writing) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidStateException()); this.writer.Close(); bufferState = BufferState.Created; int size = (int)stream.Length - offset; sections.Add(new Section(offset, size, this.quotas)); offset += size; } public void Close() { if (bufferState != BufferState.Created) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidStateException()); bufferState = BufferState.Reading; int bufferSize; buffer = stream.ToArray(out bufferSize); writer = null; stream = null; } Exception CreateInvalidStateException() { return new InvalidOperationException(SR.GetString(SR.XmlBufferInInvalidState)); } public XmlDictionaryReader GetReader(int sectionIndex) { if (bufferState != BufferState.Reading) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidStateException()); Section section = sections[sectionIndex]; XmlDictionaryReader reader = XmlDictionaryReader.CreateBinaryReader(buffer, section.Offset, section.Size, XD.Dictionary, section.Quotas, null, null); reader.MoveToContent(); return reader; } public void WriteTo(int sectionIndex, XmlWriter writer) { if (bufferState != BufferState.Reading) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateInvalidStateException()); XmlDictionaryReader reader = GetReader(sectionIndex); try { writer.WriteNode(reader, false); } finally { reader.Close(); } } } } // 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
- ResourceReferenceExpression.cs
- UnmanagedMemoryStream.cs
- ColumnMapVisitor.cs
- ShaderEffect.cs
- AutoGeneratedFieldProperties.cs
- CurrencyWrapper.cs
- DataGridCheckBoxColumn.cs
- OciHandle.cs
- HttpRawResponse.cs
- ServicesUtilities.cs
- HtmlHistory.cs
- XmlWrappingReader.cs
- Parser.cs
- AutoGeneratedField.cs
- AsyncPostBackErrorEventArgs.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- MetadataItemEmitter.cs
- LogArchiveSnapshot.cs
- Visual3DCollection.cs
- SvcMapFileLoader.cs
- BitmapEffectDrawingContextState.cs
- GACIdentityPermission.cs
- Site.cs
- InkPresenterAutomationPeer.cs
- EmptyImpersonationContext.cs
- GenericFlowSwitchHelper.cs
- PrimitiveSchema.cs
- ToolStripManager.cs
- PropertyManager.cs
- XPathNodeHelper.cs
- BevelBitmapEffect.cs
- MetadataArtifactLoaderCompositeResource.cs
- TypeBuilderInstantiation.cs
- TextRunCacheImp.cs
- WhitespaceRuleReader.cs
- ColumnMap.cs
- ConnectionStringSettings.cs
- RecognizerInfo.cs
- ObsoleteAttribute.cs
- XmlWhitespace.cs
- ValidationResult.cs
- HttpCachePolicyBase.cs
- TypeHelpers.cs
- ListDataHelper.cs
- AutoScrollHelper.cs
- UmAlQuraCalendar.cs
- ToolTipService.cs
- Menu.cs
- JoinElimination.cs
- DesignerTransaction.cs
- CodeDomLocalizationProvider.cs
- TypeHelpers.cs
- InvalidOleVariantTypeException.cs
- OdbcDataReader.cs
- WindowsListViewItemStartMenu.cs
- ExpandCollapsePattern.cs
- DataControlPagerLinkButton.cs
- AssemblyCollection.cs
- TimeSpanSecondsConverter.cs
- XmlSchemaAttributeGroup.cs
- Expander.cs
- RewritingSimplifier.cs
- PartialCachingControl.cs
- CodeLabeledStatement.cs
- StorageInfo.cs
- TimeSpanHelper.cs
- AnchoredBlock.cs
- IndexExpression.cs
- ServiceBuildProvider.cs
- Pointer.cs
- SafeNativeMethodsMilCoreApi.cs
- InfiniteTimeSpanConverter.cs
- PartialCachingControl.cs
- BaseDataBoundControl.cs
- DependencyObjectType.cs
- Scheduler.cs
- AssemblyFilter.cs
- WindowsFormsHelpers.cs
- IDReferencePropertyAttribute.cs
- DataAdapter.cs
- IndexedEnumerable.cs
- ObjectAnimationBase.cs
- TextRangeAdaptor.cs
- WasEndpointConfigContainer.cs
- X500Name.cs
- MethodCallExpression.cs
- MediaEntryAttribute.cs
- Animatable.cs
- RegexWriter.cs
- BamlBinaryReader.cs
- EntityDataSourceDesigner.cs
- EntityViewGenerationAttribute.cs
- UIElementCollection.cs
- PageCatalogPartDesigner.cs
- CommonObjectSecurity.cs
- EnumMemberAttribute.cs
- PointAnimationUsingKeyFrames.cs
- Visual3DCollection.cs
- EUCJPEncoding.cs
- MaxSessionCountExceededException.cs