Example #1
0
 /// <summary>
 /// Gets the entity properties.
 /// </summary>
 /// <param name="nonComputedProperties">Non-computed properties from the entity.</param>
 /// <returns>The the computed and non-computed entity properties.</returns>
 internal override IEnumerable <ODataProperty> GetProperties(IEnumerable <ODataProperty> nonComputedProperties)
 {
     if (!isResourceEnd)
     {
         return(nonComputedProperties);
     }
     else
     {
         return(ODataUtilsInternal.ConcatEnumerables(nonComputedProperties, this.GetComputedStreamProperties(nonComputedProperties)));
     }
 }
Example #2
0
 private void AddOrRemovePayloadKinds(Func <ODataPayloadKind, bool> addOrRemoveAction, params ODataPayloadKind[] payloadKinds)
 {
     for (int i = 0; i < payloadKinds.Length; i++)
     {
         ODataPayloadKind payloadKind = payloadKinds[i];
         if (ODataUtilsInternal.IsPayloadKindSupported(payloadKind, !base.ReadingResponse))
         {
             addOrRemoveAction(payloadKind);
         }
     }
 }
Example #3
0
        /// <summary>
        /// Write an error message.
        /// </summary>
        /// <param name="jsonWriter">The JSON writer to write to.</param>
        /// <param name="error">The error instance to write.</param>
        /// <param name="includeDebugInformation">A flag indicating whether error details should be written (in debug mode only) or not.</param>
        internal static void WriteError(JsonWriter jsonWriter, ODataError error, bool includeDebugInformation)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(jsonWriter != null, "jsonWriter != null");
            Debug.Assert(error != null, "error != null");

            string code, message, messageLanguage;

            ODataUtilsInternal.GetErrorDetails(error, out code, out message, out messageLanguage);

            string innerError = includeDebugInformation ? error.InnerError : null;

            WriteError(jsonWriter, code, message, messageLanguage, innerError);
        }
