Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ContractReference.cs
1using System.Text;
2using System.Xml;
4using NeuroFeatures;
8
10{
14 [CollectionName("ContractReferences")]
15 [Index("ContractId")]
16 [Index("IsTemplate", "ContractLoaded", "Category", "Name", "Created")]
17 public class ContractReference
18 {
19 private Contract? contract;
20
25 {
26 }
27
31 [ObjectId]
32 public string? ObjectId { get; set; }
33
37 public CaseInsensitiveString? ContractId { get; set; }
38
42 public DateTime Created { get; set; }
43
47 public DateTime Updated { get; set; }
48
52 public DateTime Loaded { get; set; }
53
57 public string? ContractXml { get; set; }
58
62 public string? Name { get; set; }
63
67 public string? Category { get; set; }
68
72 public bool ContractLoaded { get; set; }
73
77 public bool IsTemplate { get; set; }
78
82 [DefaultValue(false)]
83 public bool IsTokenCreationTemplate { get; set; }
84
88 public ContractState State { get; set; }
89
94 public async Task<Contract?> GetContract()
95 {
96 if (this.contract is null && !string.IsNullOrEmpty(this.ContractXml))
97 {
98 XmlDocument Doc = new()
99 {
100 PreserveWhitespace = true
101 };
102 Doc.LoadXml(this.ContractXml);
103
104 ParsedContract Parsed = await Contract.Parse(Doc.DocumentElement, ServiceRef.XmppService.ContractsClient, false);
105
106 this.contract = Parsed?.Contract;
107 }
108
109 return this.contract;
110 }
111
116 public async Task SetContract(Contract Contract)
117 {
118 this.contract = Contract;
119
120 if (Contract is null)
121 {
122 this.ContractXml = null;
123 this.ContractLoaded = false;
124 this.IsTemplate = false;
125 this.IsTokenCreationTemplate = false;
126 this.Name = string.Empty;
127 this.Category = string.Empty;
128 this.State = ContractState.Failed;
129 }
130 else
131 {
132 StringBuilder Xml = new();
133 Contract.Serialize(Xml, true, true, true, true, true, true, true);
134 this.ContractXml = Xml.ToString();
135 this.ContractLoaded = true;
136 this.ContractId = Contract.ContractId;
137 this.IsTemplate = Contract.PartsMode == ContractParts.TemplateOnly;
138 this.State = Contract.State;
139 this.Created = Contract.Created;
140 this.Updated = Contract.Updated;
141 this.Loaded = DateTime.UtcNow;
142
143 this.IsTokenCreationTemplate =
144 this.IsTemplate &&
145 Contract.ForMachinesLocalName == "Create" &&
146 Contract.ForMachinesNamespace == NeuroFeaturesClient.NamespaceNeuroFeatures;
147
148 this.Name = await ContractModel.GetName(Contract);
149 this.Category = await ContractModel.GetCategory(Contract);
150 }
151 }
152 }
153}
Contains a local reference to a contract that the user has created or signed.
async Task< Contract?> GetContract()
Gets a parsed contract.
bool ContractLoaded
If a local copy of the contract is available.
async Task SetContract(Contract Contract)
Sets a parsed contract.
bool IsTemplate
If the contract can work as a template
bool IsTokenCreationTemplate
If the contract represents a token creation template
DateTime Loaded
When object was last loaded.
DateTime Updated
When object was last updated.
CaseInsensitiveString? ContractId
Contract reference
ContractReference()
Contains a local reference to a contract that the user has created or signed.
Base class that references services in the app.
Definition: ServiceRef.cs:31
static IXmppService XmppService
The XMPP service for XMPP communication.
Definition: ServiceRef.cs:67
static async Task< string > GetName(Contract? Contract)
Gets a displayable name for a contract.
static async Task< string?> GetCategory(Contract Contract)
Gets the category of a contract
const string NamespaceNeuroFeatures
Namespace for Neuro-Features.
Contains the definition of a contract
Definition: Contract.cs:22
static Task< ParsedContract > Parse(XmlDocument Xml)
Validates a contract XML Document, and returns the contract definition in it.
Definition: Contract.cs:397
DateTime Created
When the contract was created
Definition: Contract.cs:130
DateTime Updated
When the contract was last updated
Definition: Contract.cs:139
void Serialize(StringBuilder Xml, bool IncludeNamespace, bool IncludeIdAttribute, bool IncludeClientSignatures, bool IncludeAttachments, bool IncludeStatus, bool IncludeServerSignature, bool IncludeAttachmentReferences)
Serializes the Contract, in normalized form.
Definition: Contract.cs:1542
ContractState State
Contract state
Definition: Contract.cs:121
string ContractId
Contract identity
Definition: Contract.cs:65
Contains information about a parsed contract.
Represents a case-insensitive string.
ContractParts
How the parts of the contract are defined.
Definition: Part.cs:9
ContractState
Recognized contract states
Definition: Enumerations.cs:9