/// <summary> /// Gets the absolute uri for the given link href value /// </summary> /// <param name="baseUri">The context base uri</param> /// <param name="xmlBase">The base uri annotation from the payload</param> /// <param name="hrefValue">The href value for the link</param> /// <returns>The absolute uri for the link, or a relative uri if it cannot be determined</returns> internal static Uri GetAbsoluteUriForLink(Uri baseUri, XmlBaseAnnotation xmlBase, string hrefValue) { var absoluteUri = new Uri(hrefValue, UriKind.RelativeOrAbsolute); if (!absoluteUri.IsAbsoluteUri) { string root; if (xmlBase != null) { root = xmlBase.Value; } else if (baseUri != null) { ExceptionUtilities.Assert(baseUri.IsAbsoluteUri, "baseUri was not an absolute uri. It was: '{0}'", baseUri.OriginalString); root = baseUri.AbsoluteUri; } else { // TODO: need to be able to read xml:base from feed, cannot currently. // just return a relative uri for now return(absoluteUri); } absoluteUri = new Uri(UriHelpers.ConcatenateUriSegments(root, hrefValue)); } return(absoluteUri); }
/// <summary> /// Generates the next link for an expanded feed. /// </summary> /// <param name="containingEntity">The containing entity.</param> /// <param name="navigation">The expanded navigation property.</param> /// <param name="lastEntityValue">The last entity value.</param> /// <returns> /// The expected next link /// </returns> public string GenerateExpandedNextLink(EntityInstance containingEntity, NavigationPropertyInstance navigation, QueryStructuralValue lastEntityValue) { ExceptionUtilities.CheckArgumentNotNull(containingEntity, "containingEntity"); ExceptionUtilities.CheckArgumentNotNull(navigation, "navigation"); ExceptionUtilities.CheckArgumentNotNull(lastEntityValue, "lastEntityValue"); var navigationUriString = ((ExpandedLink)navigation.Value).UriString; if (string.IsNullOrEmpty(navigationUriString)) { navigationUriString = UriHelpers.ConcatenateUriSegments(containingEntity.EditLink, navigation.Name); } var skipTokenValues = new List <object>(); foreach (var keyProperty in lastEntityValue.Type.Properties.Where(p => p.IsPrimaryKey)) { skipTokenValues.Add(lastEntityValue.GetScalarValue(keyProperty.Name).Value); } var skiptoken = this.BuildSkipTokenFromValues(skipTokenValues); var nextLinkUri = new ODataUri(new UnrecognizedSegment(navigationUriString)); nextLinkUri.SkipToken = skiptoken; return(this.UriToStringConverter.ConvertToString(nextLinkUri)); }
private HttpRequestData CreateInsertRequest(DataServiceContextData dataBeforeSaveChanges, EntityDescriptorData entityDescriptorData) { Uri insertUri; if (entityDescriptorData.InsertLink != null) { insertUri = entityDescriptorData.InsertLink; } else { ExceptionUtilities.CheckObjectNotNull(entityDescriptorData.ParentForInsert, "Entity descriptor data did not have insert link or parent for insert: {0}", entityDescriptorData); ExceptionUtilities.CheckObjectNotNull(entityDescriptorData.ParentPropertyForInsert, "Entity descriptor data did not have insert link or parent property for insert: {0}", entityDescriptorData); var parentDescriptor = dataBeforeSaveChanges.GetEntityDescriptorData(entityDescriptorData.ParentForInsert); var linkInfo = parentDescriptor.LinkInfos.SingleOrDefault(l => l.Name == entityDescriptorData.ParentPropertyForInsert); if (linkInfo != null && linkInfo.NavigationLink != null) { insertUri = linkInfo.NavigationLink; } else { insertUri = new Uri(UriHelpers.ConcatenateUriSegments(parentDescriptor.EditLink.OriginalString, entityDescriptorData.ParentPropertyForInsert)); } } return(new HttpRequestData() { Verb = HttpVerb.Post, Uri = insertUri }); }
internal static Uri GetEntityInsertUri(DataServiceContextData contextData, EntityDescriptorData entityDescriptorData) { Uri insertUri; if (entityDescriptorData.InsertLink != null) { insertUri = entityDescriptorData.InsertLink; } else { ExceptionUtilities.CheckObjectNotNull(entityDescriptorData.ParentForInsert, "Entity descriptor data did not have insert link or parent for insert: {0}", entityDescriptorData); ExceptionUtilities.CheckObjectNotNull(entityDescriptorData.ParentPropertyForInsert, "Entity descriptor data did not have insert link or parent property for insert: {0}", entityDescriptorData); var parentDescriptor = contextData.GetEntityDescriptorData(entityDescriptorData.ParentForInsert); var linkInfo = parentDescriptor.LinkInfos.SingleOrDefault(l => l.Name == entityDescriptorData.ParentPropertyForInsert); if (linkInfo != null && linkInfo.NavigationLink != null) { insertUri = linkInfo.NavigationLink; } else { insertUri = new Uri(UriHelpers.ConcatenateUriSegments(parentDescriptor.EditLink.OriginalString, entityDescriptorData.ParentPropertyForInsert), UriKind.RelativeOrAbsolute); if (!insertUri.IsAbsoluteUri && contextData.BaseUri != null) { insertUri = new Uri(contextData.BaseUri, insertUri); } } } return(insertUri); }
private static HttpRequestData BuildBatchRequest(DataServiceContextData contextDataClone) { ExceptionUtilities.CheckObjectNotNull(contextDataClone.BaseUri, "Base uri cannot be null in batch cases"); var batchRequest = new HttpRequestData() { Verb = HttpVerb.Post, Uri = new Uri(UriHelpers.ConcatenateUriSegments(contextDataClone.BaseUri.OriginalString, Endpoints.Batch)) }; SetExpectedIfMatchHeader(batchRequest, null); SetUnexpectedPreferHeader(batchRequest); SetExpectedXHTTPMethodHeader(batchRequest, false); return(batchRequest); }
private string NormalizeLinkFromPayload(string link, IEnumerable<XmlBaseAnnotation> xmlBaseAnnotations) { if (link == null) { return null; } var linkUri = new Uri(link, UriKind.RelativeOrAbsolute); if (!linkUri.IsAbsoluteUri) { linkUri = new Uri(UriHelpers.ConcatenateUriSegments(xmlBaseAnnotations.Select(b => b.Value).Concat(link).ToArray()), UriKind.RelativeOrAbsolute); } return linkUri.OriginalString; }
internal static Uri BuildLinkUri(LinkDescriptorData linkDescriptorData, LinkInfoData info) { Uri linkUri; if (info != null && info.RelationshipLink != null) { linkUri = info.RelationshipLink; } else { ExceptionUtilities.CheckObjectNotNull(linkDescriptorData.SourceDescriptor.EditLink, "Edit link of source descriptor cannot be null"); linkUri = new Uri(UriHelpers.ConcatenateUriSegments(linkDescriptorData.SourceDescriptor.EditLink.OriginalString, Endpoints.Ref, linkDescriptorData.SourcePropertyName), UriKind.RelativeOrAbsolute); } return(linkUri); }
/// <summary> /// Tracks the AddObject method. /// </summary> /// <param name="data">The data service context data on which to apply state transition.</param> /// <param name="entitySetName">Name of the entity set.</param> /// <param name="entity">The entity.</param> public static void TrackAddObject(this DataServiceContextData data, string entitySetName, object entity) { CheckEntitySetName(ref entitySetName); CheckEntityIsNotTracked(data, entity); var entityDescriptorData = data.CreateEntityDescriptorData(EntityStates.Added, data.GetNextChangeOrder(), entity) .SetEntitySetName(entitySetName); if (data.ResolveEntitySet != null) { entityDescriptorData.InsertLink = data.ResolveEntitySet(entitySetName); } else { entityDescriptorData.InsertLink = new Uri(UriHelpers.ConcatenateUriSegments(data.BaseUri.OriginalString, entitySetName)); } }
private void QueryEntityInstanceAndGenerateStreams(QueryStructuralValue queryStructuralValue, IAsyncContinuation continuation) { var rootQuery = (QueryExpression)this.queryStructuralValueToRootQueryLookup[queryStructuralValue]; var query = ODataQueryTestCase.GetExistingEntityQuery(rootQuery, queryStructuralValue); var requestUriString = this.QueryExpressionToUriConverter.ComputeUri(query); requestUriString = UriHelpers.ConcatenateUriSegments(this.Workspace.ServiceUri.OriginalString, requestUriString); HttpWebRequest requestForExistingEntity = (HttpWebRequest)HttpWebRequest.Create(requestUriString); requestForExistingEntity.GetResponse <HttpWebResponse>( this.Asynchronous, continuation, (response) => { ProcessEntityAndGenerateStreams(queryStructuralValue, continuation, response); }); }
/// <summary> /// Calculates an entity id based on the base uri, entity set resolver, set name, and entity key values /// </summary> /// <param name="contextData">The context data</param> /// <param name="entitySetName">the entity set name</param> /// <param name="entity">The entity to generate an id for</param> /// <returns>The id for the given entity</returns> public Uri CalculateEntityId(DataServiceContextData contextData, string entitySetName, object entity) { ExceptionUtilities.CheckArgumentNotNull(contextData, "contextData"); ExceptionUtilities.CheckStringArgumentIsNotNullOrEmpty(entitySetName, "entitySetName"); ExceptionUtilities.CheckArgumentNotNull(entity, "entity"); if (contextData.BaseUri != null) { ExceptionUtilities.Assert(contextData.BaseUri.IsAbsoluteUri, "Base uri must be absolute. Uri was: '{0}'", contextData.BaseUri.OriginalString); return(new Uri(UriHelpers.ConcatenateUriSegments(contextData.BaseUri.AbsoluteUri, Uri.EscapeDataString(entitySetName) + this.CalculateEntityKey(entity)))); } else { ExceptionUtilities.CheckObjectNotNull(contextData.ResolveEntitySet, "Entity set resolver cannot be null if base uri is null"); var resolvedUri = contextData.ResolveEntitySet(entitySetName); ExceptionUtilities.CheckObjectNotNull(resolvedUri, "Entity set resolver returned null for set name '{0}'", entitySetName); return(new Uri(resolvedUri.AbsoluteUri + this.CalculateEntityKey(entity))); } }
/// <summary> /// Construct expected relationship link value. /// </summary> /// <param name="entity">entity that the link belongs to</param> /// <param name="navigation">navigation property instance for the relationship link</param> /// <returns>expected relationship link value</returns> private string BuildExpectedAssociationUri(EntityInstance entity, NavigationPropertyInstance navigation) { return(UriHelpers.ConcatenateUriSegments(entity.GetEditLink(), Endpoints.Ref, Uri.EscapeDataString(navigation.Name))); }