1using System.Collections.ObjectModel;
2using System.Collections.Specialized;
3using System.ComponentModel;
4using CommunityToolkit.Mvvm.ComponentModel;
18 #region Constructors and Destructor
22 this.Contract = contract;
23 this.Parameters.CollectionChanged += this.Parameters_CollectionChanged;
24 this.Roles.CollectionChanged += this.Roles_CollectionChanged;
29 #region Initialization
39 return ContractWrapper;
59 this.
Roles.Add(ObservableRole);
67 await
Role.AddPart(part);
76 await
Role.AddPart(signature);
84 #region Collection Changed Handlers
86 private void Parameters_CollectionChanged(
object? sender, NotifyCollectionChangedEventArgs e)
88 if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems is not
null)
92 param.PropertyChanged += this.Parameter_OnPropertyChanged;
95 else if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems is not
null)
97 foreach (ObservableParameter param
in e.OldItems)
99 param.PropertyChanged -= this.Parameter_OnPropertyChanged;
104 private void Roles_CollectionChanged(
object? sender, NotifyCollectionChangedEventArgs e)
106 if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems is not
null)
108 foreach (ObservableRole role
in e.NewItems)
110 role.PropertyChanged += this.Role_OnPropertyChanged;
111 role.Parts.CollectionChanged += this.Parts_CollectionChanged;
114 else if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems is not
null)
116 foreach (ObservableRole role
in e.OldItems)
118 role.PropertyChanged -= this.Role_OnPropertyChanged;
119 role.Parts.CollectionChanged -= this.Parts_CollectionChanged;
126 #region Property Changed Handlers
128 public event NotifyCollectionChangedEventHandler? PartChanged;
129 private void Parts_CollectionChanged(
object? sender, NotifyCollectionChangedEventArgs e)
131 this.PartChanged?.Invoke(sender, e);
139 private void Parameter_OnPropertyChanged(
object? sender, PropertyChangedEventArgs e)
141 this.ParameterChanged?.Invoke(sender, e);
149 private void Role_OnPropertyChanged(
object? sender, PropertyChangedEventArgs e)
151 this.RoleChanged?.Invoke(sender, e);
166 public ObservableCollection<ObservableParameter>
Parameters => this.parameters;
167 private readonly ObservableCollection<ObservableParameter> parameters = [];
172 public ObservableCollection<ObservableRole>
Roles => this.roles;
173 private readonly ObservableCollection<ObservableRole> roles = [];
180 get => this.category;
181 private set => this.SetProperty(ref this.category, value);
183 private string category =
string.Empty;
216 private bool disposed =
false;
218 #region IDisposable Support
219 public void Dispose()
222 GC.SuppressFinalize(
this);
225 protected virtual void Dispose(
bool disposing)
233 this.Parameters.CollectionChanged -= this.Parameters_CollectionChanged;
234 this.Roles.CollectionChanged -= this.Roles_CollectionChanged;
237 this.disposed =
true;
The data model for a contract.
static async Task< string?> GetCategory(Contract Contract)
Gets the category of a contract
An observable object that wraps a Contract object. This allows for easier binding in the UI....
string TemplateId
The template ID.
bool CanActAsTemplate
Whether the contract can act as a template.
static async Task< ObservableContract > CreateAsync(Contract contract)
Creates a new instance of ObservableContract and initializes the roles and parameters.
ContractVisibility Visibility
The visibility of the contract.
ObservableCollection< ObservableParameter > Parameters
The parameters of the contract.
async Task InitializeAsync()
Initializes the contract data, such as category and parameters.
string ContractId
The contract ID.
bool IsTemplate
Whether the contract is a template.
string Category
The category of the contract.
PropertyChangedEventHandler? RoleChanged
Occurs when a property value of any role changes.
PropertyChangedEventHandler? ParameterChanged
Occurs when a property value of any parameter changes.
ObservableCollection< ObservableRole > Roles
The roles of the contract.
An observable object that wraps a Waher.Networking.XMPP.Contracts.Parameter object....
static async Task< ObservableParameter > CreateAsync(Parameter parameter, Contract contract)
Creates a new instance of ObservableParameter based on the type of the parameter.
An observable object that wraps a Waher.Networking.XMPP.Contracts.Role object. This allows for easier...
async Task InitializeAsync(Contract contract)
Initializes the role in regards to a contract. E.g Sets the description of the role,...
Represents a digital signature on a contract.
string Role
Role of the legal identity in the contract.
Contains the definition of a contract
Parameter[] Parameters
Defined parameters for the smart contract.
ClientSignature[] ClientSignatures
Client signatures of the contract.
bool CanActAsTemplate
If the contract can act as a template for other contracts.
Role[] Roles
Roles defined in the smart contract.
ContractState State
Contract state
string ContractId
Contract identity
Part[] Parts
Defined parts for the smart contract.
ContractVisibility Visibility
Contrat Visibility
string TemplateId
Contract identity of template, if one was used to create the contract.
Abstract base class for contractual parameters
Class defining a part in a contract
string Role
Role of the part in the contract
ContractParts
How the parts of the contract are defined.
ContractVisibility
Visibility types for contracts.
ContractState
Recognized contract states