Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Channels / HttpStreamXmlDictionaryWriter.cs / 1 / HttpStreamXmlDictionaryWriter.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Channels
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Net;
using System.Xml;
using System.Text;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Syndication;
class HttpStreamXmlDictionaryWriter : XmlDictionaryWriter
{
WriteState state;
Stream stream;
public HttpStreamXmlDictionaryWriter(Stream stream)
{
if (stream == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream");
}
this.stream = stream;
this.state = WriteState.Start;
}
public override WriteState WriteState
{
get { return this.state; }
}
public override void Close()
{
if (this.state != WriteState.Closed)
{
this.state = WriteState.Closed;
stream.Close();
}
}
public override void Flush()
{
stream.Flush();
}
public override string LookupPrefix(string ns)
{
if (ns == string.Empty)
{
return string.Empty;
}
else if (ns == Atom10FeedFormatter.XmlNs)
{
return "xml";
}
else if (ns == Atom10FeedFormatter.XmlNsNs)
{
return "xmlns";
}
else
{
return null;
}
}
public override void WriteBase64(byte[] buffer, int index, int count)
{
if (buffer == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("buffer"));
}
if (index < 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("index"));
}
if (count < 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count"));
}
if (count > buffer.Length - index)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("count", SR2.GetString(SR2.SizeExceedsRemainingBufferSpace, buffer.Length - index)));
}
ThrowIfClosed();
this.stream.Write(buffer, index, count);
this.state = WriteState.Content;
}
public override void WriteCData(string text)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteCharEntity(char ch)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteChars(char[] buffer, int index, int count)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteComment(string text)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteDocType(string name, string pubid, string sysid, string subset)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteEndAttribute()
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteEndDocument()
{
}
public override void WriteEndElement()
{
ThrowIfClosed();
if (this.state != WriteState.Element && this.state != WriteState.Content)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR2.GetString(SR2.EndElementWithoutStartElement)));
}
}
public override void WriteEntityRef(string name)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteFullEndElement()
{
ThrowIfClosed();
if (this.state != WriteState.Element && this.state != WriteState.Content)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR2.GetString(SR2.EndElementWithoutStartElement)));
}
}
public override void WriteProcessingInstruction(string name, string text)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteRaw(string data)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteRaw(char[] buffer, int index, int count)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteStartAttribute(string prefix, string localName, string ns)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteStartDocument(bool standalone)
{
ThrowIfClosed();
}
public override void WriteStartDocument()
{
ThrowIfClosed();
}
public override void WriteStartElement(string prefix, string localName, string ns)
{
ThrowIfClosed();
if (!string.IsNullOrEmpty(prefix) || !string.IsNullOrEmpty(ns) || localName != HttpStreamMessage.StreamElementName)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
this.state = WriteState.Element;
}
public override void WriteString(string text)
{
byte[] buffer = Convert.FromBase64String(text);
WriteBase64(buffer, 0, buffer.Length);
}
public override void WriteSurrogateCharEntity(char lowChar, char highChar)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
public override void WriteWhitespace(string ws)
{
if (ws == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("ws");
}
if (ws.Length != 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
}
protected void ThrowIfClosed()
{
if (this.state == WriteState.Closed)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.XmlWriterClosed)));
}
}
}
}
// 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
- SequenceDesigner.cs
- RangeValidator.cs
- EventTrigger.cs
- PropertyKey.cs
- LineServicesCallbacks.cs
- FunctionParameter.cs
- PlainXmlDeserializer.cs
- RuntimeResourceSet.cs
- DataGridViewSortCompareEventArgs.cs
- SpotLight.cs
- ResourceIDHelper.cs
- PointKeyFrameCollection.cs
- SystemSounds.cs
- UndoManager.cs
- DefaultValueAttribute.cs
- TableCellCollection.cs
- MaskedTextProvider.cs
- AnchoredBlock.cs
- MemberHolder.cs
- StyleBamlTreeBuilder.cs
- CellRelation.cs
- XPathPatternParser.cs
- LocalizedNameDescriptionPair.cs
- KeyToListMap.cs
- PagesSection.cs
- PostBackTrigger.cs
- EnumBuilder.cs
- pingexception.cs
- Ipv6Element.cs
- PersonalizationStateInfoCollection.cs
- RowVisual.cs
- XmlWriter.cs
- EditorZone.cs
- PointLightBase.cs
- WebServiceEnumData.cs
- CodeTryCatchFinallyStatement.cs
- FloaterBaseParagraph.cs
- InterleavedZipPartStream.cs
- XmlSchemaAnyAttribute.cs
- PrintDialogException.cs
- AddInPipelineAttributes.cs
- Assembly.cs
- cookiecollection.cs
- ServerProtocol.cs
- ComponentCommands.cs
- DropTarget.cs
- X509Extension.cs
- GeometryDrawing.cs
- TextSpan.cs
- SmiContext.cs
- SqlProcedureAttribute.cs
- ColumnBinding.cs
- ServiceCredentialsElement.cs
- DateTimeSerializationSection.cs
- UrlEncodedParameterWriter.cs
- recordstate.cs
- Trigger.cs
- FixedTextPointer.cs
- DocumentXmlWriter.cs
- Int64Converter.cs
- NamedPermissionSet.cs
- EndpointDesigner.cs
- XmlEncodedRawTextWriter.cs
- BlockingCollection.cs
- DataReceivedEventArgs.cs
- ContractHandle.cs
- NameService.cs
- SourceChangedEventArgs.cs
- SimpleTextLine.cs
- ViewPort3D.cs
- EdmComplexPropertyAttribute.cs
- FileDialog.cs
- GenerateScriptTypeAttribute.cs
- KeyboardNavigation.cs
- TextEditorCharacters.cs
- CryptoApi.cs
- FamilyCollection.cs
- OdbcStatementHandle.cs
- PartialCachingAttribute.cs
- ItemCheckedEvent.cs
- AsymmetricKeyExchangeFormatter.cs
- ConfigurationValues.cs
- EntityDataSourceWrapperCollection.cs
- TokenFactoryCredential.cs
- HtmlInputFile.cs
- ProviderBase.cs
- SmtpException.cs
- IdentityReference.cs
- HMACMD5.cs
- SerializableTypeCodeDomSerializer.cs
- TextWriterTraceListener.cs
- CompositeControl.cs
- KeyInterop.cs
- KeyboardNavigation.cs
- InstanceNameConverter.cs
- Library.cs
- StateManagedCollection.cs
- glyphs.cs
- LeaseManager.cs
- TraceInternal.cs