예제 #1
0
        private void WriteNavigationLink(ODataWriter writer, ODataNestedResourceInfo link)
        {
            writer.WriteStart(link);
            var expanded = link.GetAnnotation <ODataNavigationLinkExpandedItemObjectModelAnnotation>();

            if (expanded != null)
            {
                var feed = expanded.ExpandedItem as ODataResourceSet;
                if (feed != null)
                {
                    this.WriteFeed(writer, feed);
                }
                else
                {
                    ODataResource entry = expanded.ExpandedItem as ODataResource;
                    if (entry != null || expanded.ExpandedItem == null)
                    {
                        this.WriteEntry(writer, entry);
                    }
                    else
                    {
                        ExceptionUtilities.Assert(expanded.ExpandedItem is ODataEntityReferenceLink, "Content of a nav. link can only be a feed, entry or entity reference link.");
                        writer.WriteEntityReferenceLink((ODataEntityReferenceLink)expanded.ExpandedItem);
                    }
                }
            }

            writer.WriteEnd();
        }
예제 #2
0
        internal void WriteNavigationLink(EntityDescriptor entityDescriptor, IEnumerable <LinkDescriptor> relatedLinks, ODataWriter odataWriter)
        {
            ClientTypeAnnotation clientTypeAnnotation = null;

            foreach (LinkDescriptor descriptor in relatedLinks)
            {
                descriptor.ContentGeneratedForSave = true;
                if (clientTypeAnnotation == null)
                {
                    ClientEdmModel model = ClientEdmModel.GetModel(this.requestInfo.MaxProtocolVersion);
                    clientTypeAnnotation = model.GetClientTypeAnnotation(model.GetOrCreateEdmType(entityDescriptor.Entity.GetType()));
                }
                ODataNavigationLink navigationLink = new ODataNavigationLink {
                    Url          = this.requestInfo.EntityTracker.GetEntityDescriptor(descriptor.Target).GetLatestEditLink(),
                    IsCollection = new bool?(clientTypeAnnotation.GetProperty(descriptor.SourceProperty, false).IsEntityCollection),
                    Name         = descriptor.SourceProperty
                };
                odataWriter.WriteStart(navigationLink);
                ODataEntityReferenceLink entityReferenceLink = new ODataEntityReferenceLink {
                    Url = navigationLink.Url
                };
                odataWriter.WriteEntityReferenceLink(entityReferenceLink);
                odataWriter.WriteEnd();
            }
        }
예제 #3
0
        private void WriteNavigationLink(ODataWriter writer, Lazy <ODataReader> lazyReader, ODataNavigationLink link)
        {
            this.WriteStart(writer, link);
            var expanded = link.GetAnnotation <ODataNavigationLinkExpandedItemObjectModelAnnotation>();

            if (expanded != null)
            {
                var feed = expanded.ExpandedItem as ODataFeed;
                if (feed != null)
                {
                    this.WriteFeed(writer, lazyReader, feed);
                }
                else
                {
                    ODataEntry entry = expanded.ExpandedItem as ODataEntry;
                    if (entry != null || expanded.ExpandedItem == null)
                    {
                        this.WriteEntry(writer, lazyReader, entry);
                    }
                    else
                    {
                        ExceptionUtilities.Assert(expanded.ExpandedItem is ODataEntityReferenceLink, "Content of a nav. link can only be a feed, entry or entity reference link.");
                        writer.WriteEntityReferenceLink((ODataEntityReferenceLink)expanded.ExpandedItem);
                    }
                }
            }

            this.WriteEnd(writer, ODataReaderState.NavigationLinkEnd);
            this.Read(lazyReader);
        }
예제 #4
0
        private void WriteLink(ODataWriter entryWriter, Microsoft.Data.OData.ODataEntry entry, string linkName, IEnumerable <ReferenceLink> links)
        {
            var navigationProperty = (_model.FindDeclaredType(entry.TypeName) as IEdmEntityType).NavigationProperties()
                                     .BestMatch(x => x.Name, linkName, _session.Settings.NameMatchResolver);
            bool isCollection = navigationProperty.Type.Definition.TypeKind == EdmTypeKind.Collection;

            var linkType        = GetNavigationPropertyEntityType(navigationProperty);
            var linkTypeWithKey = linkType;

            while (linkTypeWithKey.DeclaredKey == null && linkTypeWithKey.BaseEntityType() != null)
            {
                linkTypeWithKey = linkTypeWithKey.BaseEntityType();
            }

            entryWriter.WriteStart(new ODataNavigationLink()
            {
                Name         = linkName,
                IsCollection = isCollection,
                Url          = new Uri(ODataNamespace.Related + linkType, UriKind.Absolute),
            });

            foreach (var referenceLink in links)
            {
                var    linkKey   = linkTypeWithKey.DeclaredKey;
                var    linkEntry = referenceLink.LinkData.ToDictionary();
                var    contentId = GetContentId(referenceLink);
                string linkUri;
                if (contentId != null)
                {
                    linkUri = "$" + contentId;
                }
                else
                {
                    bool isSingleton;
                    var  formattedKey = _session.Adapter.GetCommandFormatter().ConvertKeyValuesToUriLiteral(
                        linkKey.ToDictionary(x => x.Name, x => linkEntry[x.Name]), true);
                    var linkedCollectionName = _session.Metadata.GetLinkedCollectionName(
                        referenceLink.LinkData.GetType().Name, linkTypeWithKey.Name, out isSingleton);
                    linkUri = linkedCollectionName + (isSingleton ? string.Empty : formattedKey);
                }
                var link = new ODataEntityReferenceLink
                {
                    Url = Utils.CreateAbsoluteUri(_session.Settings.BaseUri.AbsoluteUri, linkUri)
                };

                entryWriter.WriteEntityReferenceLink(link);
            }

            entryWriter.WriteEnd();
        }