Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
HttpConfigurableFileResource.cs
1using System;
2using System.IO;
3using System.Threading.Tasks;
6
8{
13 {
14 private readonly string fileName;
15 private readonly string contentType;
16 private readonly bool isText;
17
23 public HttpConfigurableFileResource(string ResourceName, string FileName)
24 : this(ResourceName, FileName, PlainTextCodec.DefaultContentType, true)
25 {
26 }
27
34 public HttpConfigurableFileResource(string ResourceName, string FileName, string ContentType)
35 : this(ResourceName, FileName, ContentType, true)
36 {
37 }
38
46 public HttpConfigurableFileResource(string ResourceName, string FileName, string ContentType, bool IsText)
47 : base(ResourceName)
48 {
49 this.fileName = Path.GetFullPath(FileName);
50 this.contentType = ContentType;
51 this.isText = IsText;
52 }
53
57 public override bool HandlesSubPaths => false;
58
62 public override bool UserSessions => false;
63
67 public bool AllowsGET => true;
68
75 public async Task GET(HttpRequest Request, HttpResponse Response)
76 {
77 DateTime TP = await DomainSettings.GetFileSettingTimestampAsync(Request, this.fileName);
78
79 Response.ContentType = this.contentType;
80 Response.Date = TP;
81
82 if (this.isText)
83 {
84 string Content = await DomainSettings.GetTextFileSettingAsync(Request, this.fileName);
85 await Response.Write(Content);
86 }
87 else
88 {
89 byte[] Content = await DomainSettings.GetBinaryFileSettingAsync(Request, this.fileName);
90
91 Response.ContentLength = Content.Length;
92
93 await Response.Write(Content);
94 }
95 }
96 }
97}
Plain text encoder/decoder.
static Task< string > GetTextFileSettingAsync(IHostReference HostRef, string FileName)
Gets the contents of a configurable domain-sensitive text file.
static Task< byte[]> GetBinaryFileSettingAsync(IHostReference HostRef, string FileName)
Gets the contents of a configurable domain-sensitive binary file.
static Task< DateTime > GetFileSettingTimestampAsync(IHostReference HostRef, string FileName)
Gets the timestamp of contents of a configurable domain-sensitive file.
Represents a file-based resource that can have custom values depending on what domain the resource is...
HttpConfigurableFileResource(string ResourceName, string FileName)
Represents a file-based resource that can have custom values depending on what domain the resource is...
HttpConfigurableFileResource(string ResourceName, string FileName, string ContentType)
Represents a file-based resource that can have custom values depending on what domain the resource is...
override bool HandlesSubPaths
If the resource handles sub-paths.
async Task GET(HttpRequest Request, HttpResponse Response)
Executes the GET method on the resource.
HttpConfigurableFileResource(string ResourceName, string FileName, string ContentType, bool IsText)
Represents a file-based resource that can have custom values depending on what domain the resource is...
override bool UserSessions
If the resource uses user sessions.
Represents an HTTP request.
Definition: HttpRequest.cs:18
string ResourceName
Name of resource.
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
async Task Write(byte[] Data)
Returns binary data in the response.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
GET Interface for HTTP resources.