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;
3using System.Text;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Content;
12using Waher.Script;
16
18{
23 {
28 : base("Legal/GetCreatedContracts",
29 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
30 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
31 {
32 }
33
34 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(GetCreatedContracts).Namespace + ".JSON.GetCreatedContracts.req");
35 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(GetCreatedContracts).Namespace + ".XML.GetCreatedContracts.req");
36
45 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
46 {
48
49 int Offset = 0;
50 int MaxCount = int.MaxValue;
51
52 if (Parameters.TryGetValue("POffset", out IElement E) && !(E is null) &&
53 E.AssociatedObjectValue is double d)
54 {
55 Offset = (int)d;
56 }
57
58 if (Parameters.TryGetValue("PMaxCount", out E) && !(E is null) &&
59 E.AssociatedObjectValue is double d2)
60 {
61 MaxCount = (int)d2;
62 }
63
64 List<XmlDocument> Result = new List<XmlDocument>();
65 IEnumerable<Contract> Contracts = await Database.Find<Contract>(Offset, MaxCount,
66 new FilterFieldEqualTo("Account", User.UserName), "-Created");
67 StringBuilder Xml = new StringBuilder();
68
69 foreach (Contract Contract in Contracts)
70 {
71 Xml.Clear();
72 await Contract.Serialize(Xml, true, true, true, true, true, true, true, null, XmppServerModule.Legal);
73
74 XmlDocument Doc = XML.ParseXml(Xml.ToString(), true);
75
76 Result.Add(Doc);
77 }
78
79 await Response.Return(new NamedDictionary<string, object>("ContractsResponse", AgentNamespace)
80 {
81 { "Contracts", Result.ToArray() }
82 });
83 }
84 }
85}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Helps with common XML-related tasks.
Definition: XML.cs:21
static XmlDocument ParseXml(string Xml)
Parses an XML Document from its string representation.
Definition: XML.cs:713
Represents an HTTP request.
Definition: HttpRequest.cs:22
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
Definition: Database.cs:238
This filter selects objects that have a named field equal to a given value.
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:13
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:55
Class managing a script expression.
Definition: Expression.cs:41
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:21