Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmppStatisticsCommand.cs
1using System;
3using System.Threading.Tasks;
7using Waher.Things;
10
12{
14 {
20 : base(Report)
21 {
22 }
23
24 [Page(1, "Time", 150)]
25 [Header(2, "From:")]
26 [ToolTip(3, "Search for records from this point in time.")]
27 public DateTime From = DateTime.Today.AddDays(-1);
28
29 [Page(1, "Time", 150)]
30 [Header(4, "To:")]
31 [ToolTip(5, "Search for records to this point in time.")]
32 public DateTime To = DateTime.Today.AddDays(1);
33
34 public override Task<string> GetNameAsync(Language Language)
35 {
36 return Language.GetStringAsync(typeof(XmppStatisticsCommand), 6, "Statistics...");
37 }
38
39 public override ICommand Copy()
40 {
42 {
43 From = this.From,
44 To = this.To
45 };
46 }
47
49 {
50 this.Execute(Query, Language);
51 return Task.CompletedTask;
52 }
53
54 private async void Execute(Query Query, Language Language)
55 {
56 try
57 {
58 await Query.Start();
59 await Query.SetTitle(await Language.GetStringAsync(typeof(XmppStatisticsCommand), 15, "Requests"));
60
61 if (this.To < this.From)
62 {
63 DateTime Temp = this.To;
64 this.To = this.From;
65 this.From = Temp;
66 }
67
68 List<Filter> Filters = new List<Filter>();
69 if (this.From > DateTime.MinValue)
70 Filters.Add(new FilterFieldGreaterOrEqualTo("Timestamp", this.From));
71
72 if (this.To < DateTime.MaxValue)
73 Filters.Add(new FilterFieldLesserOrEqualTo("Timestamp", this.To));
74
75 await Query.SetStatus(await Language.GetStringAsync(typeof(XmppStatisticsCommand), 8, "Searching database..."));
76
77 IEnumerable<XmppStatistic> Records = Filters.Count switch
78 {
79 0 => await Database.Find<XmppStatistic>("Timestamp"),
80 1 => await Database.Find<XmppStatistic>(Filters[0], "Timestamp"),
81 _ => await Database.Find<XmppStatistic>(new FilterAnd(Filters.ToArray()), "Timestamp"),
82 };
83
84 string Header = await Language.GetStringAsync(typeof(XmppStatisticsCommand), 17, "XMPP Statistics");
85 await Query.BeginSection(Header);
86 await Query.NewTable("Statistics", Header, new Column[]
87 {
88 new Column("Start", await Language.GetStringAsync(typeof(XmppStatisticsCommand), 10, "Start"),
89 null, null, null, null, ColumnAlignment.Left, null),
90 new Column("Timestamp", await Language.GetStringAsync(typeof(XmppStatisticsCommand), 11, "Timestamp"),
91 null, null, null, null, ColumnAlignment.Left, null),
92 new Column("Requests", await Language.GetStringAsync(typeof(XmppStatisticsCommand), 16, "#Stanzas"),
93 null, null, null, null, ColumnAlignment.Right, null),
94 new Column("Rx", await Language.GetStringAsync(typeof(XmppStatisticsCommand), 13, "#Rx"),
95 null, null, null, null, ColumnAlignment.Right, null),
96 new Column("Tx", await Language.GetStringAsync(typeof(XmppStatisticsCommand), 14, "#Tx"),
97 null, null, null, null, ColumnAlignment.Right, null)
98 });
99
100 foreach (XmppStatistic Rec in Records)
101 {
102 await Query.NewRecords("Statistics", new Record(new object[]
103 {
104 Rec.Start,
105 Rec.Timestamp,
106 Rec.NrStanzas,
107 Rec.NrBytesRx,
108 Rec.NrBytesTx
109 }));
110 }
111
112 await Query.TableDone("Statistics");
113 await Query.EndSection();
114 }
115 catch (Exception ex)
116 {
117 await Query.LogMessage(ex);
118 }
119 finally
120 {
121 await Query.Done();
122 }
123 }
124
125 }
126}
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
Definition: Database.cs:238
This filter selects objects that conform to all child-filters provided.
Definition: FilterAnd.cs:10
This filter selects objects that have a named field greater or equal to a given value.
This filter selects objects that have a named field lesser or equal to a given value.
ReportNode Report
Report node.
Contains information about a language.
Definition: Language.cs:17
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Definition: Language.cs:209
Abstract base class for commands executing a server administrator report.
override Task StartQueryExecutionAsync(Query Query, Language Language)
Starts the execution of a query.
override Task< string > GetNameAsync(Language Language)
Gets the displayable name of the command.
XmppStatisticsCommand(XmppProtocol Report)
Executes the XMPP Statistics report.
Defines a column in a table.
Definition: Column.cs:30
Class handling the reception of data from a query.
Definition: Query.cs:12
Task TableDone(string TableId)
Reports a table as being complete.
Definition: Query.cs:327
Task EndSection()
Ends a section. Each call to BeginSection(string) must be followed by a call to EndSection().
Definition: Query.cs:504
Task Start()
Starts query execution.
Definition: Query.cs:213
Task NewRecords(string TableId, params Record[] Records)
Reports a new set of records in a table.
Definition: Query.cs:300
Task BeginSection(string Header)
Begins a new section. Sections can be nested. Each call to BeginSection(string) must be followed by a...
Definition: Query.cs:483
Task NewTable(string TableId, string TableName, params Column[] Columns)
Defines a new table in the query output.
Definition: Query.cs:272
Task LogMessage(Exception Exception)
Logs an Exception as a query message.
Definition: Query.cs:381
async Task Done()
Query execution completed.
Definition: Query.cs:241
Task SetStatus(string Status)
Sets the current status of the query execution.
Definition: Query.cs:457
Task SetTitle(string Title)
Sets the title of the report.
Definition: Query.cs:430
Defines a record in a table.
Definition: Record.cs:9
Interface for commands.
Definition: ICommand.cs:32
Definition: ImplTypes.g.cs:58
ColumnAlignment
Column alignment.
Definition: Column.cs:9