Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DomainInfo.cs
2using System.Threading.Tasks;
3using Waher.Content;
6
8{
13 {
17 public DomainInfo()
18 : base("Account/DomainInfo")
19 {
20 }
21
30 {
31 return null;
32 }
33
42 public override async Task GET(HttpRequest Request, HttpResponse Response)
43 {
44 await base.GET(Request, Response);
45
46 SetTransparentCorsHeaders(this, Request, Response);
47
48 string Name = this.SelectString(Request,
52
53 string Description = this.SelectString(Request,
57
58 await Response.Return(new NamedDictionary<string, object>("DomainInfo", AgentNamespace)
59 {
60 { "domain", DomainConfiguration.Instance?.Domain ?? string.Empty },
61 { "useEncryption", DomainConfiguration.Instance?.UseEncryption ?? false },
62 { "humanReadableName", Name?? string.Empty },
63 { "humanReadableDescription", Description ?? string.Empty }
64 });
65 }
66
67 private string SelectString(HttpRequest Request, string Default, string DefaultLanguage,
68 AlternativeField[] Localizations)
69 {
70 if (Request.Header.AcceptLanguage is null)
71 return Default;
72
73 string[] Languages = GetLanguages(DefaultLanguage, Localizations);
74 string Language = Request.Header.AcceptLanguage.GetBestAlternative(Languages);
75
76 if (string.IsNullOrEmpty(Language) || DefaultLanguage == Language)
77 return Default;
78
79 if (!(Localizations is null))
80 {
81 foreach (AlternativeField Localization in Localizations)
82 {
83 if (Localization.Key == Language)
84 return Localization.Value;
85 }
86 }
87
88 return Default;
89 }
90
91 private static string[] GetLanguages(string DefaultLanguage, AlternativeField[] Localizations)
92 {
93 List<string> Languages = new List<string>();
94
95 if (!string.IsNullOrEmpty(DefaultLanguage))
96 Languages.Add(DefaultLanguage);
97
98 if (!(Localizations is null))
99 {
100 foreach (AlternativeField Localization in Localizations)
101 {
102 if (!string.IsNullOrEmpty(Localization.Key))
103 Languages.Add(Localization.Key);
104 }
105 }
106
107 return Languages.ToArray();
108 }
109 }
110}
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:22
HttpRequestHeader Header
Request header.
Definition: HttpRequest.cs:182
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:23
Task Return(Exception ex)
Returns an error to the client.
DomainInfo()
Gets information about the domain.
Definition: DomainInfo.cs:17
override HttpAuthenticationScheme[] GetAuthenticationSchemes(HttpRequest Request)
Any authentication schemes used to authenticate users before access is granted to the corresponding r...
Definition: DomainInfo.cs:29
override async Task GET(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
Definition: DomainInfo.cs:42
Abstract base class for agent resources supporting the GET method.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd