internal static Uri GenerateFunctionLink(this ResourceSetContext feedContext, string bindingParameterType, string functionName, IEnumerable <string> parameterNames) { Contract.Assert(feedContext != null); if (feedContext.EntitySetBase is IEdmContainedEntitySet) { return(null); } if (feedContext.EdmModel == null) { return(null); } IEdmModel model = feedContext.EdmModel; string elementType = DeserializationHelpers.GetCollectionElementTypeName(bindingParameterType, isNested: false); Contract.Assert(elementType != null); IEdmTypeReference typeReference = model.FindDeclaredType(elementType).ToEdmTypeReference(true); IEdmTypeReference collection = new EdmCollectionTypeReference(new EdmCollectionType(typeReference)); IEdmOperation operation = model.FindDeclaredOperations(functionName).First(); return(feedContext.GenerateFunctionLink(collection, operation, parameterNames)); }
internal static Uri GenerateActionLink(this ResourceSetContext resourceSetContext, IEdmTypeReference bindingParameterType, IEdmOperation action) { Contract.Assert(resourceSetContext != null); if (resourceSetContext.EntitySetBase is IEdmContainedEntitySet) { return(null); } IList <ODataPathSegment> actionPathSegments = new List <ODataPathSegment>(); resourceSetContext.GenerateBaseODataPathSegmentsForFeed(actionPathSegments); // generate link with cast if the navigation source doesn't match the type the action is bound to. if (resourceSetContext.EntitySetBase.Type.FullTypeName() != bindingParameterType.FullName()) { actionPathSegments.Add(new TypeSegment(bindingParameterType.Definition, resourceSetContext.EntitySetBase)); } OperationSegment operationSegment = new OperationSegment(action, entitySet: null); actionPathSegments.Add(operationSegment); string actionLink = resourceSetContext.Request.CreateODataLink(actionPathSegments); return(actionLink == null ? null : new Uri(actionLink)); }
private static void GenerateBaseODataPathSegmentsForFeed( this ResourceSetContext feedContext, IList <ODataPathSegment> odataPath) { GenerateBaseODataPathSegmentsForNonSingletons(feedContext.Request.ODataFeature().Path, feedContext.EntitySetBase, odataPath); }
/// <summary> /// Create a <see cref="ResourceSetContext"/> from an <see cref="ODataSerializerContext"/> and <see cref="IEnumerable"/>. /// </summary> /// <param name="resourceSetInstance">The instance representing the resourceSet being written.</param> /// <param name="writeContext">The serializer context.</param> /// <returns>A new <see cref="ResourceSetContext"/>.</returns> /// <remarks>This signature uses types that are AspNetCore-specific.</remarks> internal static ResourceSetContext Create(ODataSerializerContext writeContext, IEnumerable resourceSetInstance) { ResourceSetContext resourceSetContext = new ResourceSetContext { Request = writeContext.Request, EntitySetBase = writeContext.NavigationSource as IEdmEntitySetBase, // Url = writeContext.Url, ResourceSetInstance = resourceSetInstance }; return(resourceSetContext); }
/// <summary> /// Generates an action link following the OData URL conventions for the action <paramref name="action"/> and bound to the /// collection of entity represented by <paramref name="resourceSetContext"/>. /// </summary> /// <param name="resourceSetContext">The <see cref="ResourceSetContext"/> representing the feed for which the action link needs to be generated.</param> /// <param name="action">The action for which the action link needs to be generated.</param> /// <returns>The generated action link following OData URL conventions.</returns> public static Uri GenerateActionLink(this ResourceSetContext resourceSetContext, IEdmOperation action) { if (resourceSetContext == null) { throw new ArgumentNullException(nameof(resourceSetContext)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } IEdmOperationParameter bindingParameter = action.Parameters.FirstOrDefault(); if (bindingParameter == null || !bindingParameter.Type.IsCollection() || !((IEdmCollectionType)bindingParameter.Type.Definition).ElementType.IsEntity()) { throw Error.Argument("action", SRResources.ActionNotBoundToCollectionOfEntity, action.Name); } return(GenerateActionLink(resourceSetContext, bindingParameter.Type, action)); }
internal static Uri GenerateFunctionLink(this ResourceSetContext resourceSetContext, IEdmTypeReference bindingParameterType, IEdmOperation functionImport, IEnumerable <string> parameterNames) { Contract.Assert(resourceSetContext != null); if (resourceSetContext.EntitySetBase is IEdmContainedEntitySet) { return(null); } IList <ODataPathSegment> functionPathSegments = new List <ODataPathSegment>(); resourceSetContext.GenerateBaseODataPathSegmentsForFeed(functionPathSegments); // generate link with cast if the navigation source type doesn't match the entity type the function is bound to. if (resourceSetContext.EntitySetBase.Type.FullTypeName() != bindingParameterType.Definition.FullTypeName()) { functionPathSegments.Add(new TypeSegment(bindingParameterType.Definition, null)); } IList <OperationSegmentParameter> parameters = new List <OperationSegmentParameter>(); // skip the binding parameter foreach (string param in parameterNames.Skip(1)) { string value = "@" + param; parameters.Add(new OperationSegmentParameter(param, new ConstantNode(value, value))); } OperationSegment segment = new OperationSegment(new[] { functionImport }, parameters, null); functionPathSegments.Add(segment); string functionLink = resourceSetContext.Request.CreateODataLink(functionPathSegments); return(functionLink == null ? null : new Uri(functionLink)); }