Beispiel #1
0
        private static void Write(IReadOnlyList <DataPoint> points, ChartWriter.OutputFormat format, string file)
        {
            var writer = new ChartWriter("template.html");
            var stream = writer.Stream(points, format);

            File.Delete(file);
            stream.CopyTo(File.OpenWrite(file));
        }
        private static IHttpActionResult WrapStream(Stream stream, ChartWriter.OutputFormat parsedFormat)
        {
            var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StreamContent(stream)
            };

            httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(GetContentType(parsedFormat));
            return(new ResponseMessageResult(httpResponseMessage));
        }
        private static string GetContentType(ChartWriter.OutputFormat format)
        {
            switch (format)
            {
            case ChartWriter.OutputFormat.Svg:
                return("image/svg+xml");

            case ChartWriter.OutputFormat.Html:
                return("text/html");

            case ChartWriter.OutputFormat.Pdf:
                return("application/pdf");

            default:
                throw new ArgumentOutOfRangeException("format", format, null);
            }
        }