Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataWeb / Server / System / Data / Services / Serializers / AtomServiceDocumentSerializer.cs / 1 / AtomServiceDocumentSerializer.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Provides a serializer for the Atom Service Document format.
//
//
// @owner [....]
//---------------------------------------------------------------------
namespace System.Data.Services.Serializers
{
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
using System.Data.Services.Providers;
///
/// Provides support for serializing service models as
/// a Service Document.
///
///
/// For more information, see http://tools.ietf.org/html/rfc5023#section-8.
///
[DebuggerDisplay("AtomServiceDocumentSerializer={baseUri}")]
internal sealed class AtomServiceDocumentSerializer : XmlDocumentSerializer
{
/// XML prefix for the Atom Publishing Protocol namespace.
private const string AppNamespacePrefix = "app";
/// XML prefix for the Atom namespace.
private const string AtomNamespacePrefix = "atom";
///
/// Initializes a new AtomServiceDocumentSerializer, ready to write
/// out the Service Document for a data provider.
///
/// Stream to which output should be sent.
/// Base URI from which resources should be resolved.
/// Data provider from which metadata should be gathered.
/// Text encoding for the response.
internal AtomServiceDocumentSerializer(
Stream output,
Uri baseUri,
IDataServiceProvider provider,
Encoding encoding)
: base(output, baseUri, provider, encoding)
{
}
/// Writes the Service Document to the output stream.
internal override void WriteRequest()
{
try
{
this.Writer.WriteStartElement(XmlConstants.AtomPublishingServiceElementName, XmlConstants.AppNamespace);
this.IncludeCommonNamespaces();
this.Writer.WriteStartElement("", XmlConstants.AtomPublishingWorkspaceElementName, XmlConstants.AppNamespace);
this.Writer.WriteStartElement(XmlConstants.AtomTitleElementName, XmlConstants.AtomNamespace);
this.Writer.WriteString(XmlConstants.AtomPublishingWorkspaceDefaultValue);
this.Writer.WriteEndElement();
foreach (ResourceContainer container in this.Provider.GetContainers())
{
this.Writer.WriteStartElement("", XmlConstants.AtomPublishingCollectionElementName, XmlConstants.AppNamespace);
this.Writer.WriteAttributeString(XmlConstants.AtomHRefAttributeName, container.Name);
this.Writer.WriteStartElement(XmlConstants.AtomTitleElementName, XmlConstants.AtomNamespace);
this.Writer.WriteString(container.Name);
this.Writer.WriteEndElement(); // Close 'title' element.
this.Writer.WriteEndElement(); // Close 'collection' element.
}
this.Writer.WriteEndElement(); // Close 'workspace' element.
this.Writer.WriteEndElement(); // Close 'service' element.
}
finally
{
this.Writer.Close();
}
}
/// Ensures that common namespaces are included in the topmost tag.
///
/// This method should be called by any method that may write a
/// topmost element tag.
///
private void IncludeCommonNamespaces()
{
Debug.Assert(
this.Writer.WriteState == WriteState.Element,
"this.writer.WriteState == WriteState.Element - otherwise, not called at beginning - " + this.Writer.WriteState);
this.Writer.WriteAttributeString(XmlConstants.XmlNamespacePrefix, XmlConstants.XmlBaseAttributeName, null, this.BaseUri.AbsoluteUri);
this.Writer.WriteAttributeString(XmlConstants.XmlnsNamespacePrefix, AtomNamespacePrefix, null, XmlConstants.AtomNamespace);
this.Writer.WriteAttributeString(XmlConstants.XmlnsNamespacePrefix, AppNamespacePrefix, null, XmlConstants.AppNamespace);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Provides a serializer for the Atom Service Document format.
//
//
// @owner [....]
//---------------------------------------------------------------------
namespace System.Data.Services.Serializers
{
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
using System.Data.Services.Providers;
///
/// Provides support for serializing service models as
/// a Service Document.
///
///
/// For more information, see http://tools.ietf.org/html/rfc5023#section-8.
///
[DebuggerDisplay("AtomServiceDocumentSerializer={baseUri}")]
internal sealed class AtomServiceDocumentSerializer : XmlDocumentSerializer
{
/// XML prefix for the Atom Publishing Protocol namespace.
private const string AppNamespacePrefix = "app";
/// XML prefix for the Atom namespace.
private const string AtomNamespacePrefix = "atom";
///
/// Initializes a new AtomServiceDocumentSerializer, ready to write
/// out the Service Document for a data provider.
///
/// Stream to which output should be sent.
/// Base URI from which resources should be resolved.
/// Data provider from which metadata should be gathered.
/// Text encoding for the response.
internal AtomServiceDocumentSerializer(
Stream output,
Uri baseUri,
IDataServiceProvider provider,
Encoding encoding)
: base(output, baseUri, provider, encoding)
{
}
/// Writes the Service Document to the output stream.
internal override void WriteRequest()
{
try
{
this.Writer.WriteStartElement(XmlConstants.AtomPublishingServiceElementName, XmlConstants.AppNamespace);
this.IncludeCommonNamespaces();
this.Writer.WriteStartElement("", XmlConstants.AtomPublishingWorkspaceElementName, XmlConstants.AppNamespace);
this.Writer.WriteStartElement(XmlConstants.AtomTitleElementName, XmlConstants.AtomNamespace);
this.Writer.WriteString(XmlConstants.AtomPublishingWorkspaceDefaultValue);
this.Writer.WriteEndElement();
foreach (ResourceContainer container in this.Provider.GetContainers())
{
this.Writer.WriteStartElement("", XmlConstants.AtomPublishingCollectionElementName, XmlConstants.AppNamespace);
this.Writer.WriteAttributeString(XmlConstants.AtomHRefAttributeName, container.Name);
this.Writer.WriteStartElement(XmlConstants.AtomTitleElementName, XmlConstants.AtomNamespace);
this.Writer.WriteString(container.Name);
this.Writer.WriteEndElement(); // Close 'title' element.
this.Writer.WriteEndElement(); // Close 'collection' element.
}
this.Writer.WriteEndElement(); // Close 'workspace' element.
this.Writer.WriteEndElement(); // Close 'service' element.
}
finally
{
this.Writer.Close();
}
}
/// Ensures that common namespaces are included in the topmost tag.
///
/// This method should be called by any method that may write a
/// topmost element tag.
///
private void IncludeCommonNamespaces()
{
Debug.Assert(
this.Writer.WriteState == WriteState.Element,
"this.writer.WriteState == WriteState.Element - otherwise, not called at beginning - " + this.Writer.WriteState);
this.Writer.WriteAttributeString(XmlConstants.XmlNamespacePrefix, XmlConstants.XmlBaseAttributeName, null, this.BaseUri.AbsoluteUri);
this.Writer.WriteAttributeString(XmlConstants.XmlnsNamespacePrefix, AtomNamespacePrefix, null, XmlConstants.AtomNamespace);
this.Writer.WriteAttributeString(XmlConstants.XmlnsNamespacePrefix, AppNamespacePrefix, null, XmlConstants.AppNamespace);
}
}
}
// 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
- ObjectDataSource.cs
- Vector3DAnimationUsingKeyFrames.cs
- WindowProviderWrapper.cs
- TaskCanceledException.cs
- UnsafeNativeMethods.cs
- LoginUtil.cs
- CodeAttributeDeclaration.cs
- XPathLexer.cs
- X509ChainElement.cs
- mactripleDES.cs
- AdRotator.cs
- XMLUtil.cs
- TextEndOfParagraph.cs
- ProfileProvider.cs
- BasicCommandTreeVisitor.cs
- PropertyInfoSet.cs
- HostProtectionPermission.cs
- SchemaConstraints.cs
- WebPartConnectionsConnectVerb.cs
- JsonWriter.cs
- HostingPreferredMapPath.cs
- TextCharacters.cs
- HttpDebugHandler.cs
- CookieParameter.cs
- ToolStripDesignerAvailabilityAttribute.cs
- WmlTextBoxAdapter.cs
- ICollection.cs
- SQLDateTime.cs
- ToolBarButton.cs
- PathTooLongException.cs
- OperatingSystem.cs
- DataBoundControlAdapter.cs
- XmlName.cs
- WarningException.cs
- Expressions.cs
- DbConnectionPoolGroupProviderInfo.cs
- NativeMethods.cs
- GridViewCommandEventArgs.cs
- DataObjectFieldAttribute.cs
- ErrorStyle.cs
- StringUtil.cs
- StorageConditionPropertyMapping.cs
- TreeNodeEventArgs.cs
- ComponentCache.cs
- TypeForwardedToAttribute.cs
- HtmlInputReset.cs
- QilFactory.cs
- EventHandlerList.cs
- OSFeature.cs
- CheckedPointers.cs
- TextStore.cs
- DataTemplateKey.cs
- GridViewRowPresenter.cs
- DataGridAddNewRow.cs
- Workspace.cs
- EllipseGeometry.cs
- DrawListViewItemEventArgs.cs
- Vector3DAnimationUsingKeyFrames.cs
- EntitySet.cs
- PointLight.cs
- HMACRIPEMD160.cs
- AttributeQuery.cs
- GlobalProxySelection.cs
- DbProviderFactory.cs
- Int16Converter.cs
- EntityDataSourceSelectedEventArgs.cs
- SqlTransaction.cs
- CallSiteHelpers.cs
- Clock.cs
- UriTemplateVariableQueryValue.cs
- FlowLayout.cs
- XPathArrayIterator.cs
- StreamBodyWriter.cs
- EventToken.cs
- CalloutQueueItem.cs
- WorkflowWebHostingModule.cs
- ArrangedElementCollection.cs
- ObjectCacheHost.cs
- SoapElementAttribute.cs
- HebrewNumber.cs
- Line.cs
- StylusPointCollection.cs
- TrackingProfile.cs
- ParameterEditorUserControl.cs
- SetIterators.cs
- ReachDocumentSequenceSerializer.cs
- BaseDataListComponentEditor.cs
- InvokeBinder.cs
- DesignerVerb.cs
- HGlobalSafeHandle.cs
- RawStylusInput.cs
- IsolatedStorageFileStream.cs
- ProfileSettings.cs
- FileSystemWatcher.cs
- PerformanceCounterPermissionEntry.cs
- HiddenFieldPageStatePersister.cs
- Thickness.cs
- DesignerUtility.cs
- RoleGroup.cs
- FontStyle.cs