/// <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.ParentEntityDescriptor != 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.ParentEntityDescriptor.Identity == null)
                {
                    Uri relativeReferenceUri = UriUtil.CreateUri("$" + this.ParentEntityDescriptor.ChangeOrder.ToString(CultureInfo.InvariantCulture), UriKind.Relative);
                    Uri absoluteReferenceUri = baseUriResolver.GetOrCreateAbsoluteUri(relativeReferenceUri);
                    Uri requestUri           = UriUtil.CreateUri(this.ParentProperty, UriKind.Relative);
                    return(UriUtil.CreateUri(absoluteReferenceUri, requestUri));
                }
                else
                {
                    Debug.Assert(this.ParentEntityDescriptor.ParentEntityDescriptor == null, "This code assumes that parentChild relationships will only ever be one level deep");
                    Debug.Assert(this.ParentProperty != null, "ParentProperty != null");
                    LinkInfo linkInfo;
                    if (this.ParentEntityDescriptor.TryGetLinkInfo(this.ParentProperty, out linkInfo))
                    {
                        if (linkInfo.NavigationLink != null)
                        {
                            return(linkInfo.NavigationLink);
                        }
                    }

                    return(UriUtil.CreateUri(this.ParentEntityDescriptor.GetLink(queryLink), this.GetLink(queryLink)));
                }
            }
            else
            {
                return(this.GetLink(queryLink));
            }
        }
예제 #2
0
        /// <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;
        }
        /// <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;
        }
        /// <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, UriKind.Relative);
                uri = UriUtil.CreateUri(this.GetResourceUri(baseUriResolver, true /*queryLink*/), relativeUri);
            }

            return(uri);
        }
예제 #5
0
 internal ConventionalODataEntityMetadataBuilder(Uri baseUri, string entitySetName, IEdmStructuredValue entityInstance, DataServiceUrlConventions conventions)
     : this(UriResolver.CreateFromBaseUri(baseUri, "baseUri"), entitySetName, entityInstance, conventions)
 {
 }
예제 #6
0
 /// <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;
 }
예제 #7
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, UriKind.Relative); 
                uri = UriUtil.CreateUri(this.GetResourceUri(baseUriResolver, true /*queryLink*/), relativeUri);
            }

            return uri;
        }
예제 #8
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.ParentEntityDescriptor != 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.ParentEntityDescriptor.Identity == null)
                {
                    Uri relativeReferenceUri = UriUtil.CreateUri("$" + this.ParentEntityDescriptor.ChangeOrder.ToString(CultureInfo.InvariantCulture), UriKind.Relative);
                    Uri absoluteReferenceUri = baseUriResolver.GetOrCreateAbsoluteUri(relativeReferenceUri);
                    Uri requestUri = UriUtil.CreateUri(this.ParentProperty, UriKind.Relative);
                    return UriUtil.CreateUri(absoluteReferenceUri, requestUri);
                }
                else
                {
                    Debug.Assert(this.ParentEntityDescriptor.ParentEntityDescriptor == null, "This code assumes that parentChild relationships will only ever be one level deep");
                    Debug.Assert(this.ParentProperty != null, "ParentProperty != null");
                    LinkInfo linkInfo;
                    if (this.ParentEntityDescriptor.TryGetLinkInfo(this.ParentProperty, out linkInfo))
                    {
                        if (linkInfo.NavigationLink != null)
                        {
                            return linkInfo.NavigationLink;
                        }
                    }

                    return UriUtil.CreateUri(this.ParentEntityDescriptor.GetLink(queryLink), this.GetLink(queryLink));
                }
            }
            else
            {
                return this.GetLink(queryLink);
            }
        }
 /// <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;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConventionalODataUriBuilder"/> class.
 /// </summary>
 /// <param name="resolver">The uri resolver to use.</param>
 /// <param name="urlKeyDelimiter">The key delimiter user specified.</param>
 internal ConventionalODataUriBuilder(UriResolver resolver, DataServiceUrlKeyDelimiter urlKeyDelimiter)
 {
     Debug.Assert(resolver != null, "resolver != null");
     this.resolver        = resolver;
     this.urlKeyDelimiter = urlKeyDelimiter;
 }