Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RoleInfo.cs
5using System;
6using System.Threading.Tasks;
7using System.Windows.Input;
10
12{
17 {
18 private readonly ContractModel contractModel;
19 private readonly DesignModel designModel;
20 private readonly Contract contract;
21 private readonly Property<string> name;
22 private readonly Property<object> description;
23 private readonly Property<string> descriptionAsMarkdown;
24 private readonly Property<int> minCount;
25 private readonly Property<int> maxCount;
26 private readonly Property<bool> canRevoke;
27
28 private readonly Command signAsRole;
29 private readonly Command proposeForRole;
30 private readonly Command removeRole;
31
32 private readonly Role role;
33
41 : this(ContractModel, null, ContractModel.Contract, Role, Roles)
42 {
43 }
44
52 : this(null, DesignModel, DesignModel.Contract, Role, Roles)
53 {
54 }
55
65 : base(Roles)
66 {
67 this.contractModel = ContractModel;
68 this.designModel = DesignModel;
69 this.contract = Contract;
70 this.role = Role;
71
72 string Language = this.designModel?.Language ?? this.contractModel?.Language ?? Contract.DefaultLanguage;
73
74 this.name = new Property<string>(nameof(this.Name), Role.Name, this);
75 this.description = new Property<object>(nameof(this.Description), Role.ToSimpleXAML(Language, this.contract).Result, this);
76 this.descriptionAsMarkdown = new Property<string>(nameof(this.DescriptionAsMarkdown), Role.ToMarkdown(Language, this.contract, MarkdownType.ForEditing).Result.Trim(), this);
77 this.minCount = new Property<int>(nameof(this.MaxCount), Role.MinCount, this);
78 this.maxCount = new Property<int>(nameof(this.MinCount), Role.MaxCount, this);
79 this.canRevoke = new Property<bool>(nameof(this.CanRevoke), Role.CanRevoke, this);
80
81 this.signAsRole = new Command(this.CanExecuteSignAsRole, this.ExecuteSignAsRole);
82 this.proposeForRole = new Command(this.CanExecuteProposeForRole, this.ExecuteProposeForRole);
83 this.removeRole = new Command(this.CanExecuteRemoveRole, this.ExecuteRemoveRole);
84 }
85
89 public Role Role => this.role;
90
94 public string Name
95 {
96 get => this.name.Value;
97 set
98 {
99 this.Role.Name = value;
100 this.name.Value = value;
101 }
102 }
103
107 public object Description
108 {
109 get => this.description.Value;
110 }
111
116 {
117 get => this.descriptionAsMarkdown.Value;
118 set
119 {
120 string Language = this.designModel?.Language ?? this.contractModel?.Language ?? this.contract.DefaultLanguage;
121 HumanReadableText Text = value.ToHumanReadableText(Language).Result;
122
123 if (Text is null)
124 this.role.Descriptions = this.role.Descriptions.Remove(Language);
125 else
126 this.role.Descriptions = this.role.Descriptions.Append(Text);
127
128 this.descriptionAsMarkdown.Value = value;
129 this.description.Value = value.ToSimpleXAML(this.contract, Language).Result;
130 }
131 }
132
136 public int MinCount
137 {
138 get => this.minCount.Value;
139 set
140 {
141 this.role.MinCount = value;
142 this.minCount.Value = value;
143 }
144 }
145
149 public int MaxCount
150 {
151 get => this.maxCount.Value;
152 set
153 {
154 this.role.MaxCount = value;
155 this.maxCount.Value = value;
156 }
157 }
158
162 public bool CanRevoke
163 {
164 get => this.canRevoke.Value;
165 set
166 {
167 this.role.CanRevoke = value;
168 this.canRevoke.Value = value;
169 }
170 }
171
173 public override void RaisePropertyChanged(string PropertyName)
174 {
175 base.RaisePropertyChanged(PropertyName);
176
177 this.designModel?.RaisePropertyChanged(nameof(this.designModel.Roles));
178 }
179
180 internal void CanBeSignedChanged()
181 {
182 this.signAsRole.RaiseCanExecuteChanged();
183 this.proposeForRole.RaiseCanExecuteChanged();
184 }
185
189 public ICommand SignAsRole => this.signAsRole;
190
196 {
197 return this.contractModel?.CanBeSigned ?? false;
198 }
199
203 public async Task ExecuteSignAsRole()
204 {
205 try
206 {
207 if (this.contractModel is not null)
208 await this.contractModel.SignAsRole(this.Name);
209 }
210 catch (Exception ex)
211 {
212 MainWindow.ErrorBox(ex.Message);
213 }
214 }
215
219 public ICommand ProposeForRole => this.proposeForRole;
220
226 {
227 return this.contractModel?.CanBeSigned ?? false;
228 }
229
233 public async Task ExecuteProposeForRole()
234 {
235 if (this.contractModel is not null)
236 await this.contractModel.ProposeForRole(this.Name);
237 }
238
242 public ICommand RemoveRole => this.removeRole;
243
249 {
250 return this.designModel is not null;
251 }
252
256 public Task ExecuteRemoveRole()
257 {
258 this.designModel?.RemoveRole(this);
259 return Task.CompletedTask;
260 }
261
267 public async Task<string[]> GetTranslatableTexts(string Language)
268 {
269 HumanReadableText Text = this.Role.Descriptions.Find(Language);
270 if (Text is null)
271 return null;
272 else
273 return new string[] { await Text.GenerateMarkdown(this.contract, MarkdownType.ForEditing) };
274 }
275
281 public void SetTranslatableTexts(string[] Texts, string Language)
282 {
283 if (Texts.Length > 0)
284 this.DescriptionAsMarkdown = Texts[0].Trim();
285 }
286
287 }
288}
Contains the definition of a contract
Definition: Contract.cs:22
string DefaultLanguage
Default language for contract.
Definition: Contract.cs:1884
Task< string > GenerateMarkdown(Contract Contract)
Generates markdown for the human-readable text.
HumanReadableText[] Descriptions
Discriptions of the object, in different languages.
Task< string > ToMarkdown(string Language, Contract Contract)
Creates a human-readable Markdown document for the contract.
Class defining a role
Definition: Role.cs:7
bool CanRevoke
If parts having this role, can revoke their signature, once signed.
Definition: Role.cs:44
int MaxCount
Largest amount of signatures of this role required for a legally binding contract.
Definition: Role.cs:35
int MinCount
Smallest amount of signatures of this role required for a legally binding contract.
Definition: Role.cs:26
string Name
Name of the role.
Definition: Role.cs:17