/// <summary> /// Validates a named stream to ensure it's not null and it's name if correct. /// </summary> /// <param name="namedStream">The named stream to validate.</param> /// <param name="version">The version of the OData protocol used for checking.</param> internal static void ValidateNamedStream(ODataMediaResource namedStream, ODataVersion version) { DebugUtils.CheckNoExternalCallers(); ODataVersionChecker.CheckNamedStreams(version); if (namedStream == null) { throw new ODataException(Strings.ODataWriter_NamedStreamMustNotBeNull); } if (string.IsNullOrEmpty(namedStream.Name)) { throw new ODataException(Strings.ODataWriter_NamedStreamMustHaveNonEmptyName); } }
/// <summary> /// Starts writing a feed /// </summary> /// <param name="feed">The feed to write.</param> private void WriteStartImplementation(ODataFeed feed) { // Verify inline count if (feed.Count.HasValue) { // Check that Count is not set for expanded links if (!this.IsTopLevel) { throw new ODataException(Strings.ODataWriterCore_OnlyTopLevelFeedsSupportInlineCount); } // Check that Count is not set for requests if (!this.WritingResponse) { this.ThrowODataException(Strings.ODataWriterCore_InlineCountInRequest, feed); } // Verify version requirements ODataVersionChecker.CheckInlineCount(this.Version); } this.StartFeed(feed); }
/// <summary> /// Validates an <see cref="ODataFeed"/> to ensure all required information is specified and valid. /// </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 ValidateFeed(ODataFeed feed, bool writingRequest, ODataVersion version) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(feed != null, "feed != null"); // Verify non-empty ID if (string.IsNullOrEmpty(feed.Id)) { throw new ODataException(Strings.ODataWriter_FeedsMustHaveNonEmptyId); } // Verify next link if (feed.NextPageLink != null) { // Check that NextPageLink is not set for requests if (writingRequest) { throw new ODataException(Strings.ODataWriterCore_NextPageLinkInRequest); } // Verify version requirements ODataVersionChecker.CheckServerPaging(version); } }
/// <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> internal static void ValidateAssociationLink(ODataAssociationLink associationLink, ODataVersion version) { DebugUtils.CheckNoExternalCallers(); ODataVersionChecker.CheckAssociationLinks(version); // null link can not appear in the enumeration if (associationLink == null) { throw new ODataException(Strings.ODataWriter_AssociationLinkMustNotBeNull); } // Association link must have a non-empty name if (string.IsNullOrEmpty(associationLink.Name)) { throw new ODataException(Strings.ODataWriter_AssociationLinkMustSpecifyName); } // Association link must specify the Url if (associationLink.Url == null) { throw new ODataException(Strings.ODataWriter_AssociationLinkMustSpecifyUrl); } }