Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- XsdBuilder.cs
- ArithmeticException.cs
- XPathDocumentIterator.cs
- ErasingStroke.cs
- PersonalizableTypeEntry.cs
- Panel.cs
- HttpsChannelFactory.cs
- SatelliteContractVersionAttribute.cs
- SystemParameters.cs
- TextElementAutomationPeer.cs
- Exceptions.cs
- CodeCompileUnit.cs
- InnerItemCollectionView.cs
- WebPartsPersonalizationAuthorization.cs
- TreeSet.cs
- XmlAttributes.cs
- StylusDevice.cs
- StyleHelper.cs
- DataTemplate.cs
- ZipIOExtraField.cs
- OverflowException.cs
- Int32Rect.cs
- DPCustomTypeDescriptor.cs
- X509UI.cs
- ControlBindingsCollection.cs
- Trace.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- Figure.cs
- XappLauncher.cs
- LockedActivityGlyph.cs
- RemotingAttributes.cs
- Function.cs
- ScrollViewerAutomationPeer.cs
- TypeSystemHelpers.cs
- X509CertificateClaimSet.cs
- ProtocolsSection.cs
- SiteMapDataSourceDesigner.cs
- CallbackBehaviorAttribute.cs
- XmlSchemaAppInfo.cs
- SuppressMessageAttribute.cs
- SqlMetaData.cs
- DBProviderConfigurationHandler.cs
- XmlWriterSettings.cs
- VideoDrawing.cs
- Help.cs
- QilFunction.cs
- Mouse.cs
- GridViewCellAutomationPeer.cs
- DecimalMinMaxAggregationOperator.cs
- IndicShape.cs
- EntitySqlQueryCacheEntry.cs
- NameValueConfigurationElement.cs
- WsatConfiguration.cs
- RequestValidator.cs
- ColumnMapProcessor.cs
- ScriptReference.cs
- PropertyDescriptorCollection.cs
- HtmlImage.cs
- DataServiceExpressionVisitor.cs
- regiisutil.cs
- Container.cs
- Freezable.cs
- XNameConverter.cs
- KeyProperty.cs
- RightsManagementEncryptionTransform.cs
- FacetChecker.cs
- DbProviderSpecificTypePropertyAttribute.cs
- KeyedCollection.cs
- MailSettingsSection.cs
- TreeNodeStyle.cs
- DocumentPage.cs
- WebPartCloseVerb.cs
- LocalBuilder.cs
- BrowserCapabilitiesFactoryBase.cs
- SmtpDateTime.cs
- GridItem.cs
- TextBoxAutoCompleteSourceConverter.cs
- QilScopedVisitor.cs
- DefaultEventAttribute.cs
- URLString.cs
- UserControl.cs
- DockingAttribute.cs
- SqlConnection.cs
- MergablePropertyAttribute.cs
- xmlsaver.cs
- DataPagerFieldCollection.cs
- FlagsAttribute.cs
- DefaultMemberAttribute.cs
- WebRequest.cs
- TripleDES.cs
- HelpKeywordAttribute.cs
- GridSplitter.cs
- OrthographicCamera.cs
- TypeLoadException.cs
- DelayedRegex.cs
- EntityDataSourceValidationException.cs
- BoundPropertyEntry.cs
- LogWriteRestartAreaAsyncResult.cs
- DrawingDrawingContext.cs
- CodeCommentStatementCollection.cs