Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DomainInfo.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
3using Waher.Content;
7
9{
14 {
18 public DomainInfo()
19 : base("Account/DomainInfo")
20 {
21 }
22
29 {
30 return null;
31 }
32
41 public override async Task GET(HttpRequest Request, HttpResponse Response)
42 {
43 await base.GET(Request, Response);
44
45 SetTransparentCorsHeaders(this, Request, Response);
46
47 string Name = this.SelectString(Request,
51
52 string Description = this.SelectString(Request,
56
57 await Response.Return(new NamedDictionary<string, object>("DomainInfo", AgentNamespace)
58 {
59 { "domain", DomainConfiguration.Instance?.Domain ?? string.Empty },
60 { "useEncryption", DomainConfiguration.Instance?.UseEncryption ?? false },
61 { "humanReadableName", Name?? string.Empty },
62 { "humanReadableDescription", Description ?? string.Empty }
63 });
64 }
65
66 private string SelectString(HttpRequest Request, string Default, string DefaultLanguage,
67 AlternativeField[] Localizations)
68 {
69 if (Request.Header.AcceptLanguage is null)
70 return Default;
71
72 string[] Languages = GetLanguages(DefaultLanguage, Localizations);
73 string Language = Request.Header.AcceptLanguage.GetBestAlternative(Languages);
74
75 if (string.IsNullOrEmpty(Language) || DefaultLanguage == Language)
76 return Default;
77
78 if (!(Localizations is null))
79 {
80 foreach (AlternativeField Localization in Localizations)
81 {
82 if (Localization.Key == Language)
83 return Localization.Value;
84 }
85 }
86
87 return Default;
88 }
89
90 private static string[] GetLanguages(string DefaultLanguage, AlternativeField[] Localizations)
91 {
92 List<string> Languages = new List<string>();
93
94 if (!string.IsNullOrEmpty(DefaultLanguage))
95 Languages.Add(DefaultLanguage);
96
97 if (!(Localizations is null))
98 {
99 foreach (AlternativeField Localization in Localizations)
100 {
101 if (!string.IsNullOrEmpty(Localization.Key))
102 Languages.Add(Localization.Key);
103 }
104 }
105
106 return Languages.ToArray();
107 }
108 }
109}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Represents an alternative field in a legal identity.
string Value
Alternative field Value.
string Key
Alternative field name.
AlternativeField[] LocalizedDescriptions
Localized descriptions of domain
static DomainConfiguration Instance
Current instance of configuration.
string HumanReadableDescription
Human-readable description of domain
string HumanReadableDescriptionLanguage
Language of HumanReadableDescription.
string HumanReadableName
Human-readable name of domain
AlternativeField[] LocalizedNames
Localized names of domain
bool UseEncryption
If the server uses server-side encryption.
string HumanReadableNameLanguage
Language of HumanReadableName.
Base class for all HTTP authentication schemes, as defined in RFC-7235: https://datatracker....
HttpFieldAcceptLanguage AcceptLanguage
Accept-Language HTTP Field header. (RFC 2616, §14.4)
Represents an HTTP request.
Definition: HttpRequest.cs:18
HttpRequestHeader Header
Request header.
Definition: HttpRequest.cs:134
static void SetTransparentCorsHeaders(HttpResource Resource, HttpRequest Request, HttpResponse Response)
Sets CORS headers for a resource, allowing it to be embedded in other sites.
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
async Task Return(object Object)
Returns an object to the client. This method can only be called once per response,...
DomainInfo()
Gets information about the domain.
Definition: DomainInfo.cs:18
override HttpAuthenticationScheme[] GetAuthenticationSchemes(HttpRequest Request)
Any authentication schemes used to authenticate users before access is granted to the corresponding r...
Definition: DomainInfo.cs:28
override async Task GET(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
Definition: DomainInfo.cs:41
Abstract base class for agent resources supporting the GET method.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd