예제 #1
0
        public void WriteServiceDocument()
        {
            var msgWriter   = new ODataMessageWriter(_response, _writerSettings, _map.Model);
            var collections = new List <ODataResourceCollectionInfo>();

            foreach (
                var entityContainer in
                _map.Model.EntityContainers().Where(ec => _map.Model.IsDefaultEntityContainer(ec)))
            {
                foreach (var es in entityContainer.EntitySets())
                {
                    var collectionInfo = new ODataResourceCollectionInfo {
                        Url = new Uri(es.Name, UriKind.Relative)
                    };
                    var metadata = new AtomResourceCollectionMetadata {
                        Title = es.Name
                    };
                    collectionInfo.SetAnnotation(metadata);
                    collections.Add(collectionInfo);
                }
            }
            var workspace = new ODataWorkspace {
                Collections = collections
            };

            msgWriter.WriteServiceDocument(workspace);
        }
        private static ODataResourceCollectionInfo GetODataResourceCollectionInfo(string url, string name)
        {
            ODataResourceCollectionInfo info = new ODataResourceCollectionInfo
            {
                Name = name, // Required for JSON light support
                Url = new Uri(url, UriKind.Relative)
            };

            info.SetAnnotation<AtomResourceCollectionMetadata>(new AtomResourceCollectionMetadata { Title = name });

            return info;
        }
예제 #3
0
        public static AtomResourceCollectionMetadata Atom(this ODataResourceCollectionInfo collection)
        {
            ExceptionUtils.CheckArgumentNotNull <ODataResourceCollectionInfo>(collection, "collection");
            AtomResourceCollectionMetadata annotation = collection.GetAnnotation <AtomResourceCollectionMetadata>();

            if (annotation == null)
            {
                annotation = new AtomResourceCollectionMetadata();
                collection.SetAnnotation <AtomResourceCollectionMetadata>(annotation);
            }
            return(annotation);
        }
