Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Server / System / Data / Services / Serializers / AtomServiceDocumentSerializer.cs / 1305376 / 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.Data.Services.Providers;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
///
/// 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,
DataServiceProviderWrapper provider,
Encoding encoding)
: base(output, baseUri, provider, encoding)
{
}
/// Writes the Service Document to the output stream.
/// Data service instance.
internal override void WriteRequest(IDataService service)
{
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 (ResourceSetWrapper container in this.Provider.ResourceSets)
{
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.Data.Services.Providers;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
///
/// 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,
DataServiceProviderWrapper provider,
Encoding encoding)
: base(output, baseUri, provider, encoding)
{
}
/// Writes the Service Document to the output stream.
/// Data service instance.
internal override void WriteRequest(IDataService service)
{
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 (ResourceSetWrapper container in this.Provider.ResourceSets)
{
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
- ReferentialConstraint.cs
- DependencyPropertyDescriptor.cs
- Transform.cs
- Base64Stream.cs
- ProfileGroupSettings.cs
- assertwrapper.cs
- PrePrepareMethodAttribute.cs
- FormsAuthenticationUserCollection.cs
- FileInfo.cs
- ObjectHelper.cs
- PersonalizableTypeEntry.cs
- X509Certificate2.cs
- GetMemberBinder.cs
- DefaultShape.cs
- DataGridHeaderBorder.cs
- ParseElement.cs
- QuaternionAnimationUsingKeyFrames.cs
- TraceContextRecord.cs
- WindowsTreeView.cs
- SelectionRangeConverter.cs
- DefaultTextStoreTextComposition.cs
- DataRow.cs
- SqlFunctionAttribute.cs
- StoreContentChangedEventArgs.cs
- XamlStyleSerializer.cs
- MatrixTransform3D.cs
- Block.cs
- DataServiceRequestOfT.cs
- RedBlackList.cs
- NetNamedPipeBindingElement.cs
- TimelineClockCollection.cs
- ReflectionServiceProvider.cs
- DataShape.cs
- ReachFixedPageSerializer.cs
- CodeMemberMethod.cs
- DatatypeImplementation.cs
- TableItemPatternIdentifiers.cs
- ImageSource.cs
- MissingSatelliteAssemblyException.cs
- TypeSystemProvider.cs
- Resources.Designer.cs
- DefaultBinder.cs
- Rights.cs
- ContextCorrelationInitializer.cs
- SqlStream.cs
- dbdatarecord.cs
- HuffmanTree.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- ListSortDescriptionCollection.cs
- FatalException.cs
- XmlDictionaryReader.cs
- EncodingInfo.cs
- SrgsRule.cs
- RSAPKCS1KeyExchangeFormatter.cs
- SoundPlayerAction.cs
- XmlSchemaImport.cs
- TextServicesPropertyRanges.cs
- ValidationUtility.cs
- UIntPtr.cs
- Currency.cs
- WebHostUnsafeNativeMethods.cs
- TriggerActionCollection.cs
- SystemIcmpV4Statistics.cs
- linebase.cs
- XPathDocumentNavigator.cs
- AuthenticationModulesSection.cs
- ListenDesigner.cs
- ProviderException.cs
- InstalledFontCollection.cs
- PenThreadPool.cs
- Baml2006SchemaContext.cs
- ItemsChangedEventArgs.cs
- CompilerTypeWithParams.cs
- ImageFormat.cs
- tooltip.cs
- UriExt.cs
- StyleTypedPropertyAttribute.cs
- CustomAttributeBuilder.cs
- DesignTimeParseData.cs
- PerformanceCountersElement.cs
- Stylesheet.cs
- WindowsAuthenticationEventArgs.cs
- ListViewGroupItemCollection.cs
- SQLMoneyStorage.cs
- ToolStripItem.cs
- Throw.cs
- Animatable.cs
- AsyncPostBackErrorEventArgs.cs
- PropertyGridEditorPart.cs
- BinaryWriter.cs
- LateBoundBitmapDecoder.cs
- XsltContext.cs
- WebException.cs
- DispatcherHookEventArgs.cs
- NativeMethods.cs
- DebugController.cs
- Tokenizer.cs
- TextRangeSerialization.cs
- Array.cs
- PageCatalogPart.cs