public byte[] Render(string code, OutputFormat outputFormat)
        {
            string urlComponent = GetUrlComponent(code);
            string renderUrl    = urlFormatMap.GetRenderUrl(urlComponent, outputFormat);

            using (HttpClient httpClient = new HttpClient())
            {
                var result = httpClient.GetAsync(renderUrl).Result;

                if (result.IsSuccessStatusCode)
                {
                    return(result.Content.ReadAsByteArrayAsync().Result);
                }

                if (result.StatusCode == HttpStatusCode.BadRequest)
                {
                    var messages = result.Headers.GetValues("X-PlantUML-Diagram-Error");
                    throw new RenderingException(code, string.Join(Environment.NewLine, messages));
                }

                throw new HttpRequestException(result.ReasonPhrase);
            }
        }
Пример #2
0
        public Uri GetRenderUrl(string code, OutputFormat outputFormat)
        {
            string urlComponent = PlantUmlTextEncoding.EncodeUrl(code);

            return(urlFormatMap.GetRenderUrl(urlComponent, outputFormat));
        }