4using System.Threading.Tasks;
25 private Parameter[] recordDefinition =
null;
27 private int? minRecords =
null;
28 private int? maxRecords =
null;
36 get => this.minRecords;
37 set => this.minRecords = value;
46 get => this.maxRecords;
47 set => this.maxRecords = value;
61 set =>
throw new Exception(
"Record set parameters are set via the records or the record definition.");
69 ClearValues(this.recordDefinition);
71 if (this.records is
null)
74 foreach (
Parameter[] Record
in this.records)
78 private static void ClearValues(
Parameter[] Parameters)
80 if (Parameters is
null)
107 if (!(this.recordDefinition is
null))
109 foreach (
Parameter P
in this.recordDefinition)
115 foreach (
Parameter P
in this.recordDefinition)
121 if (!(this.records is
null))
123 foreach (
Parameter[] Record
in this.records)
127 await
Table.ToMarkdownCell(Markdown, State2, P, NotesRef);
144 Xml.Append(
"<recordSet");
148 Xml.Append(
" exp=\"");
149 Xml.Append(
XML.
Encode(
this.Expression.Normalize(NormalizationForm.FormC)));
153 if (this.maxRecords.HasValue)
155 Xml.Append(
" maxRecords=\"");
156 Xml.Append(this.maxRecords.Value.ToString());
160 if (this.minRecords.HasValue)
162 Xml.Append(
" minRecords=\"");
163 Xml.Append(this.minRecords.Value.ToString());
167 Xml.Append(
" name=\"");
168 Xml.Append(
XML.
Encode(
this.Name.Value.Normalize(NormalizationForm.FormC)));
174 Description.
Serialize(Xml,
"description",
null);
177 Xml.Append(
"<recordDefinition>");
179 if (!(this.recordDefinition is
null))
181 foreach (
Parameter P
in this.recordDefinition)
185 Xml.Append(
"</recordDefinition>");
187 if (!(this.records is
null))
189 foreach (
Parameter[] Record
in this.records)
191 Xml.Append(
"<record>");
199 Xml.Append(
"</record>");
203 Xml.Append(
"</recordSet>");
216 if (!this.minRecords.HasValue)
217 return "Minimum number of records missing.";
219 if (!this.maxRecords.HasValue)
220 return "Maximum number of records missing.";
222 if (this.minRecords.Value > 0 && (
this.records is
null ||
this.records.Length <
this.minRecords.Value))
223 return "Too few records defined.";
225 if (!(this.records is
null) && this.records.Length >
this.maxRecords.Value)
226 return "Too many records defined.";
228 if (!(this.records is
null))
230 foreach (
Parameter[] Record
in this.records)
232 if (Record.Length != (
this.recordDefinition?.Length ?? 0))
233 return "Record length mismatch.";
235 int i, c = Record.Length;
237 for (i = 0; i < c; i++)
241 if (!
Item.CopyValidationRules(
this.recordDefinition[i]))
242 return "Record element type mismatch.";
246 if (!
string.IsNullOrEmpty(Error))
264 if (!(this.records is
null))
268 foreach (
Parameter[] Record
in this.records)
270 if (RecordVariables is
null)
273 RecordVariables.Clear();
278 Dictionary<string, IElement> Items =
new Dictionary<string, IElement>();
297 if (!(UpdatedParameter is
RecordSet UpdatedRecordSet))
302 if (this.minRecords != UpdatedRecordSet.minRecords ||
303 this.maxRecords != UpdatedRecordSet.maxRecords ||
304 (c =
this.recordDefinition?.Length ?? 0) != (UpdatedRecordSet.recordDefinition?.Length ?? 0) ||
305 (d =
this.records?.Length ?? 0) != (UpdatedRecordSet.records?.Length ?? 0) ||
306 base.UpdateRequiresReview(UpdatedParameter))
311 for (i = 0; i < c; i++)
317 for (j = 0; j < d; j++)
320 if (Record.Length != c)
323 Parameter[] UpdatedRecord = UpdatedRecordSet.records[j];
324 if (UpdatedRecord.Length != c)
327 for (i = 0; i < c; i++)
352 public override async Task<bool>
Import(XmlElement Xml)
354 this.minRecords = Xml.HasAttribute(
"minRecords") ?
XML.
Attribute(Xml,
"minRecords", 0) : (
int?)
null;
355 this.maxRecords = Xml.HasAttribute(
"maxRecords") ?
XML.
Attribute(Xml,
"maxRecords", 0) : (
int?)
null;
361 foreach (XmlNode N
in Xml.ChildNodes)
363 if (!(N is XmlElement E))
368 case "recordDefinition":
369 if (!await
Contract.ParseParameters(E, RecordDefinitions))
379 if (!await
Contract.ParseParameters(E, Record))
382 Records.Add(Record.ToArray());
387 return await base.
Import(Xml);
399 case "recordDefinition":
404 return base.IsChildLocalNameRecognized(LocalName);
423 this.recordDefinition = Typed.recordDefinition;
424 this.records = Typed.records;
425 this.minRecords = Typed.minRecords;
426 this.maxRecords = Typed.maxRecords;
428 return base.CopyValidationRules(From);
436 this.recordDefinition =
null;
438 this.minRecords =
null;
439 this.maxRecords =
null;
441 base.ClearValidationRules();
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
static string Encode(string s)
Encodes a string for use in XML.
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.
T[] ToArray()
Returns an array containing all elements of the collection.
Class that keeps track of events and timing.
Class that keeps track of events and timing for one thread.
Class managing a script expression.
static readonly StringValue Empty
The empty string.
Contains information about a variable.
string Name
Name of variable.
IElement ValueElement
Value element of variable.
Contains the definition of a contract
State of the Markdown output generator.
Contract Contract
Contract being rendered.
string Language
Desired language
Abstract base class for contractual parameters
abstract void Serialize(StringBuilder Xml)
Serializes the parameter, in normalized form.
abstract TextAlignment CellAlignment
Alignment of the cell in a table, if the parameter is to be displayed in a table.
abstract void ClearValue()
Clears the value, without resetting the protected value.
CaseInsensitiveString Name
Parameter name
virtual async Task< bool > Import(XmlElement Xml)
Imports parameter values from its XML definition.
HumanReadableText[] Descriptions
Discriptions of the role, in different languages.
void Populate(Variables Variables)
Populates a variable collection with the value of the parameter.
virtual void ClearValidationRules()
Clears validation rules form the parameter.
override async Task< bool > Import(XmlElement Xml)
Imports parameter values from its XML definition.
override bool IsChildLocalNameRecognized(string LocalName)
If a local name of a child XML element is recognized.
override void Populate(Variables Variables, ProfilerThread Profiler)
Populates a variable collection with the value of the parameter.
override void ClearValidationRules()
Clears validation rules form the parameter.
override bool CopyValidationRules(Parameter From)
Copies validation rules from another parameter.
override void Serialize(StringBuilder Xml)
Serializes the parameter, in normalized form.
override void ClearValue()
Clears the value, without resetting the protected value.
override async Task< string > IsParameterValid(Variables Variables, LegalComponent Legal, ProfilerThread Profiler)
Checks if the parameter value is valid.
int? MaxRecords
Maximum number of records.
override async Task ToMarkdown(MarkdownOutput Markdown, MarkdownOutputState State)
Exports the value to Markdown.
override bool UpdateRequiresReview(Parameter UpdatedParameter)
Checks if an updated parameter requires review.
override object ObjectValue
Parameter value.
int? MinRecords
Minimum number of records.
override Parameter TryCreateNew(object NewValue)
Clones the parameter with a new value.
override async Task ToMarkdown(MarkdownOutput Markdown, MarkdownOutputState State)
Exports the human-readable text to Markdown.
Class representing human-readable text.
override void Serialize(StringBuilder Xml)
Serializes the element in normalized form.
void Append(string s)
Appends text to the Markdown output.
void AppendLine(string s)
Appends text to the Markdown output, followed by a new line.
Legal (digital identities, smart contracts) service component.
TextAlignment
Text alignment of contents.
CellAlignment
Horizontal alignment of contents in a cell.