예제 #1
0
 public static void WriteDataUris(StringBuilder sb, List <string> dataUris)
 {
     foreach (var name in dataUris)
     {
         AppendEntry(sb, name, Svg.GetDataUri(name));
     }
 }
예제 #2
0
        public override async Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName)
        {
            var svg = Svg.GetImage(Id, Fill);

            if (svg == null)
            {
                httpRes.StatusCode        = 404;
                httpRes.StatusDescription = "SVG Image was not found";
            }
            else if (Format == "svg")
            {
                httpRes.ContentType = MimeTypes.ImageSvg;
                await httpRes.WriteAsync(svg);
            }
            else if (Format == "css")
            {
                httpRes.ContentType = "text/css";
                var css = $".svg-{Id} {{\n  {Svg.InBackgroundImageCss(Svg.GetImage(Id, Fill))}\n}}\n";
                await httpRes.WriteAsync(css);
            }
            else if (Format == "datauri")
            {
                var dataUri = Svg.GetDataUri(Id, Fill);
                httpRes.ContentType = MimeTypes.PlainText;
                await httpRes.WriteAsync(dataUri);
            }
            else
            {
                httpRes.StatusCode        = 400;
                httpRes.StatusDescription = "Unknown format, valid formats: svg, css, datauri";
            }
            httpRes.EndRequest();
        }