Example #4
0
        /// <summary>
        /// Adds or removes the set of specified payload kinds to/from the detected payload kinds (if the specified
        /// payload kinds are valid for the current request/response).
        /// </summary>
        /// <param name="addOrRemoveAction">The function that implements the 'Add' or 'Remove' action.</param>
        /// <param name="payloadKinds">The payload kinds to add/remove.</param>
        private void AddOrRemovePayloadKinds(Func <ODataPayloadKind, bool> addOrRemoveAction, params ODataPayloadKind[] payloadKinds)
        {
            Debug.Assert(addOrRemoveAction != null, "addOrRemoveAction != null");
            Debug.Assert(payloadKinds != null, "payloadKinds != null");

            for (int i = 0; i < payloadKinds.Length; ++i)
            {
                ODataPayloadKind payloadKind = payloadKinds[i];
                if (ODataUtilsInternal.IsPayloadKindSupported(payloadKind, !this.ReadingResponse))
                {
                    addOrRemoveAction(payloadKind);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Injects the appropriate metadata builder based on the metadata level.
        /// </summary>
        /// <param name="entry">The entry to inject the builder.</param>
        /// <param name="builder">The metadata builder to inject.</param>
        internal override void InjectMetadataBuilder(ODataEntry entry, ODataEntityMetadataBuilder builder)
        {
            DebugUtils.CheckNoExternalCallers();
            entry.MetadataBuilder = builder;

            // Inject to the Media Resource.
            var mediaResource = entry.NonComputedMediaResource;

            if (mediaResource != null)
            {
                mediaResource.SetMetadataBuilder(builder, /*propertyName*/ null);
            }

            // Inject to named stream property values
            if (entry.NonComputedProperties != null)
            {
                foreach (ODataProperty property in entry.NonComputedProperties)
                {
                    var streamReferenceValue = property.ODataValue as ODataStreamReferenceValue;
                    if (streamReferenceValue != null)
                    {
                        streamReferenceValue.SetMetadataBuilder(builder, property.Name);
                    }
                }
            }

            // Inject to operations
            IEnumerable <ODataOperation> operations = ODataUtilsInternal.ConcatEnumerables((IEnumerable <ODataOperation>)entry.NonComputedActions, (IEnumerable <ODataOperation>)entry.NonComputedFunctions);

            if (operations != null)
            {
                foreach (ODataOperation operation in operations)
                {
                    operation.SetMetadataBuilder(builder, this.NonNullMetadataDocumentUri);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Returns a hash set of operation imports (actions and functions) in the given entry.
        /// </summary>
        /// <param name="entry">The entry in question.</param>
        /// <param name="model">The edm model to resolve operation imports.</param>
        /// <param name="metadataDocumentUri">The metadata document uri.</param>
        /// <returns>The hash set of operation imports (actions and functions) in the given entry.</returns>
        private static HashSet <IEdmOperation> GetOperationsInEntry(ODataEntry entry, IEdmModel model, Uri metadataDocumentUri)
        {
            Debug.Assert(entry != null, "entry != null");
            Debug.Assert(model != null, "model != null");
            Debug.Assert(metadataDocumentUri != null && metadataDocumentUri.IsAbsoluteUri, "metadataDocumentUri != null && metadataDocumentUri.IsAbsoluteUri");

            HashSet <IEdmOperation>      edmOperationImportsInEntry = new HashSet <IEdmOperation>(EqualityComparer <IEdmOperation> .Default);
            IEnumerable <ODataOperation> operations = ODataUtilsInternal.ConcatEnumerables((IEnumerable <ODataOperation>)entry.NonComputedActions, (IEnumerable <ODataOperation>)entry.NonComputedFunctions);

            if (operations != null)
            {
                foreach (ODataOperation operation in operations)
                {
                    Debug.Assert(operation.Metadata != null, "operation.Metadata != null");
                    string operationMetadataString = UriUtils.UriToString(operation.Metadata);
                    Debug.Assert(
                        ODataJsonLightUtils.IsMetadataReferenceProperty(operationMetadataString),
                        "ODataJsonLightUtils.IsMetadataReferenceProperty(operationMetadataString)");
                    Debug.Assert(
                        operationMetadataString[0] == ODataConstants.ContextUriFragmentIndicator || metadataDocumentUri.IsBaseOf(operation.Metadata),
                        "operationMetadataString[0] == JsonLightConstants.ContextUriFragmentIndicator || metadataDocumentUri.IsBaseOf(operation.Metadata)");

                    string fullyQualifiedOperationName        = ODataJsonLightUtils.GetUriFragmentFromMetadataReferencePropertyName(metadataDocumentUri, operationMetadataString);
                    IEnumerable <IEdmOperation> edmOperations = model.ResolveOperations(fullyQualifiedOperationName);
                    if (edmOperations != null)
                    {
                        foreach (IEdmOperation edmOperation in edmOperations)
                        {
                            edmOperationImportsInEntry.Add(edmOperation);
                        }
                    }
                }
            }

            return(edmOperationImportsInEntry);
        }
Example #7
0
        /// <summary>
        /// Injects the appropriate metadata builder based on the metadata level.
        /// </summary>
        /// <param name="resource">The resource to inject the builder.</param>
        /// <param name="builder">The metadata builder to inject.</param>
        internal override void InjectMetadataBuilder(ODataResourceBase resource, ODataResourceMetadataBuilder builder)
        {
            base.InjectMetadataBuilder(resource, builder);

            // Inject to the Media Resource.
            var mediaResource = resource.NonComputedMediaResource;

            if (mediaResource != null)
            {
                mediaResource.SetMetadataBuilder(builder, /*propertyName*/ null);
            }

            // Inject to named stream property values
            if (resource.NonComputedProperties != null)
            {
                foreach (ODataProperty property in resource.NonComputedProperties)
                {
                    var streamReferenceValue = property.ODataValue as ODataStreamReferenceValue;
                    if (streamReferenceValue != null)
                    {
                        streamReferenceValue.SetMetadataBuilder(builder, property.Name);
                    }
                }
            }

            // Inject to operations
            IEnumerable <ODataOperation> operations = ODataUtilsInternal.ConcatEnumerables((IEnumerable <ODataOperation>)resource.NonComputedActions, (IEnumerable <ODataOperation>)resource.NonComputedFunctions);

            if (operations != null)
            {
                foreach (ODataOperation operation in operations)
                {
                    operation.SetMetadataBuilder(builder, this.NonNullMetadataDocumentUri);
                }
            }
        }
Example #8
0
 internal override IEnumerable <ODataFunction> GetFunctions()
 {
     return(ODataUtilsInternal.ConcatEnumerables(this.entryMetadataContext.Entry.NonComputedFunctions, this.MissingOperationGenerator.GetComputedFunctions()));
 }
Example #9
0
 internal override IEnumerable <ODataAction> GetActions()
 {
     DebugUtils.CheckNoExternalCallers();
     return(ODataUtilsInternal.ConcatEnumerables(this.entryMetadataContext.Entry.NonComputedActions, this.MissingOperationGenerator.GetComputedActions()));
 }
Example #10
0
 /// <summary>
 /// Gets the entity properties.
 /// </summary>
 /// <param name="nonComputedProperties">Non-computed properties from the entity.</param>
 /// <returns>The the computed and non-computed entity properties.</returns>
 internal override IEnumerable <ODataProperty> GetProperties(IEnumerable <ODataProperty> nonComputedProperties)
 {
     DebugUtils.CheckNoExternalCallers();
     return(ODataUtilsInternal.ConcatEnumerables(nonComputedProperties, this.GetComputedStreamProperties(nonComputedProperties)));
 }
Example #11
0
 internal override IEnumerable <ODataAction> GetActions()
 {
     return(ODataUtilsInternal.ConcatEnumerables(this.ResourceMetadataContext.Resource.NonComputedActions, this.MissingOperationGenerator.GetComputedActions()));
 }