internal void WriteWorkspaceMetadata(ODataWorkspace workspace)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(workspace != null, "workspace != null");

            AtomWorkspaceMetadata metadata = workspace.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 ReadTitleElementInWorkspace(AtomWorkspaceMetadata workspaceMetadata)
 {
     if (workspaceMetadata.Title != null)
     {
         throw new ODataException(Strings.ODataAtomServiceDocumentMetadataDeserializer_MultipleTitleElementsFound("workspace"));
     }
     workspaceMetadata.Title = base.ReadTitleElement();
 }
Esempio n. 3
0
 public static AtomWorkspaceMetadata Atom(this ODataWorkspace workspace)
 {
     ExceptionUtils.CheckArgumentNotNull<ODataWorkspace>(workspace, "workspace");
     AtomWorkspaceMetadata annotation = workspace.GetAnnotation<AtomWorkspaceMetadata>();
     if (annotation == null)
     {
         annotation = new AtomWorkspaceMetadata();
         workspace.SetAnnotation<AtomWorkspaceMetadata>(annotation);
     }
     return annotation;
 }
Esempio n. 4
0
        public static AtomWorkspaceMetadata Atom(this ODataWorkspace workspace)
        {
            ExceptionUtils.CheckArgumentNotNull <ODataWorkspace>(workspace, "workspace");
            AtomWorkspaceMetadata annotation = workspace.GetAnnotation <AtomWorkspaceMetadata>();

            if (annotation == null)
            {
                annotation = new AtomWorkspaceMetadata();
                workspace.SetAnnotation <AtomWorkspaceMetadata>(annotation);
            }
            return(annotation);
        }
Esempio n. 5
0
        /// <summary>
        /// Extension method to get the <see cref="AtomWorkspaceMetadata"/> for an annotatable workspace.
        /// </summary>
        /// <param name="workspace">The workspace to get the annotation from.</param>
        /// <returns>An <see cref="AtomWorkspaceMetadata" /> instance or null if no annotation of that type exists.</returns>
        public static AtomWorkspaceMetadata Atom(this ODataWorkspace workspace)
        {
            ExceptionUtils.CheckArgumentNotNull(workspace, "workspace");

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

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

            return(workspaceMetadata);
        }
        /// <summary>
        /// Reads an atom:title element and adds the new information to <paramref name="workspaceMetadata"/>.
        /// </summary>
        /// <param name="workspaceMetadata">The non-null workspace metadata object to augment.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - The start of the atom:title element.
        /// Post-Condition: Any                 - The next node after the atom:title element. 
        /// </remarks>
        internal void ReadTitleElementInWorkspace(AtomWorkspaceMetadata workspaceMetadata)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(workspaceMetadata != null, "workspaceMetadata != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.LocalName == AtomConstants.AtomTitleElementName, "Expected element named 'title'.");
            Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Element 'title' should be in the atom namespace.");

            if (workspaceMetadata.Title != null)
            {
                throw new ODataException(Strings.ODataAtomServiceDocumentMetadataDeserializer_MultipleTitleElementsFound(AtomConstants.AtomPublishingWorkspaceElementName));
            }

            workspaceMetadata.Title = this.ReadTitleElement();
        }
