/// <summary> /// Validates an <see cref="ODataFeed"/> to ensure all required information is specified and valid on the WriteEnd call. /// </summary> /// <param name="feed">The feed to validate.</param> /// <param name="writingRequest">Flag indicating whether the feed is written as part of a request or a response.</param> public void ValidateFeedAtEnd(ODataFeed feed, bool writingRequest) { WriterValidationUtils.ValidateFeedAtEnd(feed, writingRequest); }
internal static IEdmNavigationProperty ValidateNavigationLink( ODataNavigationLink navigationLink, IEdmEntityType declaringEntityType, ODataPayloadKind?expandedPayloadKind, bool bypassValidation = false) { Debug.Assert(navigationLink != null, "navigationLink != null"); Debug.Assert( !expandedPayloadKind.HasValue || expandedPayloadKind.Value == ODataPayloadKind.EntityReferenceLink || expandedPayloadKind.Value == ODataPayloadKind.Entry || expandedPayloadKind.Value == ODataPayloadKind.Feed, "If an expanded payload kind is specified it must be entry, feed or entity reference link."); if (bypassValidation) { return(declaringEntityType == null ? null : declaringEntityType.FindProperty(navigationLink.Name) as IEdmNavigationProperty); } // Navigation link must have a non-empty name if (string.IsNullOrEmpty(navigationLink.Name)) { throw new ODataException(Strings.ValidationUtils_LinkMustSpecifyName); } // If we write an entity reference link, don't validate the multiplicity of the IsCollection // property if it is 'false' (since we allow writing a singleton navigation link for // a collection navigation property in requests) nor the consistency of payload kind and metadata // (which is done separately in ODataWriterCore.CheckForNavigationLinkWithContent). bool isEntityReferenceLinkPayload = expandedPayloadKind == ODataPayloadKind.EntityReferenceLink; // true only if the expandedPayloadKind has a value and the value is 'Feed' bool isFeedPayload = expandedPayloadKind == ODataPayloadKind.Feed; // Make sure the IsCollection property agrees with the payload kind for entry and feed payloads Func <object, string> errorTemplate = null; if (!isEntityReferenceLinkPayload && navigationLink.IsCollection.HasValue && expandedPayloadKind.HasValue) { // For feed/entry make sure the IsCollection property is set correctly. if (isFeedPayload != navigationLink.IsCollection.Value) { errorTemplate = expandedPayloadKind.Value == ODataPayloadKind.Feed ? (Func <object, string>)Strings.WriterValidationUtils_ExpandedLinkIsCollectionFalseWithFeedContent : Strings.WriterValidationUtils_ExpandedLinkIsCollectionTrueWithEntryContent; } } IEdmNavigationProperty navigationProperty = null; if (errorTemplate == null && declaringEntityType != null) { navigationProperty = WriterValidationUtils.ValidateNavigationPropertyDefined(navigationLink.Name, declaringEntityType); Debug.Assert(navigationProperty != null, "If we have a declaring type we expect a non-null navigation property since open nav props are not allowed."); bool isCollectionType = navigationProperty.Type.TypeKind() == EdmTypeKind.Collection; // Make sure the IsCollection property agrees with the metadata type for entry and feed payloads if (navigationLink.IsCollection.HasValue && isCollectionType != navigationLink.IsCollection) { // Ignore the case where IsCollection is 'false' and we are writing an entity reference link // (see comment above) if (!(navigationLink.IsCollection == false && isEntityReferenceLinkPayload)) { errorTemplate = isCollectionType ? (Func <object, string>)Strings.WriterValidationUtils_ExpandedLinkIsCollectionFalseWithFeedMetadata : Strings.WriterValidationUtils_ExpandedLinkIsCollectionTrueWithEntryMetadata; } } // Make sure that the payload kind agrees with the metadata. // For entity reference links we check separately in ODataWriterCore.CheckForNavigationLinkWithContent. if (!isEntityReferenceLinkPayload && expandedPayloadKind.HasValue && isCollectionType != isFeedPayload) { errorTemplate = isCollectionType ? (Func <object, string>)Strings.WriterValidationUtils_ExpandedLinkWithEntryPayloadAndFeedMetadata : Strings.WriterValidationUtils_ExpandedLinkWithFeedPayloadAndEntryMetadata; } } if (errorTemplate != null) { string uri = navigationLink.Url == null ? "null" : UriUtils.UriToString(navigationLink.Url); throw new ODataException(errorTemplate(uri)); } return(navigationProperty); }
/// <summary> /// Validates an entry in an expanded link to make sure the entity types match. /// </summary> /// <param name="entryEntityType">The <see cref="IEdmEntityType"/> of the entry.</param> /// <param name="parentNavigationPropertyType">The type of the parent navigation property.</param> public void ValidateEntryInExpandedLink(IEdmEntityType entryEntityType, IEdmEntityType parentNavigationPropertyType) { WriterValidationUtils.ValidateEntryInExpandedLink(entryEntityType, parentNavigationPropertyType); }
/// <summary> /// Validates that an <see cref="ODataOperation"/> can be written. /// </summary> /// <param name="operation">The operation (an action or a function) to validate.</param> /// <param name="writingResponse">true if writing a response; otherwise false.</param> public void ValidateCanWriteOperation(ODataOperation operation, bool writingResponse) { WriterValidationUtils.ValidateCanWriteOperation(operation, writingResponse); }
/// <summary> /// Validates a property name to ensure all required information is specified. /// </summary> /// <param name="propertyName">The property name to validate.</param> public void ValidatePropertyName(string propertyName) { WriterValidationUtils.ValidatePropertyName(propertyName); }
/// <summary> /// Validates that a navigation property with the specified name exists on a given entity type. /// The entity type can be null if no metadata is available. /// </summary> /// <param name="propertyName">The name of the property to validate.</param> /// <param name="owningEntityType">The owning entity type or null if no metadata is available.</param> /// <returns>The <see cref="IEdmProperty"/> instance representing the navigation property with name <paramref name="propertyName"/> /// or null if no metadata is available.</returns> public IEdmNavigationProperty ValidateNavigationPropertyDefined(string propertyName, IEdmEntityType owningEntityType) { return(WriterValidationUtils.ValidateNavigationPropertyDefined(propertyName, owningEntityType)); }
/// <summary> /// Validates that the expected property allows null value. /// </summary> /// <param name="expectedPropertyTypeReference">The expected property type or null if we don't have any.</param> /// <param name="propertyName">The name of the property.</param> /// <param name="writerBehavior">The <see cref="ODataWriterBehavior"/> instance controlling the behavior of the writer.</param> /// <param name="model">The model to use to get the OData version.</param> public void ValidateNullPropertyValue(IEdmTypeReference expectedPropertyTypeReference, string propertyName, ODataWriterBehavior writerBehavior, IEdmModel model) { WriterValidationUtils.ValidateNullPropertyValue(expectedPropertyTypeReference, propertyName, writerBehavior, model); }
/// <summary> /// Validates an <see cref="ODataProperty"/> for not being null. /// </summary> /// <param name="property">The property to validate for not being null.</param> public void ValidatePropertyNotNull(ODataProperty property) { WriterValidationUtils.ValidatePropertyNotNull(property); }
/// <summary> /// Validates that message writer settings are correct. /// </summary> /// <param name="messageWriterSettings">The message writer settings to validate.</param> /// <param name="writingResponse">True if we are writing a response.</param> public void ValidateMessageWriterSettings(ODataMessageWriterSettings messageWriterSettings, bool writingResponse) { WriterValidationUtils.ValidateMessageWriterSettings(messageWriterSettings, writingResponse); }
/// <summary> /// Validates that the sepcified navigation link has cardinality, that is it has the IsCollection value set. /// </summary> /// <param name="navigationLink">The navigation link to validate.</param> public void ValidateNavigationLinkHasCardinality(ODataNavigationLink navigationLink) { WriterValidationUtils.ValidateNavigationLinkHasCardinality(navigationLink); }
/// <summary> /// Validates that the specified navigation link has a Url. /// </summary> /// <param name="navigationLink">The navigation link to validate.</param> public void ValidateNavigationLinkUrlPresent(ODataNavigationLink navigationLink) { WriterValidationUtils.ValidateNavigationLinkUrlPresent(navigationLink); }
/// <summary> /// Validates an entity reference link instance. /// </summary> /// <param name="entityReferenceLink">The entity reference link to validate.</param> public void ValidateEntityReferenceLink(ODataEntityReferenceLink entityReferenceLink) { WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink); }
/// <summary> /// Validates a named stream property to ensure it's not null and it's name if correct. /// </summary> /// <param name="streamProperty">The stream reference property to validate.</param> /// <param name="edmProperty">Property metadata to validate against.</param> /// <param name="writingResponse">true when writing a response; otherwise false.</param> /// <remarks>This does NOT validate the value of the stream property, just the property itself.</remarks> public void ValidateStreamReferenceProperty(ODataProperty streamProperty, IEdmProperty edmProperty, bool writingResponse) { WriterValidationUtils.ValidateStreamReferenceProperty(streamProperty, edmProperty, writingResponse); }
/// <summary> /// Validates an <see cref="ODataStreamReferenceValue"/> to ensure all required information is specified and valid. /// </summary> /// <param name="streamReference">The stream reference to validate.</param> /// <param name="isDefaultStream">true if <paramref name="streamReference"/> is the default stream for an entity; false if it is a named stream property value.</param> public void ValidateStreamReferenceValue(ODataStreamReferenceValue streamReference, bool isDefaultStream) { WriterValidationUtils.ValidateStreamReferenceValue(streamReference, isDefaultStream); }
/// <summary> /// Validates an <see cref="ODataEntry"/> to ensure all required information is specified and valid on WriteEnd call. /// </summary> /// <param name="entry">The entry to validate.</param> public void ValidateEntryAtEnd(ODataEntry entry) { WriterValidationUtils.ValidateEntryAtEnd(entry); }