Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ReportFileNode.cs
1using System;
2using System.IO;
3using System.Threading.Tasks;
4using Waher.Events;
7using Waher.Script;
8using Waher.Things;
9
10namespace Waher.Reports.Files
11{
16 {
17 private readonly string fileName;
18 private ReportFile parsedReport = null;
19 private DateTime reportTimestamp = DateTime.MinValue;
20
28 : base(NodeId, Parent)
29 {
30 this.fileName = Path.GetFullPath(FileName);
31 }
32
36 public string FileName => this.fileName;
37
42 {
43 get
44 {
45 try
46 {
47 if (this.parsedReport is null || File.GetLastWriteTimeUtc(this.fileName) > this.reportTimestamp)
48 {
49 this.parsedReport = new ReportFile(this.fileName);
50 this.reportTimestamp = File.GetLastWriteTimeUtc(this.fileName);
51 }
52
53 return this.parsedReport;
54 }
55 catch (Exception ex)
56 {
57 Log.Exception(ex);
58
59 return null;
60 }
61 }
62 }
63
69 public override Task<ExecuteReport> GetExecuteCommand()
70 {
71 ReportFile Report = this.ParsedReport;
72 if (Report is null)
73 return Task.FromResult<ExecuteReport>(null);
74
75 ExecuteReportFileCommand Command = new ExecuteReportFileCommand(Report, this, new Variables());
76 return Task.FromResult<ExecuteReport>(Command);
77 }
78
84 public override Task<bool> CanViewAsync(RequestOrigin Caller)
85 {
86 ReportFile Report = this.ParsedReport;
87 if (Report is null)
88 return Task.FromResult(false);
89
90 if (Report.Privileges.Length == 0)
91 return Task.FromResult(true);
92
93 foreach (string Privilege in Report.Privileges)
94 {
95 if (!Caller.HasPrivilege(Privilege))
96 return Task.FromResult(false);
97 }
98
99 return Task.FromResult(true);
100 }
101 }
102}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1657
Abstract base class for commands executing a report.
Contains a parsed report, as defined in a report file.
Definition: ReportFile.cs:23
string[] Privileges
Privileges required to execute the report.
Definition: ReportFile.cs:288
Report node based on the contents of a report file.
ReportFileNode(string FileName, string NodeId, ReportNode Parent)
Report node based on the contents of a report file.
override Task< bool > CanViewAsync(RequestOrigin Caller)
If the node is visible to the caller.
ReportFile ParsedReport
Parsed report, or null if unable to parse report.
override Task< ExecuteReport > GetExecuteCommand()
Gets the command object to execute a report. If null is returned, the report node is just a group pla...
string FileName
Report file name.
Abstract base class for report nodes.
Definition: ReportNode.cs:15
INode Parent
Parent Node, or null if a root node.
Definition: ReportNode.cs:107
string NodeId
ID of node.
Definition: ReportNode.cs:39
Collection of variables.
Definition: Variables.cs:25
Tokens available in request.
Definition: RequestOrigin.cs:9