Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PartInfo.cs
3using System.Threading.Tasks;
4using System.Windows.Input;
6
8{
12 public class PartInfo : OrderedItem
13 {
14 private readonly Property<string> legalId;
15 private readonly Property<string> role;
16 private readonly IPartsModel partsModel;
17
18 private readonly Command removePart;
19
20 private readonly Part part;
21
28 public PartInfo(Part Part, IPartsModel PartsModel, Property<PartInfo[]> Parts)
29 : base(Parts)
30 {
31 this.legalId = new Property<string>(nameof(this.LegalId), Part.LegalId, this);
32 this.role = new Property<string>(nameof(this.Role), Part.Role, this);
33
34 this.partsModel = PartsModel;
35 this.part = Part;
36
37 this.removePart = new Command(this.CanExecuteRemovePart, this.ExecuteRemovePart);
38
39 if (this.partsModel is not null)
40 this.partsModel.PropertyChanged += this.DesignModel_PropertyChanged;
41 }
42
46 public Part Part => this.part;
47
51 public string LegalId
52 {
53 get => this.legalId.Value;
54 set
55 {
56 this.part.LegalId = value;
57 this.legalId.Value = value;
58 }
59 }
60
64 public string Role
65 {
66 get => this.role.Value;
67 set
68 {
69 this.part.Role = value;
70 this.role.Value = value;
71 }
72 }
73
77 public string[] Roles => this.partsModel.RoleNames;
78
79 private void DesignModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
80 {
81 if (e.PropertyName == nameof(this.Roles))
82 this.RaisePropertyChanged(nameof(this.Roles));
83 }
84
88 public ICommand RemovePart => this.removePart;
89
95 {
96 return this.partsModel is not null;
97 }
98
102 public Task ExecuteRemovePart()
103 {
104 if (this.partsModel is not null)
105 {
106 this.partsModel.PropertyChanged -= this.DesignModel_PropertyChanged;
107 this.partsModel.RemovePart(this);
108 }
109
110 return Task.CompletedTask;
111 }
112 }
113}
Class defining a part in a contract
Definition: Part.cs:30
string LegalId
Legal identity of part
Definition: Part.cs:38
string Role
Role of the part in the contract
Definition: Part.cs:57
Class defining a role
Definition: Role.cs:7