/// <summary> /// Create ODataContextUrlInfo from ODataResourceTypeContext /// </summary> /// <param name="typeContext">The ODataResourceTypeContext to be used.</param> /// <param name="version">The OData Version of the response</param> /// <param name="isSingle">Whether target is single item.</param> /// <param name="odataUri">The odata uri info for current query.</param> /// <returns>The generated ODataContextUrlInfo.</returns> internal static ODataContextUrlInfo Create(ODataResourceTypeContext typeContext, ODataVersion version, bool isSingle, ODataUri odataUri = null) { Debug.Assert(typeContext != null, "typeContext != null"); var hasNavigationSourceInfo = typeContext.NavigationSourceKind != EdmNavigationSourceKind.None || !string.IsNullOrEmpty(typeContext.NavigationSourceName); var typeName = hasNavigationSourceInfo ? typeContext.NavigationSourceFullTypeName : typeContext.ExpectedResourceTypeName == null ? null : isSingle ? typeContext.ExpectedResourceTypeName : EdmLibraryExtensions.GetCollectionTypeName(typeContext.ExpectedResourceTypeName); return(new ODataContextUrlInfo() { HasNavigationSourceInfo = hasNavigationSourceInfo, IsUnknownEntitySet = typeContext.NavigationSourceKind == EdmNavigationSourceKind.UnknownEntitySet, NavigationSource = typeContext.NavigationSourceName, TypeCast = typeContext.NavigationSourceEntityTypeName == null || typeContext.ExpectedResourceTypeName == null || typeContext.ExpectedResourceType is IEdmComplexType || typeContext.NavigationSourceEntityTypeName == typeContext.ExpectedResourceTypeName ? null : typeContext.ExpectedResourceTypeName, TypeName = typeName, IncludeFragmentItemSelector = isSingle && typeContext.NavigationSourceKind != EdmNavigationSourceKind.Singleton, NavigationPath = ComputeNavigationPath(typeContext.NavigationSourceKind, odataUri, typeContext.NavigationSourceName), ResourcePath = ComputeResourcePath(odataUri), QueryClause = ComputeQueryClause(odataUri, version), IsUndeclared = ComputeIfIsUndeclared(odataUri) }); }
/// <summary> /// Remove the Edm. prefix from the type name if it is primitive type. /// </summary> /// <param name="typeName">The type name to remove the Edm. prefix</param> /// <returns>The type name without the Edm. Prefix</returns> internal static string RemoveEdmPrefixFromTypeName(string typeName) { if (!string.IsNullOrEmpty(typeName)) { string itemTypeName = EdmLibraryExtensions.GetCollectionItemTypeName(typeName); if (itemTypeName == null) { IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(typeName); if (primitiveType != null) { return(primitiveType.ShortQualifiedName()); } } else { IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(itemTypeName); if (primitiveType != null) { return(EdmLibraryExtensions.GetCollectionTypeName(primitiveType.ShortQualifiedName())); } } } return(typeName); }
/// <summary> /// Add the Edm. prefix to the primitive type if there isn't. /// </summary> /// <param name="typeName">The type name which may be not prefixed (Edm.).</param> /// <returns>The type name with Edm. prefix</returns> internal static string AddEdmPrefixOfTypeName(string typeName) { if (!string.IsNullOrEmpty(typeName)) { string itemTypeName = EdmLibraryExtensions.GetCollectionItemTypeName(typeName); if (itemTypeName == null) { // This is the primitive type IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(typeName); if (primitiveType != null) { return(primitiveType.FullName()); } } else { // This is the collection type IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(itemTypeName); if (primitiveType != null) { return(EdmLibraryExtensions.GetCollectionTypeName(primitiveType.FullName())); } } } // Return the origin type name return(typeName); }
/// <summary> /// Prepare the type name for writing. /// 1) If it is primitive type, remove the Edm. prefix. /// 2) If it is a non-primitive type or 4.0, prefix with #. /// </summary> /// <param name="typeName">The type name to write</param> /// <param name="version">OData Version of payload being written</param> /// <returns>The type name for writing</returns> internal static string PrefixTypeNameForWriting(string typeName, ODataVersion version) { if (!string.IsNullOrEmpty(typeName)) { string itemTypeName = EdmLibraryExtensions.GetCollectionItemTypeName(typeName); if (itemTypeName == null) { IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(typeName); if (primitiveType != null) { typeName = primitiveType.ShortQualifiedName(); return(version < ODataVersion.V401 ? PrefixTypeName(typeName) : typeName); } } else { IEdmSchemaType primitiveType = EdmLibraryExtensions.ResolvePrimitiveTypeName(itemTypeName); if (primitiveType != null) { typeName = EdmLibraryExtensions.GetCollectionTypeName(primitiveType.ShortQualifiedName()); return(version < ODataVersion.V401 ? PrefixTypeName(typeName) : typeName); } } } return(PrefixTypeName(typeName)); }
/// <summary> /// Create ODataContextUrlInfo from ODataCollectionStartSerializationInfo /// </summary> /// <param name="info">The ODataCollectionStartSerializationInfo to be used.</param> /// <param name="itemTypeReference">ItemTypeReference specifying element type.</param> /// <returns>The generated ODataContextUrlInfo.</returns> internal static ODataContextUrlInfo Create(ODataCollectionStartSerializationInfo info, IEdmTypeReference itemTypeReference) { string collectionTypeName = null; if (info != null) { collectionTypeName = info.CollectionTypeName; } else if (itemTypeReference != null) { collectionTypeName = EdmLibraryExtensions.GetCollectionTypeName(itemTypeReference.FullName()); } return(new ODataContextUrlInfo() { TypeName = collectionTypeName, }); }
/// <summary> /// Creates the metadata URI for an operation (function, action, service op) based on its function import. /// </summary> /// <param name="serializationInfo">Serialization information to generate the metadata uri.</param> /// <param name="itemTypeReference">The item type of the collection.</param> /// <param name="metadataUri">Returns the metadata URI for an operation (function, action, service op) based on its function import.</param> /// <returns>true if we have successfully built the metadata URI; false otherwise.</returns> internal override bool TryBuildCollectionMetadataUri(ODataCollectionStartSerializationInfo serializationInfo, IEdmTypeReference itemTypeReference, out Uri metadataUri) { DebugUtils.CheckNoExternalCallers(); string collectionTypeName = null; if (serializationInfo != null) { collectionTypeName = serializationInfo.CollectionTypeName; } else if (itemTypeReference != null) { collectionTypeName = EdmLibraryExtensions.GetCollectionTypeName(itemTypeReference.ODataFullName()); } metadataUri = CreateTypeMetadataUri(this.metadataDocumentUri, collectionTypeName); if (this.writingResponse && metadataUri == null) { throw new ODataException(OData.Strings.ODataJsonLightMetadataUriBuilder_TypeNameMissingForTopLevelCollectionWhenWritingResponsePayload); } return(metadataUri != null); }
/// <summary>Returns EDM name of the type for a collection of specified <paramref name="itemType"/>.</summary> /// <param name="itemType">Resource type of a single item in the collection.</param> /// <returns>EDM name of the type of a collection of <paramref name="itemType"/>.</returns> private static string GetName(ResourceType itemType) { Debug.Assert(itemType != null, "itemType != null"); return(EdmLibraryExtensions.GetCollectionTypeName(itemType.FullName)); }
/// <summary> /// Determines the resource set type name to write to the payload. /// </summary> /// <param name="expectedResourceTypeName">The expected resource type name of the items in the resource set.</param> /// <param name="resourceSet">The ODataResourceSet whose type is to be written.</param> /// <param name="isUndeclared">true if the resource set is for some undeclared property</param> /// <returns>Type name to write to the payload, or null if no type name should be written.</returns> internal override string GetResourceSetTypeNameForForWriting(string expectedResourceTypeName, ODataResourceSet resourceSet, bool isUndeclared) { Debug.Assert(resourceSet != null, "resourceSet != null"); if (resourceSet.TypeAnnotation != null) { return(resourceSet.TypeAnnotation.TypeName); } var expectedResourceSetTypeName = expectedResourceTypeName == null ? null : EdmLibraryExtensions.GetCollectionTypeName(expectedResourceTypeName); if (expectedResourceSetTypeName != resourceSet.TypeName || isUndeclared) { return(resourceSet.TypeName); } return(null); }
/// <summary> /// Gets the specified type name as an EDM Collection type, e.g. Collection(Edm.String) /// </summary> /// <param name="itemTypeName">Type name of the items in the collection.</param> /// <returns>Collection type name for the specified item type name.</returns> private static string GetCollectionName(string itemTypeName) { return(itemTypeName == null ? null : EdmLibraryExtensions.GetCollectionTypeName(itemTypeName)); }