Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PlantUmlDocumentToImageConverter.cs
1using System;
2using System.IO;
3using System.Threading.Tasks;
6
8{
13 {
18 {
19 }
20
24 public string[] FromContentTypes => new string[] { PlantUmlCodec.DefaultContentType };
25
29 public virtual string[] ToContentTypes
30 {
31 get
32 {
33 return new string[]
34 {
36 ImageCodec.ContentTypeSvg
37 };
38 }
39 }
40
44 public virtual Grade ConversionGrade => Grade.Excellent;
45
51 public async Task<bool> ConvertAsync(ConversionState State)
52 {
53 string GraphDescription;
54
55 using (StreamReader rd = new StreamReader(State.From))
56 {
57 GraphDescription = rd.ReadToEnd();
58 }
59
60 string s = State.ToContentType;
61 int i;
62
63 i = s.IndexOf(';');
64 if (i > 0)
65 s = s.Substring(0, i);
66
67 bool Png = string.Compare(s, ImageCodec.ContentTypePng, true) == 0;
68 bool Svg = string.Compare(s, ImageCodec.ContentTypeSvg, true) == 0;
69
70 if (!(State.PossibleContentTypes is null))
71 {
72 foreach (string ContentType in State.PossibleContentTypes)
73 {
74 s = ContentType;
75 i = s.IndexOf(';');
76 if (i > 0)
77 s = s.Substring(0, i);
78
79 Png |= string.Compare(s, ImageCodec.ContentTypePng, true) == 0;
80 Svg |= string.Compare(s, ImageCodec.ContentTypeSvg, true) == 0;
81 }
82 }
83
84 GraphInfo Graph;
85
86 if (Svg)
87 {
88 Graph = await PlantUml.GetGraphInfo("uml", GraphDescription, ResultType.Svg, true);
89 State.ToContentType = ImageCodec.ContentTypeSvg;
90 }
91 else if (Png)
92 {
93 Graph = await PlantUml.GetGraphInfo("uml", GraphDescription, ResultType.Png, true);
94 State.ToContentType = ImageCodec.ContentTypePng;
95 }
96 else
97 {
98 State.Error = new Exception("Unable to convert document from " + State.FromContentType + " to " + State.ToContentType);
99 return false;
100 }
101
102 byte[] Data = await Runtime.IO.Files.ReadAllBytesAsync(Graph.ImageFileName);
103
104 await State.To.WriteAsync(Data, 0, Data.Length);
105
106 return false;
107 }
108
109 }
110}
Contains the state of a content conversion process.
string ToContentType
Content type of the content to convert to. This value might be changed, in case the converter finds a...
string[] PossibleContentTypes
Possible content types the converter is allowed to convert to. Can be null if there are no alternativ...
string FromContentType
Content type of the content to convert from.
Stream To
Stream pointing to where binary representation of content is to be sent.
Stream From
Stream pointing to binary representation of content.
Image encoder/decoder.
Definition: ImageCodec.cs:14
const string ContentTypePng
image/png
Definition: ImageCodec.cs:30
const string ContentTypeSvg
image/svg+xml
Definition: ImageCodec.cs:45
virtual string[] ToContentTypes
Converts content to these content types.
async Task< bool > ConvertAsync(ConversionState State)
Performs the actual conversion.
Class managing PlantUML integration into Markdown documents.
Definition: PlantUml.cs:56
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...
Grade
Grade enumeration
Definition: Grade.cs:7