Example #1
0
        /// <summary>
        /// Throw if property is processed already.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="duplicationRecord">DuplicationRecord of the property.</param>
        private static void ThrowIfPropertyIsProcessed(string propertyName, DuplicationRecord duplicationRecord)
        {
            if (object.ReferenceEquals(duplicationRecord.PropertyODataAnnotations, propertyAnnotationsProcessedToken))
            {
                if (ODataJsonLightReaderUtils.IsAnnotationProperty(propertyName) && !ODataJsonLightUtils.IsMetadataReferenceProperty(propertyName))
                {
                    throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicateAnnotationNotAllowed(propertyName));
                }

                throw new ODataException(Strings.DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed(propertyName));
            }
        }
Example #2
0
        /// <summary>
        /// Marks a property to note that all its annotations should have been processed by now.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <remarks>
        /// It's an error if more annotations for a marked property are found later in the payload.
        /// </remarks>
        internal void MarkPropertyAsProcessed(string propertyName)
        {
            Debug.Assert(propertyName != null);

            PropertyData data;

            if (!propertyData.TryGetValue(propertyName, out data))
            {
                propertyData[propertyName] = data = new PropertyData(PropertyState.AnnotationSeen);
            }

            if (data.Processed)
            {
                throw new ODataException(
                          ODataJsonLightReaderUtils.IsAnnotationProperty(propertyName) &&
                          !ODataJsonLightUtils.IsMetadataReferenceProperty(propertyName)
                    ? Strings.DuplicateAnnotationNotAllowed(propertyName)
                    : Strings.DuplicatePropertyNamesNotAllowed(propertyName));
            }

            data.Processed = true;
        }
Example #3
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 #4
0
 public void IsMetadataReferencePropertyShouldReturnFalse()
 {
     ODataJsonLightUtils.IsMetadataReferenceProperty("name").Should().BeFalse();
     ODataJsonLightUtils.IsMetadataReferenceProperty("http://www.example.com/foo").Should().BeFalse();
 }
 public void IsMetadataReferencePropertyShouldReturnFalse()
 {
     Assert.False(ODataJsonLightUtils.IsMetadataReferenceProperty("name"));
     Assert.False(ODataJsonLightUtils.IsMetadataReferenceProperty("http://www.example.com/foo"));
 }