コード例 #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"));
            }
        }
コード例 #2
0
        async Task <ActionResult> Transform(
            Stream outputStream,
            string template)
        {
            string type = null;

            if (!string.IsNullOrWhiteSpace(template))
            {
                var transform = new XslCompiledTransform();
                var xdoc      = await UseXmlReader(template,
                                                   r => XDocument.LoadAsync(r, new LoadOptions {
                }, new CancellationTokenSource().Token));

                using (var r = xdoc.CreateReader())
                    transform.Load(r);

                type = GetXslOutputMediaType(xdoc)
                       ?? SupportedContentTypes.Translate(transform.OutputSettings.OutputMethod);

                using (var readStream = outputStream)
                {
                    outputStream = new MemoryStream();

                    var xmlReader = XmlReader.Create(readStream);
                    var xmlWriter = XmlWriter.Create(outputStream, transform.OutputSettings);
                    transform.Transform(xmlReader, xmlWriter);
                    outputStream.Position = 0;
                }
            }

            return(new FileStreamResult(
                       outputStream,
                       type ?? "text/plain"
                       ));
        }
コード例 #3
0
        public ActionResult GetFile(string name)
        {
            if (_filesService.TryGetFile(name, out var file))
            {
                Response.Headers.Add("location", file.Location);
                var contentType = SupportedContentTypes.GetContentType(file.Name);

                return(File(file.FileStream, contentType));
            }

            return(NotFound());
        }
コード例 #4
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();
            }
        }
コード例 #5
0
 public CacheBatchHandler(HttpServer httpServer) : base(httpServer)
 {
     SupportedContentTypes.Add(TextJson);
     SupportedContentTypes.Add(ApplicationJsonContentType);
 }