/// <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> /// <param name="version">The version of the OData protocol used for checking.</param> internal static void ValidateFeedAtEnd(ODataFeed feed, bool writingRequest, ODataVersion version) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(feed != null, "feed != null"); // Verify next link if (feed.NextPageLink != null) { // Check that NextPageLink is not set for requests if (writingRequest) { throw new ODataException(Strings.WriterValidationUtils_NextPageLinkInRequest); } // Verify version requirements ODataVersionChecker.CheckNextLink(version); } // Verify Delta link, writingRequest is not verfied in order to be consistent with the behavior in Json. if (feed.DeltaLink != null) { // Verify version requirements ODataVersionChecker.CheckDeltaLink(version); } }
private void WriteStartFeedImplementation(ODataFeed feed) { Action action = null; this.CheckForNavigationLinkWithContent(ODataPayloadKind.Feed); this.EnterScope(WriterState.Feed, feed); if (!this.SkipWriting) { if (action == null) { action = delegate { WriterValidationUtils.ValidateFeedAtStart(feed); if (feed.Count.HasValue) { if (!this.IsTopLevel) { throw new ODataException(Microsoft.Data.OData.Strings.ODataWriterCore_OnlyTopLevelFeedsSupportInlineCount); } if (!this.outputContext.WritingResponse) { this.ThrowODataException(Microsoft.Data.OData.Strings.ODataWriterCore_InlineCountInRequest, feed); } ODataVersionChecker.CheckCount(this.outputContext.Version); } this.StartFeed(feed); }; } this.InterceptException(action); } }
internal static void ValidateAssociationLink(ODataAssociationLink associationLink, ODataVersion version, bool writingResponse) { ODataVersionChecker.CheckAssociationLinks(version); if (!writingResponse) { throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_AssociationLinkInRequest(associationLink.Name)); } ValidationUtils.ValidateAssociationLink(associationLink); }
private void VerifyEntityReferenceLinksHeaders(ODataEntityReferenceLinks links) { if (links.Count.HasValue) { ODataVersionChecker.CheckCount(this.settings.Version.Value); } if (links.NextPageLink != null) { ODataVersionChecker.CheckNextLink(this.settings.Version.Value); } }
internal static void ValidateFeedAtEnd(ODataFeed feed, bool writingRequest, ODataVersion version) { if (feed.NextPageLink != null) { if (writingRequest) { throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_NextPageLinkInRequest); } ODataVersionChecker.CheckNextLink(version); } }
internal static void ValidateStreamReferenceProperty(ODataProperty streamProperty, IEdmProperty edmProperty, ODataVersion version, bool writingResponse) { ODataVersionChecker.CheckStreamReferenceProperty(version); ValidationUtils.ValidateStreamReferenceProperty(streamProperty, edmProperty); if (!writingResponse) { throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_StreamPropertyInRequest(streamProperty.Name)); } ODataStreamReferenceValue streamReference = (ODataStreamReferenceValue)streamProperty.Value; ValidateStreamReferenceValue(streamReference, false); }
/// <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="version">The version of the OData protocol used for checking.</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> internal static void ValidateStreamReferenceProperty(ODataProperty streamProperty, IEdmProperty edmProperty, ODataVersion version, bool writingResponse) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(streamProperty != null, "streamProperty != null"); ODataVersionChecker.CheckStreamReferenceProperty(version); ValidationUtils.ValidateStreamReferenceProperty(streamProperty, edmProperty); if (!writingResponse) { throw new ODataException(Strings.WriterValidationUtils_StreamPropertyInRequest(streamProperty.Name)); } }
public ODataMessageReader(IODataResponseMessage responseMessage, ODataMessageReaderSettings settings, IEdmModel model) { this.readerPayloadKind = ODataPayloadKind.Unsupported; ExceptionUtils.CheckArgumentNotNull <IODataResponseMessage>(responseMessage, "responseMessage"); this.settings = (settings == null) ? new ODataMessageReaderSettings() : new ODataMessageReaderSettings(settings); ReaderValidationUtils.ValidateMessageReaderSettings(this.settings, true); this.readingResponse = true; this.message = new ODataResponseMessage(responseMessage, false, this.settings.DisableMessageStreamDisposal, this.settings.MessageQuotas.MaxReceivedMessageSize); this.urlResolver = responseMessage as IODataUrlResolver; this.version = ODataUtilsInternal.GetDataServiceVersion(this.message, this.settings.MaxProtocolVersion); this.model = model ?? EdmCoreModel.Instance; ODataVersionChecker.CheckVersionSupported(this.version, this.settings); }
private void VerifyCanCreateODataParameterReader(IEdmFunctionImport functionImport) { this.VerifyReaderNotDisposedAndNotUsed(); if (this.readingResponse) { throw new ODataException(Microsoft.Data.OData.Strings.ODataMessageReader_ParameterPayloadInResponse); } ODataVersionChecker.CheckParameterPayload(this.version); if ((functionImport != null) && !this.model.IsUserModel()) { throw new ArgumentException(Microsoft.Data.OData.Strings.ODataMessageReader_FunctionImportSpecifiedWithoutMetadata("functionImport"), "functionImport"); } }
/// <summary> /// Validates an <see cref="ODataAssociationLink"/> to ensure all required information is specified and valid. /// </summary> /// <param name="associationLink">The association link to validate.</param> /// <param name="version">The version of the OData protocol used for checking.</param> /// <param name="writingResponse">true if we are writing a response; otherwise false.</param> internal static void ValidateAssociationLink(ODataAssociationLink associationLink, ODataVersion version, bool writingResponse) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(associationLink != null, "associationLink != null"); ODataVersionChecker.CheckAssociationLinks(version); if (!writingResponse) { throw new ODataException(Strings.WriterValidationUtils_AssociationLinkInRequest(associationLink.Name)); } ValidationUtils.ValidateAssociationLink(associationLink); }
internal static void ValidateTypeSupported(IEdmTypeReference typeReference, ODataVersion version) { if (typeReference != null) { if (typeReference.IsNonEntityODataCollectionTypeKind()) { ODataVersionChecker.CheckCollectionValue(version); } else if (typeReference.IsSpatial()) { ODataVersionChecker.CheckSpatialValue(version); } } }
internal static void ValidateMessageReaderSettings(ODataMessageReaderSettings messageReaderSettings, bool readingResponse) { if ((messageReaderSettings.BaseUri != null) && !messageReaderSettings.BaseUri.IsAbsoluteUri) { throw new ODataException(Microsoft.Data.OData.Strings.ReaderValidationUtils_MessageReaderSettingsBaseUriMustBeNullOrAbsolute(UriUtilsCommon.UriToString(messageReaderSettings.BaseUri))); } if (!readingResponse && (messageReaderSettings.UndeclaredPropertyBehaviorKinds != ODataUndeclaredPropertyBehaviorKinds.None)) { throw new ODataException(Microsoft.Data.OData.Strings.ReaderValidationUtils_UndeclaredPropertyBehaviorKindSpecifiedOnRequest); } if (!string.IsNullOrEmpty(messageReaderSettings.ReaderBehavior.ODataTypeScheme) && !string.Equals(messageReaderSettings.ReaderBehavior.ODataTypeScheme, "http://schemas.microsoft.com/ado/2007/08/dataservices/scheme")) { ODataVersionChecker.CheckCustomTypeScheme(messageReaderSettings.MaxProtocolVersion); } if (!string.IsNullOrEmpty(messageReaderSettings.ReaderBehavior.ODataNamespace) && !string.Equals(messageReaderSettings.ReaderBehavior.ODataNamespace, "http://schemas.microsoft.com/ado/2007/08/dataservices")) { ODataVersionChecker.CheckCustomDataNamespace(messageReaderSettings.MaxProtocolVersion); } }
private void VerifyODataParameterWriterHeaders() { ODataVersionChecker.CheckParameterPayload(this.settings.Version.Value); }