internal static HttpStatusCode GetExpectedStatusCode(ODataUri uri, IODataUriEvaluator evaluator) { bool specialStatusCodeIfNull = false; specialStatusCodeIfNull |= uri.IsNamedStream(); specialStatusCodeIfNull |= uri.IsMediaResource(); specialStatusCodeIfNull |= uri.IsEntity(); specialStatusCodeIfNull |= uri.IsEntityReferenceLink(); specialStatusCodeIfNull |= uri.IsPropertyValue(); bool uriIsValue = uri.IsNamedStream() || uri.IsMediaResource(); // For an action it is evaluated specially via the actionresponse verifier, skip eval here if (!uri.IsAction() && specialStatusCodeIfNull && evaluator.Evaluate(uri).IsNull) { if (uriIsValue) { return(HttpStatusCode.NoContent); } else { return(HttpStatusCode.NotFound); } } return(HttpStatusCode.OK); }
private static bool HasETagOnRetrieve(ODataUri uri) { if (uri.ExpandSegments.Any()) { return(false); } if (uri.IsEntity()) { return(true); } if (uri.IsProperty()) { return(true); } if (uri.IsPropertyValue() || uri.IsMediaResource()) { // this covers media-resources as well return(true); } if (uri.IsNamedStream()) { return(true); } return(false); }
internal static string DetermineAcceptType(ODataUri uri, string defaultAcceptType) { if (uri.IsNamedStream() || uri.IsMediaResource()) { return(MimeTypes.Any); } if (uri.IsCount()) { return(MimeTypes.TextPlain); } if (uri.IsPropertyValue()) { string propertyAcceptType = MimeTypes.Any; var propertySegment = uri.Segments[uri.Segments.Count - 2] as PropertySegment; ExceptionUtilities.CheckObjectNotNull(propertySegment, "Cannot get Property segment from uri"); var mimeTypeAnnotation = propertySegment.Property.Annotations.OfType <MimeTypeAnnotation>().SingleOrDefault(); if (mimeTypeAnnotation != null) { propertyAcceptType = mimeTypeAnnotation.MimeTypeValue; } return(propertyAcceptType); } return(defaultAcceptType); }
private string CalculateExpectedETagForEntityOrStream(ODataUri uri, QueryStructuralValue entity) { if (uri.IsMediaResource()) { return(entity.GetDefaultStreamValue().GetExpectedETag()); } if (uri.IsNamedStream()) { var streamSegment = uri.Segments.OfType <NamedStreamSegment>().Last(); return(entity.GetStreamValue(streamSegment.Name).GetExpectedETag()); } return(this.LiteralConverter.ConstructWeakETag(entity)); }
/// <summary> /// Returns the strategy to use for serializing/deserialzing the given content type /// </summary> /// <param name="contentType">The content type</param> /// <param name="uri">The request uri</param> /// <returns>A serialization strategy</returns> public virtual IProtocolFormatStrategy GetStrategy(string contentType, ODataUri uri) { if (uri != null) { // if its a named stream or an MLE, handle the returned payload as a binary stream if (uri.IsNamedStream() || uri.IsMediaResource()) { return(this.BinaryValueStrategy); } // if its a raw $count request, we need to use a different strategy if (uri.IsCount() && IsPlainTextMimeType(contentType)) { return(this.CountStrategy); } } if (IsXmlMimeType(contentType)) { return(this.XmlStrategy); } if (IsJsonMimeType(contentType)) { return(this.JsonStrategy); } if (IsTextBasedMimeType(contentType)) { return(this.TextValueStrategy); } if (IsHtmlFormMimeType(contentType)) { return(this.HtmlFormStrategy); } return(this.BinaryValueStrategy); }
/// <summary> /// Determines whether the request manager should try to resolve the payload's metadata /// </summary> /// <param name="requestUri">The request uri</param> /// <param name="responseStatusCode">The response status code</param> /// <param name="responsePayloadType">The response payload type</param> /// <returns>True if it should resolve the metadata, false otherwise</returns> internal static bool ShouldResolveMetadata(ODataUri requestUri, HttpStatusCode responseStatusCode, ODataPayloadElementType responsePayloadType) { ExceptionUtilities.CheckArgumentNotNull(requestUri, "requestUri"); if (responseStatusCode.IsError()) { return(false); } if (requestUri.IsNamedStream() || requestUri.IsMediaResource()) { return(false); } if (responsePayloadType == ODataPayloadElementType.MetadataPayloadElement || responsePayloadType == ODataPayloadElementType.HtmlErrorPayload || responsePayloadType == ODataPayloadElementType.ODataErrorPayload) { return(false); } return(true); }