예제 #4
0
        private static ODataResourceCollectionInfo GetODataResourceCollectionInfo(string url, string name)
        {
            ODataResourceCollectionInfo info = new ODataResourceCollectionInfo
            {
                Url = new Uri(url, UriKind.Relative)
            };

            info.SetAnnotation <AtomResourceCollectionMetadata>(new AtomResourceCollectionMetadata {
                Title = name
            });

            return(info);
        }
        internal void WriteServiceDocument(DataServiceProviderWrapper provider)
        {
            ODataWorkspace defaultWorkspace = new ODataWorkspace {
                Collections = provider.GetResourceSets().Select <ResourceSetWrapper, ODataResourceCollectionInfo>(delegate(ResourceSetWrapper rs) {
                    ODataResourceCollectionInfo info = new ODataResourceCollectionInfo {
                        Url = new Uri(rs.Name, UriKind.RelativeOrAbsolute)
                    };
                    AtomResourceCollectionMetadata annotation = new AtomResourceCollectionMetadata();
                    AtomTextConstruct construct = new AtomTextConstruct {
                        Text = rs.Name
                    };
                    annotation.Title = construct;
                    info.SetAnnotation <AtomResourceCollectionMetadata>(annotation);
                    return(info);
                })
            };

            this.writer.WriteServiceDocument(defaultWorkspace);
        }
        /// <summary>
        /// Reads a resource collection element of a workspace of the service document.
        /// </summary>
        /// <returns>An <see cref="ODataResourceCollectionInfo"/> representing the resource collection in a workspace of a service document.</returns>
        /// <remarks>
        /// Pre-Condition:  XmlNodeType.Element - the collection element inside the workspace.
        /// Post-Condition: Any    - The next node after the collection element.
        /// </remarks>
        private ODataResourceCollectionInfo ReadCollectionElement()
        {
            Debug.Assert(this.XmlReader != null, "this.XmlReader != null");
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(this.XmlReader.LocalNameEquals(this.AtomPublishingCollectionElementName), "Expected element named 'collection'.");
            Debug.Assert(this.XmlReader.NamespaceEquals(this.AtomPublishingNamespace), "Element 'collection' should be in the atom publishing namespace.");

            ODataResourceCollectionInfo collectionInfo = new ODataResourceCollectionInfo();

            string href = this.XmlReader.GetAttribute(this.AtomHRefAttributeName, this.EmptyNamespace);

            ValidationUtils.ValidateResourceCollectionInfoUrl(href);

            collectionInfo.Url = ProcessUriFromPayload(href, this.XmlReader.XmlBaseUri);
            bool enableAtomMetadataReading = this.MessageReaderSettings.EnableAtomMetadataReading;

            AtomResourceCollectionMetadata collectionMetadata = null;

            if (enableAtomMetadataReading)
            {
                collectionMetadata = new AtomResourceCollectionMetadata();
            }

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

                do
                {
                    switch (this.XmlReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (this.XmlReader.NamespaceEquals(this.AtomPublishingNamespace))
                        {
                            if (this.XmlReader.LocalNameEquals(this.AtomPublishingCategoriesElementName))
                            {
                                if (enableAtomMetadataReading)
                                {
                                    this.ServiceDocumentMetadataDeserializer.ReadCategoriesElementInCollection(collectionMetadata);
                                }
                                else
                                {
                                    this.XmlReader.Skip();
                                }
                            }
                            else if (this.XmlReader.LocalNameEquals(this.AtomPublishingAcceptElementName))
                            {
                                if (enableAtomMetadataReading)
                                {
                                    this.ServiceDocumentMetadataDeserializer.ReadAcceptElementInCollection(collectionMetadata);
                                }
                                else
                                {
                                    this.XmlReader.Skip();
                                }
                            }
                            else
                            {
                                // Throw error if we find anything other then a 'app:categories' or an 'app:accept' element in the ATOM publishing namespace.
                                throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInResourceCollection(this.XmlReader.LocalName));
                            }
                        }
                        else if (this.XmlReader.NamespaceEquals(this.AtomNamespace))
                        {
                            if (enableAtomMetadataReading && this.XmlReader.LocalNameEquals(this.AtomTitleElementName))
                            {
                                this.ServiceDocumentMetadataDeserializer.ReadTitleElementInCollection(collectionMetadata);
                            }
                            else
                            {
                                // Skip all other elements in the atom namespace
                                this.XmlReader.Skip();
                            }
                        }
                        else
                        {
                            // For now, skip all other elements.
                            this.XmlReader.Skip();
                        }

                        break;

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

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

            this.AssertXmlCondition(true, XmlNodeType.EndElement);

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

            if (enableAtomMetadataReading)
            {
                collectionInfo.SetAnnotation(collectionMetadata);
            }

            return(collectionInfo);
        }
예제 #7
0
        private ODataResourceCollectionInfo ReadCollectionElement()
        {
            ODataResourceCollectionInfo info = new ODataResourceCollectionInfo();
            string attribute = base.XmlReader.GetAttribute(this.AtomHRefAttributeName, this.EmptyNamespace);

            ValidationUtils.ValidateResourceCollectionInfoUrl(attribute);
            info.Url = base.ProcessUriFromPayload(attribute, base.XmlReader.XmlBaseUri);
            bool enableAtomMetadataReading = base.MessageReaderSettings.EnableAtomMetadataReading;
            AtomResourceCollectionMetadata collectionMetadata = null;

            if (enableAtomMetadataReading)
            {
                collectionMetadata = new AtomResourceCollectionMetadata();
            }
            if (!base.XmlReader.IsEmptyElement)
            {
                base.XmlReader.ReadStartElement();
                do
                {
                    switch (base.XmlReader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (base.XmlReader.NamespaceEquals(this.AtomPublishingNamespace))
                        {
                            if (base.XmlReader.LocalNameEquals(this.AtomPublishingCategoriesElementName))
                            {
                                if (enableAtomMetadataReading)
                                {
                                    this.ServiceDocumentMetadataDeserializer.ReadCategoriesElementInCollection(collectionMetadata);
                                }
                                else
                                {
                                    base.XmlReader.Skip();
                                }
                            }
                            else
                            {
                                if (!base.XmlReader.LocalNameEquals(this.AtomPublishingAcceptElementName))
                                {
                                    throw new ODataException(Strings.ODataAtomServiceDocumentDeserializer_UnexpectedElementInResourceCollection(base.XmlReader.LocalName));
                                }
                                if (enableAtomMetadataReading)
                                {
                                    this.ServiceDocumentMetadataDeserializer.ReadAcceptElementInCollection(collectionMetadata);
                                }
                                else
                                {
                                    base.XmlReader.Skip();
                                }
                            }
                        }
                        else if (base.XmlReader.NamespaceEquals(this.AtomNamespace))
                        {
                            if (enableAtomMetadataReading && base.XmlReader.LocalNameEquals(this.AtomTitleElementName))
                            {
                                this.ServiceDocumentMetadataDeserializer.ReadTitleElementInCollection(collectionMetadata);
                            }
                            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();
            if (enableAtomMetadataReading)
            {
                info.SetAnnotation <AtomResourceCollectionMetadata>(collectionMetadata);
            }
            return(info);
        }