Beispiel #1
0
        /// <summary>uri to edit the entity</summary>
        /// <param name="baseUriResolver">retrieves the baseUri to use for a given entity set.</param>
        /// <param name="queryLink">whether to return the query link or edit link</param>
        /// <returns>absolute uri which can be used to edit the entity</returns>
        internal Uri GetResourceUri(UriResolver baseUriResolver, bool queryLink)
        {
            // If the entity was inserted using the AddRelatedObject API
            if (this.ParentForInsert != null)
            {
                // This is the batch scenario, where the entity might not have been saved yet, and there is another operation
                // (for e.g. PUT $1/links/BestFriend or something). Hence we need to generate a Uri with the changeorder number.
                if (this.ParentForInsert.Identity == null)
                {
                    Uri relativeReferenceUri = UriUtil.CreateUri("$" + this.ParentForInsert.ChangeOrder.ToString(CultureInfo.InvariantCulture), UriKind.Relative);
                    Uri absoluteReferenceUri = baseUriResolver.GetOrCreateAbsoluteUri(relativeReferenceUri);
                    Uri requestUri           = UriUtil.CreateUri(this.ParentPropertyForInsert, UriKind.Relative);
                    return(UriUtil.CreateUri(absoluteReferenceUri, requestUri));
                }
                else
                {
                    Debug.Assert(this.ParentForInsert.ParentForInsert == null, "This code assumes that parentChild relationships will only ever be one level deep");
                    Debug.Assert(this.ParentPropertyForInsert != null, "parentProperty != null");
                    LinkInfo linkInfo;
                    if (this.ParentForInsert.TryGetLinkInfo(this.ParentPropertyForInsert, out linkInfo))
                    {
                        if (linkInfo.NavigationLink != null)
                        {
                            return(linkInfo.NavigationLink);
                        }
                    }

                    return(UriUtil.CreateUri(this.ParentForInsert.GetLink(queryLink), this.GetLink(queryLink)));
                }
            }
            else
            {
                return(this.GetLink(queryLink));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConventionalODataEntityMetadataBuilder"/> class.
        /// </summary>
        /// <param name="resolver">The URI resolver to use.</param>
        /// <param name="entitySetName">Name of the entity set the entity belongs to.</param>
        /// <param name="entityInstance">The entity instance to build metadata for.</param>
        /// <param name="conventions">The user-specified conventions to use.</param>
        internal ConventionalODataEntityMetadataBuilder(UriResolver resolver, string entitySetName, IEdmStructuredValue entityInstance, DataServiceUrlConventions conventions)
        {
            Util.CheckArgumentNullAndEmpty(entitySetName, "entitySetName");
            Util.CheckArgumentNull(entityInstance, "entityInstance");
            Util.CheckArgumentNull(conventions, "conventions");
            this.entitySetName  = entitySetName;
            this.entityInstance = entityInstance;

            this.uriBuilder = new ConventionalODataUriBuilder(resolver, conventions);
            this.baseUri    = resolver.BaseUriOrNull;
        }
Beispiel #3
0
        internal Uri GetNavigationLink(UriResolver baseUriResolver, ClientPropertyAnnotation property)
        {
            LinkInfo linkInfo       = null;
            Uri      navigationLink = null;

            if (this.TryGetLinkInfo(property.PropertyName, out linkInfo))
            {
                navigationLink = linkInfo.NavigationLink;
            }
            if (navigationLink == null)
            {
                Uri requestUri = Util.CreateUri(property.PropertyName + (property.IsEntityCollection ? "()" : string.Empty), UriKind.Relative);
                navigationLink = Util.CreateUri(this.GetResourceUri(baseUriResolver, true), requestUri);
            }
            return(navigationLink);
        }
Beispiel #4
0
        internal Uri GetResourceUri(UriResolver baseUriResolver, bool queryLink)
        {
            LinkInfo info;

            if (this.parentDescriptor == null)
            {
                return(this.GetLink(queryLink));
            }
            if (this.parentDescriptor.Identity == null)
            {
                return(Util.CreateUri(Util.CreateUri(baseUriResolver.GetBaseUriWithSlash(), new Uri("$" + this.parentDescriptor.ChangeOrder.ToString(CultureInfo.InvariantCulture), UriKind.Relative)), Util.CreateUri(this.parentProperty, UriKind.Relative)));
            }
            if (this.parentDescriptor.TryGetLinkInfo(this.parentProperty, out info) && (info.NavigationLink != null))
            {
                return(info.NavigationLink);
            }
            return(Util.CreateUri(this.parentDescriptor.GetLink(queryLink), this.GetLink(queryLink)));
        }
Beispiel #5
0
        /// <summary>
        /// Try and get the navigation link. If the navigation link is not specified, then its used the self link of the entity and
        /// appends the property name.
        /// </summary>
        /// <param name="baseUriResolver">retrieves the appropriate baseUri for a given entitySet.</param>
        /// <param name="property">ClientProperty instance representing the navigation property.</param>
        /// <returns>returns the uri for the given link. If the link is not present, its uses the self link of the current entity and appends the navigation property name.</returns>
        internal Uri GetNavigationLink(UriResolver baseUriResolver, ClientPropertyAnnotation property)
        {
            LinkInfo linkInfo = null;
            Uri      uri      = null;

            if (this.TryGetLinkInfo(property.PropertyName, out linkInfo))
            {
                uri = linkInfo.NavigationLink;
            }

            if (uri == null)
            {
                Uri relativeUri = UriUtil.CreateUri(property.PropertyName + (property.IsEntityCollection ? "()" : String.Empty), UriKind.Relative);
                uri = UriUtil.CreateUri(this.GetResourceUri(baseUriResolver, true /*queryLink*/), relativeUri);
            }

            return(uri);
        }
 internal ConventionalODataEntityMetadataBuilder(Uri baseUri, string entitySetName, IEdmStructuredValue entityInstance, DataServiceUrlConventions conventions)
     : this(UriResolver.CreateFromBaseUri(baseUri, "baseUri"), entitySetName, entityInstance, conventions)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConventionalODataUriBuilder"/> class.
 /// </summary>
 /// <param name="resolver">The uri resolver to use.</param>
 /// <param name="conventions">The user specified conventions to use.</param>
 internal ConventionalODataUriBuilder(UriResolver resolver, DataServiceUrlConventions conventions)
 {
     Debug.Assert(resolver != null, "resolver != null");
     this.resolver    = resolver;
     this.conventions = conventions;
 }
Beispiel #8
0
 internal Uri GetResourceUri(UriResolver baseUriResolver, bool queryLink)
 {
     LinkInfo info;
     if (this.parentDescriptor == null)
     {
         return this.GetLink(queryLink);
     }
     if (this.parentDescriptor.Identity == null)
     {
         return Util.CreateUri(Util.CreateUri(baseUriResolver.GetBaseUriWithSlash(), new Uri("$" + this.parentDescriptor.ChangeOrder.ToString(CultureInfo.InvariantCulture), UriKind.Relative)), Util.CreateUri(this.parentProperty, UriKind.Relative));
     }
     if (this.parentDescriptor.TryGetLinkInfo(this.parentProperty, out info) && (info.NavigationLink != null))
     {
         return info.NavigationLink;
     }
     return Util.CreateUri(this.parentDescriptor.GetLink(queryLink), this.GetLink(queryLink));
 }
Beispiel #9
0
 internal Uri GetNavigationLink(UriResolver baseUriResolver, ClientPropertyAnnotation property)
 {
     LinkInfo linkInfo = null;
     Uri navigationLink = null;
     if (this.TryGetLinkInfo(property.PropertyName, out linkInfo))
     {
         navigationLink = linkInfo.NavigationLink;
     }
     if (navigationLink == null)
     {
         Uri requestUri = Util.CreateUri(property.PropertyName + (property.IsEntityCollection ? "()" : string.Empty), UriKind.Relative);
         navigationLink = Util.CreateUri(this.GetResourceUri(baseUriResolver, true), requestUri);
     }
     return navigationLink;
 }