3using System.Threading.Tasks;
18 : base(
"/ValidateContract")
22 public override bool HandlesSubPaths =>
false;
23 public override bool UserSessions =>
true;
37 if (Content.
HasError || !(Content.
Decoded is Dictionary<string, object> RequestObj) ||
38 !RequestObj.TryGetValue(
"ContractId", out
object Obj) || !(Obj is
string ContractId) ||
39 !RequestObj.TryGetValue(
"Purpose", out Obj) || !(Obj is
string Purpose) ||
40 !RequestObj.TryGetValue(
"Password", out Obj) || !(Obj is
string Password) ||
41 !RequestObj.TryGetValue(
"TabID", out Obj) || !(Obj is
string TabID))
47 if (ContractId.IndexOf(
'@') < 0)
59 Dictionary<string, object> ResponseObj;
64 ResponseObj = await this.Encode(
Contract);
68 string PetitionId = Guid.NewGuid().ToString();
70 Purpose = Purpose.Trim();
71 if (
string.IsNullOrEmpty(Purpose))
72 Purpose =
"Validating Contract through web interface at " +
Gateway.
Domain;
78 {
"PetitionId", e.PetitionId },
79 {
"PetitionResponse", e.Response },
80 {
"Contract", await this.Encode(e.RequestedContract) },
81 {
"Declined", e.RequestedContract is
null && !(e.Message is
null) },
82 {
"Timeout", e.Message is
null }
84 }, TimeSpan.FromMinutes(5)))
86 await Response.
SendResponse(
new ForbiddenException(Request,
"Unable to sign petition. Either password is incorrect, or no legal identity assigned to broker."));
90 ResponseObj =
new Dictionary<string, object>()
94 {
"PetitionId", PetitionId },
95 {
"Message",
"The information has been petitioned from the owner. If the owner accepts to share the information, it will be displayed here when it arrives." }
99 await Response.
Return(ResponseObj);
109 List<Dictionary<string, object>> List =
new List<Dictionary<string, object>>();
110 Dictionary<string, object> ResponseObj =
new Dictionary<string, object>()
112 {
"ContractId", Contract.ContractId },
113 {
"ContractIdUri", Contract.ContractIdUriString },
114 {
"Petition",
false },
115 {
"Provider", Contract.Provider },
117 {
"ValidationStatus", Status.ToString() },
118 {
"ValidationStatusTags", e.Tags },
119 {
"Visibility", Contract.Visibility },
120 {
"Created", Contract.Created },
121 {
"Updated", Contract.Updated },
122 {
"From", Contract.From },
123 {
"To", Contract.To },
124 {
"SignAfter", Contract.SignAfter },
125 {
"SignBefore", Contract.SignBefore },
129 {
"TemplateId", Contract.TemplateId },
130 {
"TemplateIdUri", Contract.TemplateIdUriString },
131 {
"CanActAsTemplate", Contract.CanActAsTemplate },
133 {
"DefaultLanguage", Contract.DefaultLanguage },
137 {
"ForMachinesLocalName", Contract.ForMachinesLocalName },
138 {
"ForMachinesNamespace", Contract.ForMachinesNamespace },
146 List.Add(
new Dictionary<string, object>()
148 {
"Name", Role.Name },
149 {
"MinCount", Role.MinCount },
150 {
"MaxCount", Role.MaxCount },
151 {
"CanRevoke", Role.CanRevoke },
156 ResponseObj[
"Roles"] = List.ToArray();
164 List.Add(
new Dictionary<string, object>()
166 {
"LegalId", Part.LegalId },
167 {
"LegalIdUri", Part.LegalIdUriString },
168 {
"Role", Part.Role }
172 ResponseObj[
"Parts"] = List.ToArray();
180 List.Add(
new Dictionary<string, object>()
182 {
"Name", Parameter.Name },
183 {
"Value", Parameter.ObjectValue },
188 ResponseObj[
"Parameters"] = List.ToArray();
196 List.Add(
new Dictionary<string, object>()
198 {
"BareJid", ClientSignature.BareJid },
200 {
"LegalId", ClientSignature.LegalId },
201 {
"LegalIdUri", ClientSignature.LegalIdUriString },
202 {
"Role", ClientSignature.Role },
203 {
"Timestamp", ClientSignature.Timestamp },
204 {
"Transferable", ClientSignature.Transferable }
208 ResponseObj[
"ClientSignatures"] = List.ToArray();
216 List.Add(
new Dictionary<string, object>()
218 {
"BareJid", ClientSignature.BareJid },
220 {
"LegalId", ClientSignature.LegalId },
221 {
"LegalIdUri", ClientSignature.LegalIdUriString },
222 {
"Role", ClientSignature.Role },
223 {
"Timestamp", ClientSignature.Timestamp },
224 {
"Transferable", ClientSignature.Transferable }
228 ResponseObj[
"ClientSignatures"] = List.ToArray();
236 List.Add(
new Dictionary<string, object>()
238 {
"Id", Attachment.Id },
239 {
"ContentType", Attachment.ContentType },
240 {
"FileName", Attachment.FileName },
241 {
"Url", Attachment.Url },
243 {
"Timestamp", Attachment.Timestamp },
247 ResponseObj[
"Attachments"] = List.ToArray();
251 ResponseObj[
"ServerSignature"] =
new Dictionary<string, object>()
254 {
"Timestamp", Contract.ServerSignature.Timestamp }
262 List<Dictionary<string, object>> List =
new List<Dictionary<string, object>>();
266 List.Add(
new Dictionary<string, object>()
268 {
"Language", Localization.Language },
274 return List.ToArray();
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
static string GetBody(string Html)
Extracts the contents of the BODY element in a HTML string.
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Helps with common XML-related tasks.
static string PrettyXml(string Xml)
Reformats XML to make it easier to read.
The ClientEvents class allows applications to push information asynchronously to web clients connecte...
static Task< int > PushEvent(string[] TabIDs, string Type, object Data)
Puses an event to a set of Tabs, given their Tab IDs.
Static class managing the runtime environment of the IoT Gateway.
static CaseInsensitiveString Domain
Domain name.
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
static ContractsClient ContractsClient
XMPP Contracts Client, if such a compoent is available on the XMPP broker.
static Task< bool > PetitionContract(string ContractId, string PetitionId, string Purpose, EventHandlerAsync< ContractPetitionResponseEventArgs > Callback, TimeSpan Timeout, HttpRequest Request)
Petitions information about a smart contract from its owner.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
Represents an HTTP request.
bool HasData
If the request has data.
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Task Return(Exception ex)
Returns an error to the client.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Contains a reference to an attachment assigned to a legal object.
byte[] Signature
Binary signature of the attachment, generated by an approved legal identity of the account-holder....
Represents a digital signature on a contract.
Contains the definition of a contract
byte[] ContentSchemaDigest
The hash digest of the schema used to validate the machine-readable contents (ForMachines) of the sma...
Security.HashFunction ContentSchemaHashFunction
Hash function of the schema used to validate the machine-readable contents (ForMachines) of the smart...
Parameter[] Parameters
Defined parameters for the smart contract.
Duration? ArchiveRequired
Requied time to archive a signed smart contract, after it becomes obsolete.
ClientSignature[] ClientSignatures
Client signatures of the contract.
HumanReadableText[] ForHumans
Human-readable contents of the contract.
Attachment[] Attachments
Attachments assigned to the legal identity.
Duration? ArchiveOptional
Optional time to archive a signed smart contract, after it becomes obsolete, and after its required a...
XmlElement ForMachines
Machine-readable contents of the contract.
Role[] Roles
Roles defined in the smart contract.
ContractParts PartsMode
How parts are defined in the smart contract.
ContractState State
Contract state
Part[] Parts
Defined parts for the smart contract.
Duration? Duration
Duration of the contract. Is counted from the time it is signed by the required parties.
ServerSignature ServerSignature
Server signature attesting to the validity of the contents of the contract.
Task< Contract > GetContractAsync(string ContractId)
Gets a contract
Task< IdentityValidationEventArgs > ValidateAsync(LegalIdentity Identity)
Validates a legal identity.
Event arguments for identity validation responses
ContractStatus Status
Validation status of smart contract.
override async Task< HumanReadableElement > IsWellDefined()
Checks if the element is well-defined.
Class representing human-readable text.
async Task< string > GenerateHTML(Contract Contract)
Generates HTML for the human-readable text.
HumanReadableText[] Descriptions
Discriptions of the object, in different languages.
Abstract base class for contractual parameters
Class defining a part in a contract
byte[] DigitalSignature
Digital Signature
bool AllowsPOST
If the POST method is allowed.
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
POST Interface for HTTP resources.
ContractStatus
Validation Status of smart contract
override string ToString()