Esempio n. 7
0
        /// <summary>
        /// Reads an atom:title element and adds the new information to <paramref name="workspaceMetadata"/>.
        /// </summary>
        /// <param name="workspaceMetadata">The non-null workspace metadata object to augment.</param>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - The start of the atom:title element.
        /// Post-Condition: Any                 - The next node after the atom:title element.
        /// </remarks>
        internal void ReadTitleElementInWorkspace(AtomWorkspaceMetadata workspaceMetadata)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(workspaceMetadata != null, "workspaceMetadata != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.LocalName == AtomConstants.AtomTitleElementName, "Expected element named 'title'.");
            Debug.Assert(this.XmlReader.NamespaceURI == AtomConstants.AtomNamespace, "Element 'title' should be in the atom namespace.");

            if (workspaceMetadata.Title != null)
            {
                throw new ODataException(Strings.ODataAtomServiceDocumentMetadataDeserializer_MultipleTitleElementsFound(AtomConstants.AtomPublishingWorkspaceElementName));
            }

            workspaceMetadata.Title = this.ReadTitleElement();
        }
        internal void WriteWorkspaceMetadata(ODataWorkspace workspace)
        {
            AtomWorkspaceMetadata annotation    = workspace.GetAnnotation <AtomWorkspaceMetadata>();
            AtomTextConstruct     textConstruct = null;

            if (annotation != null)
            {
                textConstruct = annotation.Title;
            }
            if (textConstruct == null)
            {
                textConstruct = new AtomTextConstruct {
                    Text = "Default"
                };
            }
            if (base.UseServerFormatBehavior && (textConstruct.Kind == AtomTextConstructKind.Text))
            {
                base.WriteElementWithTextContent("atom", "title", "http://www.w3.org/2005/Atom", textConstruct.Text);
            }
            else
            {
                base.WriteTextConstruct("atom", "title", "http://www.w3.org/2005/Atom", textConstruct);
            }
        }
        /// <summary>
        /// Reads a workspace of a service document.
        /// </summary>
        /// <returns>An <see cref="ODataWorkspace"/> representing the workspace of a service document.</returns>
        /// <remarks>
        /// Pre-Condition:  Any    - the next node after the service element.
        /// Post-Condition: Any    - The next node after the workspace element.
        /// </remarks>
        private ODataWorkspace ReadWorkspace()
        {
            Debug.Assert(this.XmlReader != null, "this.XmlReader != null");

            bool enableAtomMetadataReading = this.AtomInputContext.MessageReaderSettings.EnableAtomMetadataReading;

            // skip anything which is not in the ATOM publishing namespace.
            this.SkipToElementInAtomPublishingNamespace();

            this.AssertXmlCondition(XmlNodeType.Element, XmlNodeType.EndElement);

            // if we already found an EndElement, it means that there is no workspace.
            if (this.XmlReader.NodeType == XmlNodeType.EndElement)
            {
                return(null);
            }

            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.NamespaceEquals(this.AtomPublishingNamespace), "The current element should have been in the Atom publishing namespace.");

            if (!this.XmlReader.LocalNameEquals(this.AtomPublishingWorkspaceElementName))
            {
                throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInServiceDocument(this.XmlReader.LocalName));
            }

            List <ODataResourceCollectionInfo> collections = new List <ODataResourceCollectionInfo>();
            AtomWorkspaceMetadata workspaceMetadata        = null;

            if (enableAtomMetadataReading)
            {
                workspaceMetadata = new AtomWorkspaceMetadata();
            }

            if (!this.XmlReader.IsEmptyElement)
            {
                // read over the 'workspace' element.
                this.XmlReader.ReadStartElement();

                do
                {
                    this.XmlReader.SkipInsignificantNodes();

                    switch (this.XmlReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (this.XmlReader.NamespaceEquals(this.AtomPublishingNamespace))
                        {
                            if (this.XmlReader.LocalNameEquals(this.AtomPublishingCollectionElementName))
                            {
                                ODataResourceCollectionInfo collection = this.ReadCollectionElement();
                                Debug.Assert(collection != null, "collection != null");
                                collections.Add(collection);
                            }
                            else
                            {
                                // Throw error if we find anything other then a 'collection' element in the Atom publishing namespace.
                                throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInWorkspace(this.XmlReader.LocalName));
                            }
                        }
                        else if (enableAtomMetadataReading && this.XmlReader.NamespaceEquals(this.AtomNamespace))
                        {
                            if (this.XmlReader.LocalNameEquals(this.AtomTitleElementName))
                            {
                                this.ServiceDocumentMetadataDeserializer.ReadTitleElementInWorkspace(workspaceMetadata);
                            }
                            else
                            {
                                this.XmlReader.Skip();
                            }
                        }
                        else
                        {
                            // skip all other elements
                            this.XmlReader.Skip();
                        }

                        break;

                    case XmlNodeType.EndElement:
                        // end of 'workspace' element.
                        break;

                    default:
                        // ignore all other nodes.
                        this.XmlReader.Skip();
                        break;
                    }
                }while (this.XmlReader.NodeType != XmlNodeType.EndElement);
            } // if (!this.XmlReader.IsEmptyElement)

            // read over the end tag of the workspace element or the start tag if the workspace element is empty.
            this.XmlReader.Read();

            ODataWorkspace workspace = new ODataWorkspace
            {
                Collections = new ReadOnlyEnumerable <ODataResourceCollectionInfo>(collections)
            };

            if (enableAtomMetadataReading)
            {
                workspace.SetAnnotation <AtomWorkspaceMetadata>(workspaceMetadata);
            }

            return(workspace);
        }
 internal void ReadTitleElementInWorkspace(AtomWorkspaceMetadata workspaceMetadata)
 {
     if (workspaceMetadata.Title != null)
     {
         throw new ODataException(Strings.ODataAtomServiceDocumentMetadataDeserializer_MultipleTitleElementsFound("workspace"));
     }
     workspaceMetadata.Title = base.ReadTitleElement();
 }
        private ODataWorkspace ReadWorkspace()
        {
            bool enableAtomMetadataReading = base.AtomInputContext.MessageReaderSettings.EnableAtomMetadataReading;
            this.SkipToElementInAtomPublishingNamespace();
            if (base.XmlReader.NodeType == XmlNodeType.EndElement)
            {
                return null;
            }
            if (!base.XmlReader.LocalNameEquals(this.AtomPublishingWorkspaceElementName))
            {
                throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInServiceDocument(base.XmlReader.LocalName));
            }
            List<ODataResourceCollectionInfo> sourceList = new List<ODataResourceCollectionInfo>();
            AtomWorkspaceMetadata workspaceMetadata = null;
            if (enableAtomMetadataReading)
            {
                workspaceMetadata = new AtomWorkspaceMetadata();
            }
            if (!base.XmlReader.IsEmptyElement)
            {
                base.XmlReader.ReadStartElement();
                do
                {
                    base.XmlReader.SkipInsignificantNodes();
                    switch (base.XmlReader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (base.XmlReader.NamespaceEquals(this.AtomPublishingNamespace))
                            {
                                if (!base.XmlReader.LocalNameEquals(this.AtomPublishingCollectionElementName))
                                {
                                    throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInWorkspace(base.XmlReader.LocalName));
                                }
                                ODataResourceCollectionInfo item = this.ReadCollectionElement();
                                sourceList.Add(item);
                            }
                            else if (enableAtomMetadataReading && base.XmlReader.NamespaceEquals(this.AtomNamespace))
                            {
                                if (base.XmlReader.LocalNameEquals(this.AtomTitleElementName))
                                {
                                    this.ServiceDocumentMetadataDeserializer.ReadTitleElementInWorkspace(workspaceMetadata);
                                }
                                else
                                {
                                    base.XmlReader.Skip();
                                }
                            }
                            else
                            {
                                base.XmlReader.Skip();
                            }
                            break;

                        case XmlNodeType.EndElement:
                            break;

                        default:
                            base.XmlReader.Skip();
                            break;
                    }
                }
                while (base.XmlReader.NodeType != XmlNodeType.EndElement);
            }
            base.XmlReader.Read();
            ODataWorkspace workspace = new ODataWorkspace {
                Collections = new ReadOnlyEnumerable<ODataResourceCollectionInfo>(sourceList)
            };
            if (enableAtomMetadataReading)
            {
                workspace.SetAnnotation<AtomWorkspaceMetadata>(workspaceMetadata);
            }
            return workspace;
        }
