Esempio n. 1
0
        /// <summary>
        /// Validates the incoming request that contains the batch request messages.
        /// </summary>
        /// <param name="request">The request containing the batch request messages.</param>
        public virtual void ValidateRequest(HttpRequestMessage request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (request.Content == null)
            {
                throw new HttpResponseException(request.CreateErrorResponse(
                                                    HttpStatusCode.BadRequest,
                                                    "BatchRequestMissingContent"));
            }

            MediaTypeHeaderValue contentType = request.Content.Headers.ContentType;

            if (contentType == null)
            {
                throw new HttpResponseException(request.CreateErrorResponse(
                                                    HttpStatusCode.BadRequest,
                                                    "BatchContentTypeMissing"));
            }

            if (!SupportedContentTypes.Contains(contentType.MediaType, StringComparer.OrdinalIgnoreCase))
            {
                throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.BadRequest, "BatchMediaTypeNotSupported"));
            }
        }
Esempio n. 2
0
        public Serializer(Action <JsonSerializerSettings> settingsAction = null, DataFormat dataFormat = DataFormat.Json, params string[] supportedContentTypes)
        {
            _serializerSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                TypeNameHandling = TypeNameHandling.None,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            settingsAction?.Invoke(_serializerSettings);

            DataFormat            = dataFormat;
            SupportedContentTypes = supportedContentTypes;
            if (!SupportedContentTypes.Contains(JsonContentType))
            {
                SupportedContentTypes = SupportedContentTypes.Union(new[] { JsonContentType }).ToArray();
            }
        }