private Version GetMinDataServiceVersion(Version maxProtocolVersion) { if (this.requestMinVersion == null) { this.TryGetMinDataServiceVersionFromWrappedHost(out this.requestMinVersion); if ((maxProtocolVersion < RequestDescription.Version3Dot0) || (this.requestMinVersion == null)) { this.requestMinVersion = RequestDescription.DataServiceDefaultResponseVersion; } else { if (this.requestMinVersion > maxProtocolVersion) { throw DataServiceException.CreateBadRequestError(Strings.DataService_MinDSVGreaterThanMPV(this.requestMinVersion.ToString(2), maxProtocolVersion.ToString(2))); } if (!RequestDescription.IsKnownRequestVersion(this.requestMinVersion)) { throw DataServiceException.CreateBadRequestError(Strings.DataService_InvalidMinDSV(this.requestMinVersion.ToString(2), KnownDataServiceVersionsToString(GetMaxRequestVersionAllowed(maxProtocolVersion)))); } } } return(this.requestMinVersion); }
private void CheckExpandPaths() { if (this.expandPathsAsText.Count > 0) { if (this.queryExpression == null) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryExpandOptionNotApplicable); } if (this.description.TargetResourceType.ResourceTypeKind == ResourceTypeKind.Collection) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryExpandOptionNotApplicable); } } this.expandPaths = new List <ExpandSegmentCollection>(this.expandPathsAsText.Count); for (int i = this.expandPathsAsText.Count - 1; i >= 0; i--) { ExpandSegmentCollection item = this.CheckSingleExpandPath(this.expandPathsAsText[i]); if (item == null) { this.expandPathsAsText.RemoveAt(i); } else { this.expandPaths.Add(item); ExpandedProjectionNode rootProjectionNode = this.GetRootProjectionNode(); for (int j = 0; j < item.Count; j++) { ExpandSegment segment = item[j]; ExpandedProjectionNode node2 = rootProjectionNode.AddExpandedNode(segment); this.GetRootProjectionNode().ExpansionOnDerivedTypesSpecified |= rootProjectionNode.HasExpandedPropertyOnDerivedType; rootProjectionNode = node2; } this.GetRootProjectionNode().ExpansionsSpecified = true; } } }
/// <summary>create exception when boundary delimiter is not valid</summary> /// <param name="delimiter">delimiter specified as specified in the request.</param> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamInvalidDelimiter(string delimiter) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidDelimiter(delimiter)))); }
/// <summary>create exception when end changeset boundary delimiter is missing</summary> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamMissingEndChangesetDelimiter() { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_MissingEndChangesetDelimiter))); }
/// <summary>create exception when operation header is specified in start of changeset</summary> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamInvalidOperationHeaderSpecified() { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidOperationHeaderSpecified))); }
/// <summary>create exception when invalid batch request is specified</summary> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamInvalidBatchFormat() { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidBatchFormat))); }
/// <summary>create exception when more data is specified after end of batch delimiter.</summary> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamMoreDataAfterEndOfBatch() { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_MoreDataAfterEndOfBatch))); }
/// <summary>Creates a new exception to indicate a syntax error.</summary> /// <param name="message">Plain text error message for this exception.</param> /// <returns>A new exception to indicate a syntax error.</returns> internal static DataServiceException CreateSyntaxError(string message) { return(DataServiceException.CreateBadRequestError(message)); }
/// <summary>internal error when content type header is missing</summary> /// <param name="headerName">name of the missing header</param> /// <returns>exception to throw</returns> internal static InvalidOperationException BatchStreamMissingContentTypeHeader(string headerName) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_MissingContentTypeHeader(headerName)))); }
/// <summary>create exception when CUD operation is specified in batch</summary> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamOnlyGETOperationsCanBeSpecifiedInBatch() { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_OnlyGETOperationsCanBeSpecifiedInBatch))); }
/// <summary>internal error Content-Transfer-Encoding is not specified or its value is not 'binary'</summary> /// <param name="headerName">name of the header</param> /// <param name="headerValue">expected value of the header</param> /// <returns>exception to throw</returns> internal static InvalidOperationException BatchStreamMissingOrInvalidContentEncodingHeader(string headerName, string headerValue) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_MissingOrInvalidContentEncodingHeader(headerName, headerValue)))); }
/// <summary>internal error number of headers at the start of changeset is not correct</summary> /// <param name="header1">First valid header name</param> /// <param name="header2">Second valid header name</param> /// <returns>exception to throw</returns> internal static InvalidOperationException BatchStreamInvalidNumberOfHeadersAtChangeSetStart(string header1, string header2) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidNumberOfHeadersAtChangeSetStart(header1, header2)))); }
/// <summary>internal error when http version in batching request is not valid</summary> /// <param name="actualVersion">actual version as specified in the payload.</param> /// <param name="expectedVersion">expected version value.</param> /// <returns>exception to throw</returns> internal static InvalidOperationException BatchStreamInvalidHttpVersionSpecified(string actualVersion, string expectedVersion) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidHttpVersionSpecified(actualVersion, expectedVersion)))); }
/// <summary>internal error where the first request header is not of the form: 'MethodName' 'Url' 'Version'</summary> /// <param name="header">actual header value specified in the payload.</param> /// <returns>exception to throw</returns> internal static InvalidOperationException BatchStreamInvalidMethodHeaderSpecified(string header) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidMethodHeaderSpecified(header)))); }
/// <summary>internal error where batch stream does do look ahead when read request is smaller than boundary delimiter</summary> /// <returns>exception to throw</returns> internal static InvalidOperationException BatchStreamInternalBufferRequestTooSmall() { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InternalBufferRequestTooSmall))); }
/// <summary>create exception when header value specified is not valid</summary> /// <param name="headerValue">header value as specified in the request.</param> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamInvalidHeaderValueSpecified(string headerValue) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidHeaderValueSpecified(headerValue)))); }
private ExpandSegmentCollection CheckSingleExpandPath(List <string> path) { ResourceType targetResourceType = this.description.TargetResourceType; ResourceSetWrapper targetContainer = this.description.LastSegmentInfo.TargetContainer; ExpandSegmentCollection segments = new ExpandSegmentCollection(path.Count); bool flag = false; bool previousSegmentIsTypeSegment = false; for (int i = 0; i < path.Count; i++) { string propertyName = path[i]; ResourcePropertyKind stream = ResourcePropertyKind.Stream; ResourceProperty navigationProperty = targetResourceType.TryResolvePropertyName(propertyName, stream); if (navigationProperty == null) { ResourceType type2 = WebUtil.ResolveTypeIdentifier(this.service.Provider, propertyName, targetResourceType, previousSegmentIsTypeSegment); if (type2 == null) { if (targetResourceType.IsOpenType) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(propertyName)); } throw DataServiceException.CreateSyntaxError(System.Data.Services.Strings.RequestUriProcessor_PropertyNotFound(targetResourceType.FullName, propertyName)); } this.description.VerifyProtocolVersion(RequestDescription.Version3Dot0, this.service); targetResourceType = type2; previousSegmentIsTypeSegment = true; } else { previousSegmentIsTypeSegment = false; if (navigationProperty.TypeKind == ResourceTypeKind.EntityType) { targetContainer = this.service.Provider.GetContainer(targetContainer, targetResourceType, navigationProperty); if (targetContainer == null) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.BadRequest_InvalidPropertyNameSpecified(navigationProperty.Name, targetResourceType.FullName)); } bool singleResult = navigationProperty.Kind == ResourcePropertyKind.ResourceReference; DataServiceConfiguration.CheckResourceRightsForRead(targetContainer, singleResult); Expression filter = DataServiceConfiguration.ComposeQueryInterceptors(this.service, targetContainer); if (((targetContainer.PageSize != 0) && !singleResult) && !this.IsCustomPaged) { OrderingInfo orderingInfo = new OrderingInfo(true); ParameterExpression expression = Expression.Parameter(targetContainer.ResourceType.InstanceType, "p"); foreach (ResourceProperty property2 in targetContainer.GetKeyPropertiesForOrderBy()) { Expression expression3; if (property2.CanReflectOnInstanceTypeProperty) { expression3 = Expression.Property(expression, targetContainer.ResourceType.GetPropertyInfo(property2)); } else { expression3 = Expression.Convert(Expression.Call(null, DataServiceProviderMethods.GetValueMethodInfo, expression, Expression.Constant(property2)), property2.Type); } orderingInfo.Add(new OrderingExpression(Expression.Lambda(expression3, new ParameterExpression[] { expression }), true)); } segments.Add(new ExpandSegment(navigationProperty.Name, filter, targetContainer.PageSize, targetContainer, targetResourceType, navigationProperty, orderingInfo)); this.description.VerifyProtocolVersion(RequestDescription.Version2Dot0, this.service); this.description.VerifyAndRaiseResponseVersion(RequestDescription.Version2Dot0, this.service); } else { if (!singleResult && this.IsCustomPaged) { this.CheckAndApplyCustomPaging(null); } segments.Add(new ExpandSegment(navigationProperty.Name, filter, this.service.Configuration.MaxResultsPerCollection, targetContainer, targetResourceType, navigationProperty, null)); } this.description.UpdateAndCheckEpmFeatureVersion(targetContainer, this.service); this.description.UpdateVersions(this.service.OperationContext.Host.RequestAccept, targetContainer, this.service); flag = false; targetResourceType = navigationProperty.ResourceType; } else { flag = true; } } } if (previousSegmentIsTypeSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryParametersPathCannotEndInTypeIdentifier("$expand", targetResourceType.FullName)); } if (!flag) { return(segments); } return(null); }
/// <summary>create exception when content length is not valid</summary> /// <param name="contentLength">content length as specified in the request.</param> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamInvalidContentLengthSpecified(string contentLength) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidContentLengthSpecified(contentLength)))); }
/// <summary>Creates a new "Bad Request" exception for recursion limit exceeded.</summary> /// <param name="recursionLimit">Recursion limit that was reaced.</param> /// <returns>A new exception to indicate that the request is rejected.</returns> internal static DataServiceException CreateDeepRecursion(int recursionLimit) { return(DataServiceException.CreateBadRequestError(Strings.BadRequest_DeepRecursion(recursionLimit))); }
/// <summary>internal error when content type header value is invalid.</summary> /// <param name="headerName">name of the header whose value is not correct.</param> /// <param name="headerValue">actual value as specified in the payload</param> /// <param name="mime1">expected value 1</param> /// <param name="mime2">expected value 2</param> /// <returns>exception to throw</returns> internal static InvalidOperationException BatchStreamInvalidContentTypeSpecified(string headerName, string headerValue, string mime1, string mime2) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidContentTypeSpecified(headerName, headerValue, mime1, mime2)))); }
/// <summary>create exception when http method name is not valid</summary> /// <param name="methodName">name of the http method as specified in the request.</param> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamInvalidHttpMethodName(string methodName) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_InvalidHttpMethodName(methodName)))); }
private void ApplyProjectionsToExpandTree(List <List <string> > selectPathsAsText) { for (int i = selectPathsAsText.Count - 1; i >= 0; i--) { List <string> list = selectPathsAsText[i]; ExpandedProjectionNode rootProjectionNode = this.GetRootProjectionNode(); ResourceType type = null; for (int j = 0; j < list.Count; j++) { bool flag2; string containerQualifiedName = list[j]; bool lastPathSegment = j == (list.Count - 1); rootProjectionNode.ProjectionFound = true; if (containerQualifiedName == "*") { rootProjectionNode.ProjectAllImmediateProperties = true; break; } if (this.service.Provider.GetNameFromContainerQualifiedName(containerQualifiedName, out flag2) == "*") { rootProjectionNode.ProjectAllImmediateOperations = true; break; } ResourceType previousSegmentResourceType = type ?? rootProjectionNode.ResourceType; ResourceProperty property = previousSegmentResourceType.TryResolvePropertyName(containerQualifiedName); if (property == null) { type = WebUtil.ResolveTypeIdentifier(this.service.Provider, containerQualifiedName, previousSegmentResourceType, type != null); if (type != null) { this.description.VerifyProtocolVersion(RequestDescription.Version3Dot0, this.service); continue; } Func <OperationWrapper, bool> predicate = null; string serviceActionName = this.service.Provider.GetNameFromContainerQualifiedName(containerQualifiedName, out flag2); OperationWrapper operation = null; if (!previousSegmentResourceType.IsOpenType || flag2) { if (predicate == null) { predicate = o => o.Name == serviceActionName; } operation = this.service.ActionProvider.GetServiceActionsByBindingParameterType(this.service.OperationContext, previousSegmentResourceType).SingleOrDefault <OperationWrapper>(predicate); } if (operation != null) { rootProjectionNode.AddOperation(operation); if (!lastPathSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_ServiceActionMustBeLastSegmentInSelect(containerQualifiedName)); } continue; } if (!previousSegmentResourceType.IsOpenType) { throw DataServiceException.CreateSyntaxError(System.Data.Services.Strings.RequestUriProcessor_PropertyNotFound(previousSegmentResourceType.FullName, containerQualifiedName)); } if (!lastPathSegment) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.OpenNavigationPropertiesNotSupportedOnOpenTypes(containerQualifiedName)); } } rootProjectionNode = ApplyProjectionForProperty(rootProjectionNode, containerQualifiedName, property, previousSegmentResourceType, lastPathSegment); type = null; } if (type != null) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryProcessor_QueryParametersPathCannotEndInTypeIdentifier("$select", type.FullName)); } } }
/// <summary>create exception when missing an expected batch boundary</summary> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamMissingBoundary() { return(Trace(DataServiceException.CreateBadRequestError(Strings.DataService_InvalidContentTypeForBatchRequest))); }
/// <summary>Creates a new "Bad Request" exception for recursion limit exceeded.</summary> /// <returns>A new exception to indicate that the request is rejected.</returns> internal static DataServiceException CreateDeepRecursion_General() { return(DataServiceException.CreateBadRequestError(Strings.BadRequest_DeepRecursion_General)); }
/// <summary>create exception when unexpected content is discovered</summary> /// <param name="state">http method operation</param> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamContentUnexpected(BatchStreamState state) { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_ContentUnexpected(state.ToString())))); }
/// <summary> /// If the provider implements IConcurrencyProvider, then this method passes the etag values /// to the provider, otherwise compares the etag itself. /// </summary> /// <param name="resourceCookie">etag values for the given resource.</param> /// <param name="container">container for the given resource.</param> internal void SetETagValues(object resourceCookie, ResourceSetWrapper container) { Debug.Assert(resourceCookie != null, "resourceCookie != null"); Debug.Assert(container != null, "container != null"); DataServiceHostWrapper host = this.service.OperationContext.Host; Debug.Assert(String.IsNullOrEmpty(host.RequestIfNoneMatch), "IfNoneMatch header cannot be specified for Update/Delete operations"); // Resolve the cookie first to the actual resource type object actualEntity = this.ResolveResource(resourceCookie); Debug.Assert(actualEntity != null, "actualEntity != null"); ResourceType resourceType = WebUtil.GetNonPrimitiveResourceType(this.service.Provider, actualEntity); Debug.Assert(resourceType != null, "resourceType != null"); IList <ResourceProperty> etagProperties = this.service.Provider.GetETagProperties(container.Name, resourceType); if (etagProperties.Count == 0) { if (!String.IsNullOrEmpty(host.RequestIfMatch)) { throw DataServiceException.CreateBadRequestError(Strings.Serializer_NoETagPropertiesForType); } // If the type has no etag properties, then we do not need to do any etag checks return; } // If the provider implements IConcurrencyProvider, then we need to call the provider // and pass the etag values. Else, we need to compare the etag values ourselves. IDataServiceUpdateProvider concurrencyProvider = this.updateProvider as IDataServiceUpdateProvider; if (concurrencyProvider != null) { bool?checkForEquality = null; IEnumerable <KeyValuePair <string, object> > etagValues = null; if (!String.IsNullOrEmpty(host.RequestIfMatch)) { checkForEquality = true; etagValues = ParseETagValue(etagProperties, host.RequestIfMatch); } else { etagValues = new KeyValuePair <string, object> [0]; } concurrencyProvider.SetConcurrencyValues(resourceCookie, checkForEquality, etagValues); } else if (String.IsNullOrEmpty(host.RequestIfMatch)) { throw DataServiceException.CreateBadRequestError(Strings.DataService_CannotPerformOperationWithoutETag(resourceType.FullName)); } else if (host.RequestIfMatch != XmlConstants.HttpAnyETag) { // Compare If-Match header value with the current etag value, if the If-Match header value is not equal to '*' string etagValue = WebUtil.GetETagValue(resourceCookie, resourceType, etagProperties, this.service, false /*getMethod*/); Debug.Assert(!String.IsNullOrEmpty(etagValue), "etag value can never be null"); if (etagValue != host.RequestIfMatch) { throw DataServiceException.CreatePreConditionFailedError(Strings.Serializer_ETagValueDoesNotMatch); } } }
/// <summary>create exception when Get operation is specified in changeset</summary> /// <returns>exception to throw</returns> internal static DataServiceException BatchStreamGetMethodNotSupportInChangeset() { return(Trace(DataServiceException.CreateBadRequestError(Strings.BatchStream_GetMethodNotSupportedInChangeset))); }