1using DocumentFormat.OpenXml.EMMA;
9using System.Collections.Generic;
11using System.Threading.Tasks;
13using System.Windows.Controls;
14using System.Windows.Media;
29 private static readonly
Contract emptyContract =
new();
36 protected readonly Dictionary<CaseInsensitiveString, ParameterInfo> parametersByName =
new();
38 private StackPanel languageOptions =
null;
39 private StackPanel parameterOptions =
null;
40 private StackPanel additionalCommands =
null;
58 this.contract =
Contract ?? emptyContract;
70 if (this.contract is not
null)
71 this.contract.FormatParameterDisplay -= this.Contract_FormatParameterDisplay;
74 this.contract.FormatParameterDisplay += this.Contract_FormatParameterDisplay;
78 return Task.CompletedTask;
86 return Task.CompletedTask;
89 protected void SetParameters(
Parameter[] ContractParameters)
91 this.contractParameters = ContractParameters;
96 this.Languages = this.contract.
GetLanguages().ToIso639_1();
98 if (!
string.IsNullOrWhiteSpace(PrevLanguage))
102 if (Rec.Code == PrevLanguage)
114 this.Languages =
new string[] {
"en" }.ToIso639_1();
115 this.Language =
"en";
120 if (ContractParameters is not
null)
145 get => this.language.Value;
154 get => this.languages.
Value;
155 set => this.languages.Value = value;
168 if (!
string.IsNullOrEmpty(
Language))
175 PI.DescriptionAsMarkdown =
string.Empty;
180 if (this.languageOptions is not
null)
181 await this.
PopulateParameters(this.languageOptions, this.parameterOptions, this.additionalCommands,
null);
200 get => this.parametersOk.Value;
203 this.parametersOk.Value = value;
204 this.ParametersOkChanged();
208 protected virtual void ParametersOkChanged()
222 Dictionary<CaseInsensitiveString, object> PresetValues)
224 List<ParameterInfo> ParameterList =
new();
226 Control First =
null;
229 if (this.languageOptions is not
null)
230 this.languageOptions.DataContext =
this;
233 this.parameterOptions.Children.Clear();
234 this.parameterOptions.DataContext =
this;
235 this.parametersByName.Clear();
241 CheckBox CheckBox =
new()
244 IsChecked = BP.Value.HasValue && BP.Value.Value,
245 VerticalContentAlignment = VerticalAlignment.Center,
248 Margin =
new Thickness(0, 10, 0, 0)
251 if ((PresetValues?.TryGetValue(
Parameter.
Name, out
object PresetValue) ??
false) && PresetValue is
bool b)
254 CheckBox.IsChecked = b;
257 CheckBox.Checked += this.Parameter_CheckedChanged;
258 CheckBox.Unchecked += this.Parameter_CheckedChanged;
268 System.Windows.Controls.Label
Label =
new()
271 Margin =
new Thickness(0, 10, 0, 0)
274 TextBox TextBox =
new()
281 if (PresetValues?.TryGetValue(
Parameter.
Name, out
object PresetValue) ??
false)
286 TextBox.TextChanged += this.Parameter_TextChanged;
290 if (PresetValue is decimal d)
294 null,
null,
null,
null, this.designModel, this.parameters);
298 if (PresetValue is
string s)
302 null,
null,
null,
null,
null,
null,
null, this.designModel, this.parameters);
306 if (PresetValue is DateTime TP)
310 null,
null,
null,
null, this.designModel, this.parameters);
314 if (PresetValue is DateTime TP)
318 null,
null,
null,
null, this.designModel, this.parameters);
322 if (PresetValue is TimeSpan TS)
326 null,
null,
null,
null, this.designModel, this.parameters);
334 null,
null,
null,
null, this.designModel, this.parameters);
338 TextBox.IsReadOnly =
true;
341 this.designModel, this.parameters);
345 if (PresetValue is
string s)
349 this.designModel, this.parameters);
363 this.Parameters = ParameterList.ToArray();
367 this.additionalCommands = AdditionalCommands;
368 if (this.additionalCommands is not
null)
370 this.additionalCommands.DataContext =
this;
371 this.additionalCommands.Visibility = Visibility.Visible;
372 this.additionalCommands.InvalidateVisual();
378 private async
void Parameter_CheckedChanged(
object sender, RoutedEventArgs e)
382 if (sender is not CheckBox CheckBox || !this.parametersByName.TryGetValue(CheckBox.Tag.ToString(), out
ParameterInfo ParameterInfo))
385 ParameterInfo.Value = CheckBox.IsChecked;
394 await this.RaiseParametersChanged();
397 protected async Task RaiseParametersChanged()
401 await this.ParametersChanged();
409 protected virtual Task ParametersChanged()
411 return Task.CompletedTask;
414 private async
void Parameter_TextChanged(
object sender, RoutedEventArgs e)
418 if (sender is not TextBox TextBox || !this.parametersByName.TryGetValue(TextBox.Tag.ToString(), out
ParameterInfo ParameterInfo))
424 ParameterInfo.Value = d;
426 ParameterInfo.Value = b;
429 if (TP.TimeOfDay != TimeSpan.Zero)
430 throw new Exception(
"Date only.");
432 ParameterInfo.Value = TP;
435 ParameterInfo.Value = TP;
437 ParameterInfo.Value = TS;
439 ParameterInfo.Value = Dr;
441 ParameterInfo.Value = TextBox.Text;
451 TextBox.Background = Brushes.Salmon;
452 this.ParametersOk =
false;
457 await this.RaiseParametersChanged();
483 P.Control.Background = P.
Protection.DefaultBrush();
488 StringBuilder Msg =
new();
490 Msg.Append(
"Parameter ");
492 Msg.Append(
" contains errors.");
496 Msg.Append(
" Reason: ");
502 Msg.Append(
", Text: ");
506 P.Control.Background = Brushes.Salmon;
512 this.ParametersOk = Ok;
522 get => this.parameters.
Value;
523 set => this.parameters.Value = value;
Converts Duration values to strings.
static string ToString(Duration Duration)
Converts a Duration to a human-readable text.
Converts values to strings.
static string ToString(object Value)
Converts a monetary value to a string, removing any round-off errors.
Interaction logic for MainWindow.xaml
static void ErrorBox(string ErrorMessage)
Displays an error message on the screen, on the main UI thread.
Contract parameters model
virtual async Task< bool > SetLanguage(string Language)
Sets the current language.
virtual async Task< Control > PopulateParameters(StackPanel Languages, StackPanel Parameters, StackPanel AdditionalCommands, Dictionary< CaseInsensitiveString, object > PresetValues)
Populates a StackPanel with parameter controls.
virtual async Task< Variables > ValidateParameters()
Validates available parameters. If OK, a collection of variables is returned, otherwise null is retur...
bool ParametersOk
If all parameters are OK or not
virtual Task SetContract(Contract Contract)
Sets the current contract.
Contract Contract
Referenced contract
Iso__639_1.Record[] Languages
Available languages.
string Language
Currently selected language.
ParameterInfo[] Parameters
Parameters defined the contract.
ContractParametersModel(Parameter[] Parameters, Contract Contract, string Language, DesignModel DesignModel)
Contract parameters model
Contains information about a parameter
virtual object Value
Parameter value
virtual void ContractUpdated(Contract Contract)
Called when the contract has been updated.
string ErrorText
Error text specification, in case ErrorReason dictates so.
virtual async Task< bool > ValidateParameter(Variables Variables)
Method called when the parameter needs to be validated.
ParameterErrorReason? ErrorReason
Error reason enumeration.
Parameter Parameter
Original parameter object in contract
ProtectionLevel Protection
Parameter protection level
Contains information about a boolean parameter
Contains information about a calculation parameter
Contains information about a contract reference parameter
Contains information about a date parameter
Contains information about a date and time parameter
Contains information about a duration parameter
Contains information about a numerical parameter
Contains information about a string parameter
Contains information about a time parameter
Abstract base class for view models
Generic class for properties
virtual T Value
Current value of the property
Contains one record of the ISO 639-1 data set.
Static class containing ISO 639-1 language codes
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Boolean contractual parameter
Calculation contractual parameter
Contains the definition of a contract
string[] GetLanguages()
Gets available languages encoded in contract.
Parameter[] Parameters
Defined parameters for the smart contract.
string DefaultLanguage
Default language for contract.
Duration? Duration
Duration of the contract. Is counted from the time it is signed by the required parties.
Contract-reference parameter
Date contractual parameter
Date and Time contractual parameter
Duration contractual parameter
Class representing human-readable text.
Task< string > GenerateMarkdown(Contract Contract)
Generates markdown for the human-readable text.
HumanReadableText[] Descriptions
Discriptions of the object, in different languages.
Numerical contractual parameter
Abstract base class for contractual parameters
abstract void Populate(Variables Variables)
Populates a variable collection with the value of the parameter.
string Name
Parameter name
abstract object ObjectValue
Parameter value.
String-valued contractual parameter
Time contractual parameter
MarkdownType
Type of Markdown to generate
Represents a duration value, as defined by the xsd:duration data type: http://www....
static bool TryParse(string s, out Duration Result)
Tries to parse a duration value.