Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Channels / HttpStreamXmlDictionaryReader.cs / 1305376 / HttpStreamXmlDictionaryReader.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.IO;
using System.Runtime;
using System.ServiceModel.Syndication;
using System.Xml;
class HttpStreamXmlDictionaryReader : XmlDictionaryReader
{
const int InitialBufferSize = 1024;
string base64StringValue;
bool isStreamClosed;
NameTable nameTable;
StreamPosition position;
XmlDictionaryReaderQuotas quotas;
bool readBase64AsString;
Stream stream;
public HttpStreamXmlDictionaryReader(Stream stream, XmlDictionaryReaderQuotas quotas) : base()
{
if (stream == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream");
}
this.stream = stream;
this.position = StreamPosition.None;
if (quotas == null)
{
quotas = XmlDictionaryReaderQuotas.Max;
}
this.quotas = quotas;
}
enum StreamPosition
{
None,
StartElement,
Stream,
EndElement,
EOF
}
public override int AttributeCount
{
get { return 0; }
}
public override string BaseURI
{
get { return string.Empty; }
}
public override bool CanCanonicalize
{
get
{
return false;
}
}
public override bool CanReadBinaryContent
{
get
{
return true;
}
}
public override bool CanReadValueChunk
{
get
{
return false;
}
}
public override bool CanResolveEntity
{
get
{
return false;
}
}
public override int Depth
{
get { return (this.position == StreamPosition.Stream) ? 1 : 0; }
}
public override bool EOF
{
get { return (this.position == StreamPosition.EOF); }
}
public override bool HasAttributes
{
get
{
return false;
}
}
public override bool HasValue
{
get { return (this.position == StreamPosition.Stream); }
}
public override bool IsDefault
{
get
{
return false;
}
}
public override bool IsEmptyElement
{
get { return false; }
}
public override string LocalName
{
get { return (this.position == StreamPosition.StartElement) ? HttpStreamMessage.StreamElementName : null; }
}
public override string NamespaceURI
{
get { return string.Empty; }
}
public override XmlNameTable NameTable
{
get
{
if (this.nameTable == null)
{
this.nameTable = new NameTable();
this.nameTable.Add(HttpStreamMessage.StreamElementName);
}
return this.nameTable;
}
}
public override XmlNodeType NodeType
{
get
{
switch (position)
{
case StreamPosition.StartElement:
return XmlNodeType.Element;
case StreamPosition.Stream:
return XmlNodeType.Text;
case StreamPosition.EndElement:
return XmlNodeType.EndElement;
case StreamPosition.EOF:
return XmlNodeType.None;
default:
return XmlNodeType.None;
}
}
}
public override string Prefix
{
get
{
return string.Empty;
}
}
public override XmlDictionaryReaderQuotas Quotas
{
get
{
return this.quotas;
}
}
public override ReadState ReadState
{
get
{
switch (this.position)
{
case StreamPosition.None:
return ReadState.Initial;
case StreamPosition.StartElement:
case StreamPosition.Stream:
case StreamPosition.EndElement:
return ReadState.Interactive;
case StreamPosition.EOF:
return ReadState.Closed;
default:
Fx.Assert("This should never get hit");
return ReadState.Error;
}
}
}
public override string Value
{
get
{
switch (this.position)
{
case StreamPosition.Stream:
return GetStreamAsBase64String();
default:
return string.Empty;
}
}
}
public override void Close()
{
if (!this.isStreamClosed)
{
try
{
this.stream.Close();
}
finally
{
this.position = StreamPosition.EOF;
this.isStreamClosed = true;
}
}
}
public override string GetAttribute(int i)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("i"));
}
public override string GetAttribute(string name, string namespaceURI)
{
return null;
}
public override string GetAttribute(string name)
{
return null;
}
public override string LookupNamespace(string prefix)
{
if (prefix == string.Empty)
{
return string.Empty;
}
else if (prefix == "xml")
{
return Atom10FeedFormatter.XmlNs;
}
else if (prefix == "xmlns")
{
return Atom10FeedFormatter.XmlNsNs;
}
else
{
return null;
}
}
public override bool MoveToAttribute(string name, string ns)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR2.GetString(SR2.CannotMoveToAttribute2, name, ns)));
}
public override bool MoveToAttribute(string name)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR2.GetString(SR2.CannotMoveToAttribute1, name)));
}
public override bool MoveToElement()
{
if (this.position == StreamPosition.None)
{
this.position = StreamPosition.StartElement;
return true;
}
return false;
}
public override bool MoveToFirstAttribute()
{
return false;
}
public override bool MoveToNextAttribute()
{
return false;
}
public override bool Read()
{
switch (this.position)
{
case StreamPosition.None:
position = StreamPosition.StartElement;
return true;
case StreamPosition.StartElement:
position = StreamPosition.Stream;
return true;
case StreamPosition.Stream:
position = StreamPosition.EndElement;
return true;
case StreamPosition.EndElement:
position = StreamPosition.EOF;
return false;
case StreamPosition.EOF:
return false;
default:
Fx.Assert("This should never get hit");
return false;
}
}
public override bool ReadAttributeValue()
{
return false;
}
public override int ReadContentAsBase64(byte[] buffer, int index, int count)
{
if (buffer == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("buffer");
}
if (index < 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("index"));
}
if (count < 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count"));
}
EnsureInStream();
int numBytesRead = stream.Read(buffer, index, count);
if (numBytesRead == 0)
{
this.position = StreamPosition.EndElement;
}
return numBytesRead;
}
public override int ReadContentAsBinHex(byte[] buffer, int index, int count)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void ResolveEntity()
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
void EnsureInStream()
{
if (this.position != StreamPosition.Stream)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR2.GetString(SR2.ReaderNotPositionedAtByteStream)));
}
}
string GetStreamAsBase64String()
{
if (!this.readBase64AsString)
{
this.base64StringValue = Convert.ToBase64String(ReadContentAsBase64());
this.readBase64AsString = true;
}
return this.base64StringValue;
}
}
}
// 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
- altserialization.cs
- XsltContext.cs
- XmlSchemaObject.cs
- NameScopePropertyAttribute.cs
- SqlRemoveConstantOrderBy.cs
- ItemsPanelTemplate.cs
- TokenBasedSetEnumerator.cs
- AssemblyNameProxy.cs
- ObjectMaterializedEventArgs.cs
- Main.cs
- StaticSiteMapProvider.cs
- CapabilitiesPattern.cs
- APCustomTypeDescriptor.cs
- TemplateComponentConnector.cs
- DataTableNewRowEvent.cs
- LoginView.cs
- QilSortKey.cs
- ReservationCollection.cs
- WebControlsSection.cs
- TargetInvocationException.cs
- QueueSurrogate.cs
- PreloadedPackages.cs
- selecteditemcollection.cs
- HTTPNotFoundHandler.cs
- _RequestCacheProtocol.cs
- EditorZoneBase.cs
- DataGridCellsPresenter.cs
- DynamicControlParameter.cs
- PropertyMapper.cs
- EDesignUtil.cs
- URL.cs
- SafeMarshalContext.cs
- DescendantOverDescendantQuery.cs
- securitycriticaldata.cs
- DateTimeOffsetConverter.cs
- TextTreeRootTextBlock.cs
- CodeCommentStatementCollection.cs
- LayoutUtils.cs
- CursorConverter.cs
- CharacterMetricsDictionary.cs
- Component.cs
- ImportCatalogPart.cs
- Point3DConverter.cs
- ToolStripSplitStackLayout.cs
- SchemaEntity.cs
- RelatedCurrencyManager.cs
- ApplyImportsAction.cs
- ScriptControlDescriptor.cs
- ConnectionPointGlyph.cs
- XmlEnumAttribute.cs
- DataRelation.cs
- GlobalDataBindingHandler.cs
- IndexOutOfRangeException.cs
- Debug.cs
- MemoryPressure.cs
- StructuralObject.cs
- XmlNavigatorStack.cs
- TimeSpanParse.cs
- Composition.cs
- DataGridCellItemAutomationPeer.cs
- SecUtil.cs
- RepeaterItemEventArgs.cs
- SocketAddress.cs
- Endpoint.cs
- MailWebEventProvider.cs
- SqlGatherConsumedAliases.cs
- ExceptionList.cs
- LoadRetryStrategyFactory.cs
- DecoratedNameAttribute.cs
- XmlSchemaCompilationSettings.cs
- DataGridViewRowsRemovedEventArgs.cs
- IgnoreSectionHandler.cs
- Tokenizer.cs
- HostingEnvironment.cs
- Substitution.cs
- SynchronizedDispatch.cs
- RangeValuePattern.cs
- CollectionChangeEventArgs.cs
- ContractInstanceProvider.cs
- _Connection.cs
- QilScopedVisitor.cs
- HwndHostAutomationPeer.cs
- EdmFunctions.cs
- mediaeventargs.cs
- ImageBrush.cs
- Emitter.cs
- ExpressionBuilderCollection.cs
- GcSettings.cs
- AdRotatorDesigner.cs
- XmlCharCheckingWriter.cs
- SkinIDTypeConverter.cs
- HtmlControl.cs
- EnumValAlphaComparer.cs
- DataObjectSettingDataEventArgs.cs
- DrawingContext.cs
- ISAPIRuntime.cs
- GroupLabel.cs
- DetailsViewRow.cs
- TemplateControlCodeDomTreeGenerator.cs
- Aggregates.cs