internal void WriteServiceDocumentMetadata(ODataServiceDocument serviceDocument)
        {
            Debug.Assert(serviceDocument != null, "serviceDocument != null");

            AtomWorkspaceMetadata metadata = serviceDocument.GetAnnotation <AtomWorkspaceMetadata>();
            AtomTextConstruct     title    = null;

            if (metadata != null)
            {
                title = metadata.Title;
            }

            if (title == null)
            {
                title = new AtomTextConstruct {
                    Text = AtomConstants.AtomWorkspaceDefaultTitle
                };
            }

            if (this.UseServerFormatBehavior && title.Kind == AtomTextConstructKind.Text)
            {
                // For WCF DS server we must not write the type attribute, just a simple <atom:title>Default<atom:title>
                this.WriteElementWithTextContent(
                    AtomConstants.NonEmptyAtomNamespacePrefix,
                    AtomConstants.AtomTitleElementName,
                    AtomConstants.AtomNamespace,
                    title.Text);
            }
            else
            {
                // <atom:title>title</atom:title>
                this.WriteTextConstruct(AtomConstants.NonEmptyAtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace, title);
            }
        }
        internal void WriteServiceDocumentMetadata(ODataServiceDocument serviceDocument)
        {
            Debug.Assert(serviceDocument != null, "serviceDocument != null");

            AtomWorkspaceMetadata metadata = serviceDocument.GetAnnotation<AtomWorkspaceMetadata>();
            AtomTextConstruct title = null;
            if (metadata != null)
            {
                title = metadata.Title;
            }

            if (title == null)
            {
                title = new AtomTextConstruct { Text = AtomConstants.AtomWorkspaceDefaultTitle };
            }

            if (this.UseServerFormatBehavior && title.Kind == AtomTextConstructKind.Text)
            {
                // For WCF DS server we must not write the type attribute, just a simple <atom:title>Default<atom:title>
                this.WriteElementWithTextContent(
                    AtomConstants.NonEmptyAtomNamespacePrefix,
                    AtomConstants.AtomTitleElementName,
                    AtomConstants.AtomNamespace,
                    title.Text);
            }
            else
            {
                // <atom:title>title</atom:title>
                this.WriteTextConstruct(AtomConstants.NonEmptyAtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace, title);
            }
        }
Exemplo n.º 3
0
        /// <summary>Determines an extension method to get the <see cref="T:System.Data.OData.Atom.AtomWorkspaceMetadata" /> for an annotatable serviceDocument.</summary>
        /// <returns>An <see cref="T:Microsoft.OData.Core.Atom.AtomWorkspaceMetadata" /> instance or null if no annotation of that type exists.</returns>
        /// <param name="serviceDocument">The serviceDocument to get the annotation from.</param>
        public static AtomWorkspaceMetadata Atom(this ODataServiceDocument serviceDocument)
        {
            ExceptionUtils.CheckArgumentNotNull(serviceDocument, "serviceDocument");

            AtomWorkspaceMetadata workspaceMetadata = serviceDocument.GetAnnotation <AtomWorkspaceMetadata>();

            if (workspaceMetadata == null)
            {
                workspaceMetadata = new AtomWorkspaceMetadata();
                serviceDocument.SetAnnotation(workspaceMetadata);
            }

            return(workspaceMetadata);
        }
            /// <summary>
            /// Visits a serviceDocument item.
            /// </summary>
            /// <param name="serviceDocument">The serviceDocument item to visit.</param>
            /// <returns>An ODataPayloadElement representing a service document enclosing the serviceDocument.</returns>
            protected override ODataPayloadElement VisitWorkspace(ODataServiceDocument serviceDocument)
            {
                ExceptionUtilities.CheckArgumentNotNull(serviceDocument, "serviceDocument");

                ServiceDocumentInstance wrappingServiceDocumentInstance = (ServiceDocumentInstance)base.VisitWorkspace(serviceDocument);

                WorkspaceInstance     workspaceInstance = wrappingServiceDocumentInstance.Workspaces.Single();
                AtomWorkspaceMetadata atomMetadata      = serviceDocument.GetAnnotation <AtomWorkspaceMetadata>();

                if (atomMetadata != null)
                {
                    if (atomMetadata.Title != null)
                    {
                        workspaceInstance.Title = atomMetadata.Title.Text;
                        workspaceInstance.AtomTitle(atomMetadata.Title.Text, ToString(atomMetadata.Title.Kind));
                    }
                }

                return(wrappingServiceDocumentInstance);
            }
 /// <summary>
 /// Visits a service document.
 /// </summary>
 /// <param name="serviceDocument">The service document to visit.</param>
 protected override void VisitServiceDocument(ODataServiceDocument serviceDocument)
 {
     this.VisitAtomMetadata(serviceDocument.GetAnnotation <AtomWorkspaceMetadata>());
     base.VisitServiceDocument(serviceDocument);
 }