4using System.Threading.Tasks;
25 private string globalComponentsJsFileName =
null;
26 private string alertPopupMdFileName =
null;
27 private string confirmPopupMdFileName =
null;
28 private string promptPopupMdFileName =
null;
29 private string masterJs =
null;
30 private string alertPopupJs =
null;
31 private string confirmPopupJs =
null;
32 private string promptPopupJs =
null;
33 private DateTime masterJsLastModified = DateTime.MinValue;
34 private DateTime alertPopupJsLastModified = DateTime.MinValue;
35 private DateTime confirmPopupJsLastModified = DateTime.MinValue;
36 private DateTime promptPopupJsLastModified = DateTime.MinValue;
37 private DateTime lastModified = DateTime.MinValue;
38 private byte[] masterJsData =
null;
39 private string contentType =
null;
60 get => this.resourceMap;
61 internal set => this.resourceMap = value;
88 bool Modified =
false;
90 if (
string.IsNullOrEmpty(this.globalComponentsJsFileName))
92 if (!this.resourceMap.
TryGetFileName(
"/GlobalComponents.js", out
this.globalComponentsJsFileName))
93 this.globalComponentsJsFileName = Path.Combine(
Gateway.
RootFolder,
"GlobalComponents.js");
96 if (
string.IsNullOrEmpty(this.alertPopupMdFileName))
98 if (!this.resourceMap.
TryGetFileName(
"/AlertPopup.md", out
this.alertPopupMdFileName))
102 if (
string.IsNullOrEmpty(this.confirmPopupMdFileName))
104 if (!this.resourceMap.
TryGetFileName(
"/ConfirmPopup.md", out
this.confirmPopupMdFileName))
105 this.confirmPopupMdFileName = Path.Combine(
Gateway.
RootFolder,
"ConfirmPopup.md");
108 if (
string.IsNullOrEmpty(this.promptPopupMdFileName))
110 if (!this.resourceMap.
TryGetFileName(
"/PromptPopup.md", out
this.promptPopupMdFileName))
114 if ((TP = File.GetLastWriteTimeUtc(
this.globalComponentsJsFileName)) >
this.masterJsLastModified ||
115 this.masterJs is
null)
117 this.masterJs = await File.ReadAllTextAsync(this.globalComponentsJsFileName);
118 this.masterJsLastModified = TP;
121 if (TP > this.lastModified)
122 this.lastModified = TP;
125 if ((TP = File.GetLastWriteTimeUtc(
this.alertPopupMdFileName)) >
this.alertPopupJsLastModified ||
126 this.alertPopupJs is
null)
128 this.alertPopupJs = await MarkdownToJavaScript(this.alertPopupMdFileName);
129 this.alertPopupJsLastModified = TP;
132 if (TP > this.lastModified)
133 this.lastModified = TP;
136 if ((TP = File.GetLastWriteTimeUtc(
this.confirmPopupMdFileName)) >
this.confirmPopupJsLastModified ||
137 this.confirmPopupJs is
null)
139 this.confirmPopupJs = await MarkdownToJavaScript(this.confirmPopupMdFileName);
140 this.confirmPopupJsLastModified = TP;
143 if (TP > this.lastModified)
144 this.lastModified = TP;
147 if ((TP = File.GetLastWriteTimeUtc(
this.promptPopupMdFileName)) >
this.promptPopupJsLastModified ||
148 this.promptPopupJs is
null)
150 this.promptPopupJs = await MarkdownToJavaScript(this.promptPopupMdFileName);
151 this.promptPopupJsLastModified = TP;
154 if (TP > this.lastModified)
155 this.lastModified = TP;
158 if (Modified || this.masterJsData is
null)
160 StringBuilder sb =
new StringBuilder();
162 sb.AppendLine(this.masterJs);
164 sb.AppendLine(this.alertPopupJs);
166 sb.AppendLine(this.confirmPopupJs);
168 sb.AppendLine(this.promptPopupJs);
170 this.contentType = JavaScriptCodec.DefaultContentType +
"; charset=utf-8";
171 this.masterJsData =
System.Text.Encoding.UTF8.GetBytes(sb.ToString());
174 Response.ContentType = this.contentType;
175 await Response.
Write(
true, this.masterJsData);
178 private static async Task<string> MarkdownToJavaScript(
string FileName)
180 string Markdown = await File.ReadAllTextAsync(FileName);
183 ParseMetaData =
false,
184 AllowInlineScript =
true,
188 string JavaScript = await Doc.GenerateJavaScript();
Contains a markdown document. This markdown document class supports original markdown,...
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Contains settings that the Markdown parser uses to customize its behavior.
Static class managing the runtime environment of the IoT Gateway.
static string RootFolder
Web root folder.
A resource that returns as a single JavaScript file, the following four files:
override bool HandlesSubPaths
If the resource handles sub-paths.
MasterJavascript(IResourceMap ResourceMap)
A resource that returns as a single JavaScript file, the following four files:
IResourceMap ResourceMap
How resources are mapped on the server.
bool AllowsGET
If the GET method is allowed.
override bool UserSessions
If the resource uses user sessions.
async Task GET(HttpRequest Request, HttpResponse Response)
Executes the GET method on the resource.
Represents an HTTP request.
Represets a response of an HTTP client request.
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...
Basic interface for Resource maps.
bool TryGetFileName(string LocalUrl, out string FileName)
Tries to get the full path of a file-based resource.
GET Interface for HTTP resources.