Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
IoTIdCodeBlock.cs
3using System.Globalization;
4using System.Text;
5using System.Xml;
10
12{
17 {
18 private MarkdownDocument? document;
19
24 {
25 }
26
30 public MarkdownDocument? Document => this.document;
31
35 public bool EvaluatesScript => false;
36
40 public async Task<bool> RenderMauiXaml(MauiXamlRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
41 {
42 XmlWriter Output = Renderer.XmlOutput;
43 LegalIdentity Identity;
44
45 try
46 {
47 StringBuilder sb = new();
48
49 foreach (string Row in Rows)
50 sb.AppendLine(Row);
51
52 XmlDocument Doc = new()
53 {
54 PreserveWhitespace = true
55 };
56 Doc.LoadXml(sb.ToString());
57
58 Identity = LegalIdentity.Parse(Doc.DocumentElement);
59 }
60 catch (Exception ex)
61 {
62 Output.WriteStartElement("Label");
63 Output.WriteAttributeString("Text", ex.Message);
64 Output.WriteAttributeString("FontFamily", "Courier New");
65 Output.WriteAttributeString("TextColor", "Red");
66 Output.WriteAttributeString("LineBreakMode", "WordWrap");
67 Output.WriteEndElement();
68
69 return false;
70 }
71
72 Output.WriteStartElement("VerticalStackLayout");
73 Output.WriteAttributeString("HorizontalOptions", "Center");
74
75 bool ImageShown = false;
76
77 if (Identity.Attachments is not null)
78 {
79 (string? FileName, int Width, int Height) = await PhotosLoader.LoadPhotoAsTemporaryFile(Identity.Attachments,
81
82 if (!string.IsNullOrEmpty(FileName))
83 {
84 Output.WriteStartElement("Image");
85 Output.WriteAttributeString("Source", FileName);
86 Output.WriteAttributeString("WidthRequest", Width.ToString(CultureInfo.InvariantCulture));
87 Output.WriteAttributeString("HeightRequest", Height.ToString(CultureInfo.InvariantCulture));
88 Output.WriteEndElement();
89
90 ImageShown = true;
91 }
92 }
93
94 if (!ImageShown)
95 {
96 Output.WriteStartElement("Path");
97 Output.WriteAttributeString("VerticalOptions", "Center");
98 Output.WriteAttributeString("HorizontalOptions", "Center");
99 Output.WriteAttributeString("HeightRequest", "16");
100 Output.WriteAttributeString("WidthRequest", "16");
101 Output.WriteAttributeString("Aspect", "Uniform");
102 Output.WriteAttributeString("Fill", "{AppThemeBinding Light={StaticResource PrimaryForegroundLight}, Dark={StaticResource PrimaryForegroundDark}}");
103 Output.WriteAttributeString("Data", "{x:Static ui:Geometries.PersonPath}");
104 Output.WriteEndElement();
105 }
106
107 Output.WriteStartElement("Label");
108 Output.WriteAttributeString("LineBreakMode", "WordWrap");
109 Output.WriteAttributeString("FontSize", "Medium");
110 Output.WriteAttributeString("HorizontalOptions", "Center");
111 Output.WriteAttributeString("Text", ContactInfo.GetFriendlyName(Identity));
112 Output.WriteEndElement();
113
114 Output.WriteStartElement("VerticalStackLayout.GestureRecognizers");
115
116 StringBuilder Xml = new();
117 Identity.Serialize(Xml, true, true, true, true, true, true, true);
118
119 Output.WriteStartElement("TapGestureRecognizer");
120 Output.WriteAttributeString("Command", "{Binding Path=IotIdUriClicked}");
121 Output.WriteAttributeString("CommandParameter", Constants.UriSchemes.IotId + ":" + Xml.ToString());
122 Output.WriteEndElement();
123
124 Output.WriteEndElement();
125 Output.WriteEndElement();
126
127 return true;
128 }
129
135 {
136 this.document = Document;
137 }
138
144 public Grade Supports(string Language)
145 {
146 return string.Equals(Language, Constants.UriSchemes.IotId, StringComparison.OrdinalIgnoreCase) ? Grade.Excellent : Grade.NotAtAll;
147 }
148 }
149}
const int DefaultImageHeight
The default height to use when generating QR Code images.
Definition: Constants.cs:866
const int DefaultImageWidth
The default width to use when generating QR Code images.
Definition: Constants.cs:862
const string IotId
The IoT ID URI Scheme (iotid)
Definition: Constants.cs:99
A set of never changing property constants and helpful values.
Definition: Constants.cs:7
Contains information about a contact.
Definition: ContactInfo.cs:21
static async Task< string > GetFriendlyName(CaseInsensitiveString RemoteId)
Gets the friendly name of a remote identity (Legal ID or Bare JID).
Definition: ContactInfo.cs:257
void Register(MarkdownDocument Document)
Registers the Markdown document in which the construct resides.
Grade Supports(string Language)
How much the module supports code of a given language (i.e. type of content)
async Task< bool > RenderMauiXaml(MauiXamlRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates Maui XAML
MarkdownDocument? Document
Markdown document.
bool EvaluatesScript
If script is evaluated for this type of code block.
Renders XAML (Maui flavour) from a Markdown document.
Contains a markdown document. This markdown document class supports original markdown,...
Interface for all markdown handlers of code content.
Definition: ICodeContent.cs:9
Grade
Grade enumeration
Definition: Grade.cs:7