Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NeuroFeatureCodeBlock.cs
3using NeuroFeatures;
4using System.Text;
5using System.Xml;
9
11{
16 {
17 private MarkdownDocument? document;
18
23 {
24 }
25
29 public MarkdownDocument? Document => this.document;
30
34 public bool EvaluatesScript => false;
35
39 public Task<bool> RenderMauiXaml(MauiXamlRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
40 {
41 XmlWriter Output = Renderer.XmlOutput;
43
44 try
45 {
46 StringBuilder sb = new();
47
48 foreach (string Row in Rows)
49 sb.AppendLine(Row);
50
51 XmlDocument Doc = new()
52 {
53 PreserveWhitespace = true
54 };
55 Doc.LoadXml(sb.ToString());
56
57 if (!NeuroFeatures.Token.TryParse(Doc.DocumentElement, out Token))
58 throw new Exception(ServiceRef.Localizer[nameof(AppResources.InvalidNeuroFeatureToken)]);
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 Task.FromResult(false);
70 }
71
72 Output.WriteStartElement("VerticalStackLayout");
73 Output.WriteAttributeString("HorizontalOptions", "Center");
74
75 Output.WriteStartElement("Path");
76 Output.WriteAttributeString("VerticalOptions", "Center");
77 Output.WriteAttributeString("HorizontalOptions", "Center");
78 Output.WriteAttributeString("HeightRequest", "16");
79 Output.WriteAttributeString("WidthRequest", "16");
80 Output.WriteAttributeString("Aspect", "Uniform");
81 Output.WriteAttributeString("Fill", "{AppThemeBinding Light={StaticResource PrimaryForegroundLight}, Dark={StaticResource PrimaryForegroundDark}}");
82 Output.WriteAttributeString("Data", "{x:Static ui:Geometries.TokenPath}");
83 Output.WriteEndElement();
84
85 Output.WriteStartElement("Label");
86 Output.WriteAttributeString("LineBreakMode", "WordWrap");
87 Output.WriteAttributeString("FontSize", "Medium");
88 Output.WriteAttributeString("HorizontalOptions", "Center");
89 Output.WriteAttributeString("Text", Token.FriendlyName);
90 Output.WriteEndElement();
91
92 Output.WriteStartElement("StackLayout.GestureRecognizers");
93
94 Output.WriteStartElement("TapGestureRecognizer");
95 Output.WriteAttributeString("Command", "{Binding Path=NeuroFeatureUriClicked}");
96 Output.WriteAttributeString("CommandParameter", Constants.UriSchemes.NeuroFeature + ":" + Token.ToXml());
97 Output.WriteEndElement();
98
99 Output.WriteEndElement();
100 Output.WriteEndElement();
101
102 return Task.FromResult(true);
103 }
104
110 {
111 this.document = Document;
112 }
113
119 public Grade Supports(string Language)
120 {
121 return string.Equals(Language, Constants.UriSchemes.NeuroFeature, StringComparison.OrdinalIgnoreCase) ? Grade.Excellent : Grade.NotAtAll;
122 }
123 }
124}
const string NeuroFeature
eDaler URI Scheme (edaler)
Definition: Constants.cs:124
A set of never changing property constants and helpful values.
Definition: Constants.cs:7
Base class that references services in the app.
Definition: ServiceRef.cs:31
static IStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:235
void Register(MarkdownDocument Document)
Registers the Markdown document in which the construct resides.
bool EvaluatesScript
If script is evaluated for this type of code block.
Grade Supports(string Language)
How much the module supports code of a given language (i.e. type of content)
Task< bool > RenderMauiXaml(MauiXamlRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates Maui XAML
Renders XAML (Maui flavour) from a Markdown document.
Neuro-Feature Token
Definition: Token.cs:43
static bool TryParse(XmlElement Xml, out Token Token)
Serializes the Token, in normalized form.
Definition: Token.cs:523
string FriendlyName
A friendly name for the token.
Definition: Token.cs:426
string ToXml()
Exports the token to XML.
Definition: Token.cs:911
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