Esempio n. 12
0
        private ODataWorkspace ReadWorkspace()
        {
            bool enableAtomMetadataReading = base.AtomInputContext.MessageReaderSettings.EnableAtomMetadataReading;

            this.SkipToElementInAtomPublishingNamespace();
            if (base.XmlReader.NodeType == XmlNodeType.EndElement)
            {
                return(null);
            }
            if (!base.XmlReader.LocalNameEquals(this.AtomPublishingWorkspaceElementName))
            {
                throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInServiceDocument(base.XmlReader.LocalName));
            }
            List <ODataResourceCollectionInfo> sourceList = new List <ODataResourceCollectionInfo>();
            AtomWorkspaceMetadata workspaceMetadata       = null;

            if (enableAtomMetadataReading)
            {
                workspaceMetadata = new AtomWorkspaceMetadata();
            }
            if (!base.XmlReader.IsEmptyElement)
            {
                base.XmlReader.ReadStartElement();
                do
                {
                    base.XmlReader.SkipInsignificantNodes();
                    switch (base.XmlReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (base.XmlReader.NamespaceEquals(this.AtomPublishingNamespace))
                        {
                            if (!base.XmlReader.LocalNameEquals(this.AtomPublishingCollectionElementName))
                            {
                                throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInWorkspace(base.XmlReader.LocalName));
                            }
                            ODataResourceCollectionInfo item = this.ReadCollectionElement();
                            sourceList.Add(item);
                        }
                        else if (enableAtomMetadataReading && base.XmlReader.NamespaceEquals(this.AtomNamespace))
                        {
                            if (base.XmlReader.LocalNameEquals(this.AtomTitleElementName))
                            {
                                this.ServiceDocumentMetadataDeserializer.ReadTitleElementInWorkspace(workspaceMetadata);
                            }
                            else
                            {
                                base.XmlReader.Skip();
                            }
                        }
                        else
                        {
                            base.XmlReader.Skip();
                        }
                        break;

                    case XmlNodeType.EndElement:
                        break;

                    default:
                        base.XmlReader.Skip();
                        break;
                    }
                }while (base.XmlReader.NodeType != XmlNodeType.EndElement);
            }
            base.XmlReader.Read();
            ODataWorkspace workspace = new ODataWorkspace {
                Collections = new ReadOnlyEnumerable <ODataResourceCollectionInfo>(sourceList)
            };

            if (enableAtomMetadataReading)
            {
                workspace.SetAnnotation <AtomWorkspaceMetadata>(workspaceMetadata);
            }
            return(workspace);
        }
Esempio n. 13
0
        /// <summary>
        /// Extension method to get the <see cref="AtomWorkspaceMetadata"/> for an annotatable workspace.
        /// </summary>
        /// <param name="workspace">The workspace to get the annotation from.</param>
        /// <returns>An <see cref="AtomWorkspaceMetadata" /> instance or null if no annotation of that type exists.</returns>
        public static AtomWorkspaceMetadata Atom(this ODataWorkspace workspace)
        {
            ExceptionUtils.CheckArgumentNotNull(workspace, "workspace");

            AtomWorkspaceMetadata workspaceMetadata = workspace.GetAnnotation<AtomWorkspaceMetadata>();
            if (workspaceMetadata == null)
            {
                workspaceMetadata = new AtomWorkspaceMetadata();
                workspace.SetAnnotation(workspaceMetadata);
            }

            return workspaceMetadata;
        }