/// <summary> /// Writes "actions" or "functions" metadata. /// </summary> /// <param name="operations">The operations to write.</param> /// <param name="isAction">true when writing the resource's actions; false when writing the resource's functions.</param> internal void WriteOperations(IEnumerable <ODataOperation> operations, bool isAction) { // We cannot compare two URIs directly because the 'Equals' method on the 'Uri' class compares two 'Uri' instances without regard to the // fragment part of the URI. (E.G: For 'http://someuri/index.htm#EC.action1' and http://someuri/index.htm#EC.action2', the 'Equals' method // will return true. IEnumerable <IGrouping <string, ODataOperation> > metadataGroups = operations.GroupBy(o => { // We need to validate here to ensure that the metadata is not null, otherwise call to the method 'UriToString' will throw. ValidationUtils.ValidateOperationNotNull(o, isAction); WriterValidationUtils.ValidateCanWriteOperation(o, this.JsonLightOutputContext.WritingResponse); ODataJsonLightValidationUtils.ValidateOperation(this.MetadataDocumentBaseUri, o); return(this.GetOperationMetadataString(o)); }); foreach (IGrouping <string, ODataOperation> metadataGroup in metadataGroups) { this.WriteOperationMetadataGroup(metadataGroup); } }
/// <summary> /// Gets the metadata reference fragment from the operation context uri. /// i.e. if the operation context uri is {absolute metadata document uri}#{container-qualified-operation-name}, /// this method will return #{container-qualified-operation-name}. /// </summary> /// <param name="operation">Operation in question.</param> /// <returns>The metadata reference fragment from the operation context uri.</returns> private string GetOperationMetadataString(ODataOperation operation) { Debug.Assert(operation != null && operation.Metadata != null, "operation != null && operation.Metadata != null"); string operationMetadataString = UriUtils.UriToString(operation.Metadata); Debug.Assert(ODataJsonLightUtils.IsMetadataReferenceProperty(operationMetadataString), "ODataJsonLightUtils.IsMetadataReferenceProperty(operationMetadataString)"); // If we don't have a metadata document URI (which is the case with nometadata mode), just write the string form of the Uri we were given. if (this.MetadataDocumentBaseUri == null) { return(operation.Metadata.Fragment); } Debug.Assert( !ODataJsonLightValidationUtils.IsOpenMetadataReferencePropertyName(this.MetadataDocumentBaseUri, operationMetadataString), "Open metadata reference property is not supported, we should have thrown before this point."); return(ODataConstants.ContextUriFragmentIndicator + ODataJsonLightUtils.GetUriFragmentFromMetadataReferencePropertyName(this.MetadataDocumentBaseUri, operationMetadataString)); }