Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GetCreatedContracts.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Content;
10using Waher.Script;
14
16{
21 {
26 : base("Legal/GetCreatedContracts",
27 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
28 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
29 {
30 }
31
32 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(GetCreatedContracts).Namespace + ".JSON.GetCreatedContracts.req");
33 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(GetCreatedContracts).Namespace + ".XML.GetCreatedContracts.req");
34
43 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
44 {
46
47 int Offset = 0;
48 int MaxCount = int.MaxValue;
49
50 if (Parameters.TryGetValue("POffset", out IElement E) && !(E is null) &&
51 E.AssociatedObjectValue is double d)
52 {
53 Offset = (int)d;
54 }
55
56 if (Parameters.TryGetValue("PMaxCount", out E) && !(E is null) &&
57 E.AssociatedObjectValue is double d2)
58 {
59 MaxCount = (int)d2;
60 }
61
62 List<XmlDocument> Result = new List<XmlDocument>();
63 IEnumerable<Contract> Contracts = await Database.Find<Contract>(Offset, MaxCount,
64 new FilterFieldEqualTo("Account", User.UserName), "-Created");
65 StringBuilder Xml = new StringBuilder();
66
67 foreach (Contract Contract in Contracts)
68 {
69 Xml.Clear();
70 Contract.Serialize(Xml, true, true, true, true, true, true, true, null, XmppServerModule.Legal);
71
72 XmlDocument Doc = new XmlDocument()
73 {
74 PreserveWhitespace = true
75 };
76 Doc.LoadXml(Xml.ToString());
77
78 Result.Add(Doc);
79 }
80
81 await Response.Return(new NamedDictionary<string, object>("ContractsResponse", AgentNamespace)
82 {
83 { "Contracts", Result.ToArray() }
84 });
85 }
86 }
87}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:96
Represents an HTTP request.
Definition: HttpRequest.cs:18
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:19
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
Definition: Database.cs:247
This filter selects objects that have a named field equal to a given value.
Class managing a script expression.
Definition: Expression.cs:39
Abstract base class for agent resources supporting the POST method.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
Service Module hosting the XMPP broker and its components.
Basic interface for all types of elements.
Definition: IElement.cs:20