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 async 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 Token? ParsedToken = await NeuroFeatures.Token.TryParse(Doc.DocumentElement);
58 if (ParsedToken is null)
59 throw new Exception(ServiceRef.Localizer[nameof(AppResources.InvalidNeuroFeatureToken)]);
60
61 Token = ParsedToken;
62 }
63 catch (Exception ex)
64 {
65 Output.WriteStartElement("Label");
66 Output.WriteAttributeString("Text", ex.Message);
67 Output.WriteAttributeString("FontFamily", "SpaceGroteskRegular");
68 Output.WriteAttributeString("TextColor", "Red");
69 Output.WriteAttributeString("LineBreakMode", "WordWrap");
70 Output.WriteEndElement();
71
72 return false;
73 }
74
75 Output.WriteStartElement("VerticalStackLayout");
76 Output.WriteAttributeString("HorizontalOptions", "Center");
77
78 Output.WriteStartElement("Path");
79 Output.WriteAttributeString("VerticalOptions", "Center");
80 Output.WriteAttributeString("HorizontalOptions", "Center");
81 Output.WriteAttributeString("HeightRequest", "16");
82 Output.WriteAttributeString("WidthRequest", "16");
83 Output.WriteAttributeString("Aspect", "Uniform");
84 Output.WriteAttributeString("Fill", "{DynamicResource ContentPrimaryWL}");
85 Output.WriteAttributeString("Data", "{x:Static ui:Geometries.TokenPath}");
86 Output.WriteEndElement();
87
88 Output.WriteStartElement("Label");
89 Output.WriteAttributeString("LineBreakMode", "WordWrap");
90 Output.WriteAttributeString("FontSize", "Medium");
91 Output.WriteAttributeString("HorizontalOptions", "Center");
92 Output.WriteAttributeString("Text", Token.FriendlyName);
93 Output.WriteEndElement();
94
95 Output.WriteStartElement("StackLayout.GestureRecognizers");
96
97 Output.WriteStartElement("TapGestureRecognizer");
98 Output.WriteAttributeString("Command", "{Binding Path=NeuroFeatureUriClicked}");
99 Output.WriteAttributeString("CommandParameter", Constants.UriSchemes.NeuroFeature + ":" + Token.ToXml());
100 Output.WriteEndElement();
101
102 Output.WriteEndElement();
103 Output.WriteEndElement();
104
105 return true;
106 }
107
113 {
114 this.document = Document;
115 }
116
122 public Grade Supports(string Language)
123 {
124 return string.Equals(Language, Constants.UriSchemes.NeuroFeature, StringComparison.OrdinalIgnoreCase) ? Grade.Excellent : Grade.NotAtAll;
125 }
126 }
127}
const string NeuroFeature
eDaler URI Scheme (edaler)
Definition: Constants.cs:178
A set of never changing property constants and helpful values.
Definition: Constants.cs:24
A strongly-typed resource class, for looking up localized strings, etc.
static string InvalidNeuroFeatureToken
Looks up a localized string similar to Invalid Neuro-Feature token..
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
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.
async Task< bool > RenderMauiXaml(MauiXamlRenderer Renderer, string[] Rows, string Language, int Indent, MarkdownDocument Document)
Generates Maui XAML
Grade Supports(string Language)
How much the module supports code of a given language (i.e. type of content)
Renders XAML (Maui flavour) from a Markdown document.
Neuro-Feature Token
Definition: Token.cs:46
static async Task< Token > TryParse(XmlElement Xml)
Tries to parse a Token.
Definition: Token.cs:555
string FriendlyName
A friendly name for the token.
Definition: Token.cs:459
string ToXml()
Exports the token to XML.
Definition: Token.cs:986
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