Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PreviewIdApplication.cs
1using Paiwise;
2using System;
3using System.Threading.Tasks;
5using Waher.Script;
9
11{
16 {
17 private readonly string fileName;
18 private readonly DateTime created;
19 private readonly DateTime updated;
20 private readonly Variables variables;
21 private readonly ScriptNode node;
22 private LegalIdentity identity = null;
23
30 public PreviewIdApplication(string FileName, DateTime Created, DateTime Updated)
31 : this(FileName, Created, Updated, null)
32 {
33 }
34
42 public PreviewIdApplication(string FileName, DateTime Created, DateTime Updated,
43 LegalIdentity Identity)
44 {
45 this.fileName = FileName;
46 this.created = Created;
47 this.updated = Updated;
48 this.identity = Identity;
49 this.variables = null;
50 this.node = null;
51 }
52
53 private PreviewIdApplication(string FileName, DateTime Created, DateTime Updated,
55 {
56 this.fileName = FileName;
57 this.created = Created;
58 this.updated = Updated;
59 this.variables = Variables;
60 this.node = Node;
61 this.identity = Identity;
62 }
63
64 public PreviewIdApplication Clone(Variables Variables, ScriptNode Node)
65 {
66 return new PreviewIdApplication(this.fileName, this.created, this.updated,
67 Variables, Node, this.identity);
68 }
69
73 public async Task<LegalIdentity> Load()
74 {
75 this.identity ??= await LegalComponent.GetPreviewIdentity(this.fileName);
76 return this.identity;
77 }
78
82 public string FileName => this.fileName;
83
84 public CaseInsensitiveString Id
85 {
86 get => this.identity?.Id ?? this.Load().Result?.Id;
87 set => throw InvalidOperation();
88 }
89
90 public CaseInsensitiveString Provider
91 {
92 get => this.identity?.Provider ?? this.Load().Result?.Provider;
93 set => throw InvalidOperation();
94 }
95
96 public IdentityState State
97 {
98 get => this.identity?.State ?? this.Load().Result?.State ?? IdentityState.Obsoleted;
99 set => throw InvalidOperation();
100 }
101
102 public CaseInsensitiveString Account
103 {
104 get => this.identity?.Account ?? this.Load().Result?.Account;
105 set => throw InvalidOperation();
106 }
107
108 public DateTime Created
109 {
110 get => this.created;
111 set => throw InvalidOperation();
112 }
113
114 public DateTime Updated
115 {
116 get => this.updated;
117 set => throw InvalidOperation();
118 }
119
120 public DateTime From
121 {
122 get => this.identity?.From ?? this.Load().Result?.From ?? DateTime.MinValue;
123 set => throw InvalidOperation();
124 }
125
126 public DateTime To
127 {
128 get => this.identity?.To ?? this.Load().Result?.To ?? DateTime.MinValue;
129 set => throw InvalidOperation();
130 }
131
132 public Property[] Properties
133 {
134 get => this.identity?.Properties ?? this.Load().Result?.Properties;
135 set => throw InvalidOperation();
136 }
137
138 public AttachmentReference[] Attachments
139 {
140 get => this.identity?.Attachments ?? this.Load().Result?.Attachments;
141 set => throw InvalidOperation();
142 }
143
144 public string ClientKeyName
145 {
146 get => this.identity?.ClientKeyName ?? this.Load().Result?.ClientKeyName;
147 set => throw InvalidOperation();
148 }
149
150 public byte[] ClientPubKey
151 {
152 get => this.identity?.ClientPubKey ?? this.Load().Result?.ClientPubKey;
153 set => throw InvalidOperation();
154 }
155
156 public byte[] ClientSignature
157 {
158 get => this.identity?.ClientSignature ?? this.Load().Result?.ClientSignature;
159 set => throw InvalidOperation();
160 }
161
162 public byte[] ServerSignature
163 {
164 get => this.identity?.ServerSignature ?? this.Load().Result?.ServerSignature;
165 set => throw InvalidOperation();
166 }
167
168 public int NrPeerReviews
169 {
170 get => this.identity?.NrPeerReviews ?? this.Load().Result?.NrPeerReviews ?? 0;
171 set => throw InvalidOperation();
172 }
173
174 public NamespaceSet Version
175 {
176 get => this.identity?.Version ?? this.Load().Result?.Version ?? NamespaceSet.Unknown;
177 set => throw InvalidOperation();
178 }
179
180 public object this[string Property]
181 {
182 get
183 {
184 LegalIdentity Identity = this.identity ?? this.Load().Result;
185 CaseInsensitiveString Value = Identity?[Property];
186
188 !IsWellKnownIdentityProperty(Property))
189 {
190 IElement E = VariableReference.TryGetConstant(Property, this.variables, this.node);
191 return E?.AssociatedObjectValue;
192
193 // Don't return empty string. WHERE clauses are executed as script,
194 // as this object only exists in an in-memory script environment.
195 // SELECT statements against persisted LegalIdentity is performed
196 // inside the object database, and do not rely on this index property
197 // in the same way.
198 }
199
200 return Value;
201 }
202 }
203
204 private static bool IsWellKnownIdentityProperty(string Property)
205 {
206 switch (Property.ToUpperInvariant())
207 {
240 return true;
241
242 default:
243 return false;
244 }
245 }
246
247 private static InvalidOperationException InvalidOperation()
248 {
249 return new InvalidOperationException("Object is read-only.");
250 }
251 }
252}
Contains personal information found in a legal identity.
const string OrganizationAddressTag
ORGADDR
const string NationalityTag
NATIONALITY
const string OrganizationNameTag
ORGNAME
const string OrganizationAddress2Tag
ORGADDR2
const string OrganizationNumberTag
ORGNR
const string MiddleNamesTag
MIDDLE
const string OrganizationCountryTag
ORGCOUNTRY
const string CountryTag
COUNTRY
const string OrganizationCityTag
ORGCITY
const string OrganizationDepartmentTag
ORGDEPT
const string OrganizationRegionTag
ORGREGION
const string AgeAboveTag
AGEABOVE
const string OrganizationRoleTag
ORGROLE
const string OrganizationAreaTag
ORGAREA
const string BirthMonthTag
BMONTH
const string OrganizationPostalCodeTag
ORGZIP
const string FullNameTag
FULLNAME
Represents a case-insensitive string.
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Represents a variable reference.
static IElement TryGetConstant(string VariableName, Variables Variables, ScriptNode Node)
Tries to get a constant value, given a variable name. This method will also check for namespaces and ...
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:34
NamespaceSet
Namespace versions
Definition: NamespaceSet.cs:7