3using System.Threading.Tasks;
19 private decimal? value;
20 private decimal? min =
null;
21 private decimal? max =
null;
22 private bool minIncluded =
true;
23 private bool maxIncluded =
true;
34 this.ProtectedValue =
null;
45 set => this.min = value;
55 set => this.max = value;
64 get => this.minIncluded;
65 set => this.minIncluded = value;
74 get => this.maxIncluded;
75 set => this.maxIncluded = value;
103 this.@value =
default;
124 Xml.Append(
"<numericalParameter");
128 Xml.Append(
" exp=\"");
129 Xml.Append(
XML.
Encode(
this.Expression.Normalize(NormalizationForm.FormC)));
133 if (!
string.IsNullOrEmpty(this.
Guide))
135 Xml.Append(
" guide=\"");
136 Xml.Append(
XML.
Encode(
this.Guide.Normalize(NormalizationForm.FormC)));
140 if (this.max.HasValue)
142 Xml.Append(
" max=\"");
144 Xml.Append(
"\" maxIncluded=\"");
149 if (this.min.HasValue)
151 Xml.Append(
" min=\"");
153 Xml.Append(
"\" minIncluded=\"");
158 Xml.Append(
" name=\"");
159 Xml.Append(
XML.
Encode(
this.Name.Value.Normalize(NormalizationForm.FormC)));
164 Xml.Append(
" protected=\"");
165 Xml.Append(Convert.ToBase64String(
this.ProtectedValue));
171 Xml.Append(
" protection=\"");
176 if (this.@value.HasValue &&
this.CanSerializeValue)
178 Xml.Append(
" value=\"");
190 Description.
Serialize(Xml,
"description",
null);
192 Xml.Append(
"</numericalParameter>");
206 if (!this.@value.HasValue)
207 return Task.FromResult(
"Value missing.");
209 if (this.min.HasValue)
211 Diff = this.@value.Value - this.min.Value;
213 if (Diff < 0 || (Diff == 0 && !this.minIncluded))
214 return Task.FromResult(
"Value below minimum permitted.");
217 if (this.max.HasValue)
219 Diff = this.@value.Value - this.max.Value;
221 if (Diff > 0 || (Diff == 0 && !this.maxIncluded))
222 return Task.FromResult(
"Value above maximum permitted.");
225 return base.IsParameterValid(
Variables, Legal);
245 this.min != UpdatedNumericalParameter.min ||
246 this.max != UpdatedNumericalParameter.max ||
247 this.minIncluded != UpdatedNumericalParameter.minIncluded ||
248 this.maxIncluded != UpdatedNumericalParameter.maxIncluded ||
249 base.UpdateRequiresReview(UpdatedParameter);
259 if (!(NewValue is decimal D))
261 if (NewValue is
double Dbl)
263 else if (NewValue is
float F)
265 else if (NewValue is sbyte i8)
267 else if (NewValue is
short i16)
269 else if (NewValue is
int i32)
271 else if (NewValue is
long i64)
273 else if (NewValue is
byte ui8)
275 else if (NewValue is ushort ui16)
277 else if (NewValue is uint ui32)
279 else if (NewValue is ulong ui64)
287 if (this.min.HasValue && (D <
this.min.Value || D ==
this.min.Value && !
this.minIncluded))
290 if (this.max.HasValue && (D >
this.max.Value || D ==
this.max.Value && !
this.maxIncluded))
313 public override Task<bool>
Import(XmlElement Xml)
315 this.Value = Xml.HasAttribute(
"value") ?
XML.
Attribute(Xml,
"value", 0.0m) : (decimal?)
null;
316 this.Min = Xml.HasAttribute(
"min") ?
XML.
Attribute(Xml,
"min", 0.0m) : (decimal?)
null;
317 this.MinIncluded =
XML.
Attribute(Xml,
"minIncluded",
true);
318 this.Max = Xml.HasAttribute(
"max") ?
XML.
Attribute(Xml,
"max", 0.0m) : (decimal?)
null;
319 this.MaxIncluded =
XML.
Attribute(Xml,
"maxIncluded",
true);
321 return base.Import(Xml);
Helps with parsing of commong data types.
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
static bool TryParse(string s, out double Value)
Tries to decode a string encoded double.
Contains a markdown document. This markdown document class supports original markdown,...
static string Encode(string s)
Encodes all special characters in a string so that it can be included in a markdown document without ...
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.
Class managing a script expression.
Contains the definition of a contract
Numerical contractual parameter
decimal? Max
Optional maximum value.
override Task< bool > Import(XmlElement Xml)
Imports parameter values from its XML definition.
override void ToMarkdown(MarkdownOutput Markdown, Contract Contract, int Level, int Indentation)
Exports the human-readable text to Markdown.
override void Populate(Variables Variables)
Populates a variable collection with the value of the parameter.
bool MaxIncluded
If the optional maximum value is included in the allowed range.
bool MinIncluded
If the optional minimum value is included in the allowed range.
decimal? Value
Parameter value
decimal? Min
Optional minimum value.
override Task< string > IsParameterValid(Variables Variables, LegalComponent Legal)
Checks if the parameter value is valid.
override bool UpdateRequiresReview(Parameter UpdatedParameter)
Checks if an updated parameter requires review.
override Parameter TryCreateNew(object NewValue)
Clones the parameter with a new value.
override string StringValue
String representation of value.
override void Serialize(StringBuilder Xml)
Serializes the parameter, in normalized form.
override void ClearValue()
Clears the value, without resetting the protected value.
override object ObjectValue
Parameter value.
Abstract base class for contractual parameters
bool CanSerializeProtectedValue
If the protected value van be serialized.
CaseInsensitiveString Name
Parameter name
string Expression
Parameter validation script expression.
HumanReadableText[] Descriptions
Discriptions of the role, in different languages.
string Guide
Parameter guide text
ProtectionLevel Protection
Level of confidentiality of the information provided by the parameter.
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.
Provisioning and registry service component.
ProtectionLevel
Parameter protection levels