Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SynchronizationStatistics.cs
1using System;
2using System.Collections.Generic;
3using System.Runtime.InteropServices.ComTypes;
4using System.Threading.Tasks;
5using Waher.Events;
7
9{
14 {
15 private readonly Dictionary<string, string> folderIds = new Dictionary<string, string>();
16 private readonly Query query;
17 private readonly FolderNode node;
18 private int nrFoldersAdded = 0;
19 private int nrFoldersFound = 0;
20 private int nrFoldersDeleted = 0;
21 private int nrFilesAdded = 0;
22 private int nrFilesFound = 0;
23 private int nrFilesDeleted = 0;
24
31 {
32 this.node = Node;
33 this.query = Query;
34 }
35
36 private async Task<string> GetFolderTableId(string Folder)
37 {
38 if (this.folderIds.TryGetValue(Folder, out string TableId))
39 return TableId;
40
41 TableId = "F" + (this.folderIds.Count + 1).ToString();
42 this.folderIds[Folder] = TableId;
43
44 await this.query.BeginSection(Folder);
45 await this.query.NewTable(TableId, "Files in " + Folder,
46 new Column("FileName", "Filename", null, null, null, null, ColumnAlignment.Left, null),
47 new Column("Action", "Action", null, null, null, null, ColumnAlignment.Left, null));
48
49 return TableId;
50 }
51
57 public async Task FileFound(string Folder, string FileName)
58 {
59 string TableId = await this.GetFolderTableId(Folder);
60
61 await this.query.NewRecords(TableId, new Record(FileName, "-"));
62
63 this.nrFilesFound++;
64 }
65
71 public async Task FolderFound(string Folder, string SubFolder)
72 {
73 string TableId = await this.GetFolderTableId(Folder);
74
75 await this.query.NewRecords(TableId, new Record(SubFolder, "-"));
76
77 this.nrFoldersFound++;
78 }
79
85 public async Task FileAdded(string Folder, string FileName)
86 {
87 string TableId = await this.GetFolderTableId(Folder);
88
89 await this.query.NewRecords(TableId, new Record(FileName, "Added"));
90
91 this.nrFilesAdded++;
92 }
93
99 public async Task FolderAdded(string Folder, string SubFolder)
100 {
101 string TableId = await this.GetFolderTableId(Folder);
102
103 await this.query.NewRecords(TableId, new Record(SubFolder, "Added"));
104
105 this.nrFoldersAdded++;
106 }
107
113 public async Task FileDeleted(string Folder, string FileName)
114 {
115 string TableId = await this.GetFolderTableId(Folder);
116
117 await this.query.NewRecords(TableId, new Record(FileName, "Deleted"));
118
119 this.nrFilesDeleted++;
120 }
121
127 public async Task FolderDeleted(string Folder, string SubFolder)
128 {
129 string TableId = await this.GetFolderTableId(Folder);
130
131 await this.query.NewRecords(TableId, new Record(SubFolder, "Deleted"));
132
133 this.nrFoldersDeleted++;
134 }
135
139 public async Task Start()
140 {
141 await this.query.Start();
142 await this.query.SetTitle(this.node.FolderPath);
143
144 await this.query.BeginSection("Title");
145 await this.query.NewTable("Totals", "Totals",
146 new Column("Key", "Metric", string.Empty, string.Empty, null, null, ColumnAlignment.Left, null),
147 new Column("Value", "Value", string.Empty, string.Empty, null, null, ColumnAlignment.Right, null));
148 await this.query.EndSection();
149 }
150
155 public async Task Error(Exception ex)
156 {
157 await this.query.LogMessage(ex);
158 }
159
163 public async Task Done()
164 {
165 await this.query.NewRecords("Totals",
166 new Record("#Files Existed", this.nrFilesFound),
167 new Record("#Files Added", this.nrFilesAdded),
168 new Record("#Files Deleted", this.nrFilesDeleted),
169 new Record("#Folders Existed", this.nrFoldersFound),
170 new Record("#Folders Added", this.nrFoldersAdded),
171 new Record("#Folders Deleted", this.nrFoldersDeleted));
172 await this.query.TableDone("Totals");
173
174 foreach (KeyValuePair<string, string> P in this.folderIds)
175 await this.query.TableDone(P.Value);
176
177 await this.query.Done();
178 }
179 }
180}
Generates basic statistics around a folder synchronization process.
async Task FileDeleted(string Folder, string FileName)
File node deleted from topology.
async Task FileFound(string Folder, string FileName)
File found, corresponding to node in topology.
async Task FileAdded(string Folder, string FileName)
File node added to topology.
async Task FolderAdded(string Folder, string SubFolder)
Subfolder node added to topology.
async Task Error(Exception ex)
An exception has occurred during synchronization.
async Task FolderDeleted(string Folder, string SubFolder)
Subfolder node deleted from topology.
async Task FolderFound(string Folder, string SubFolder)
Subfolder found, corresponding to node in topology.
SynchronizationStatistics(FolderNode Node, Query Query)
Generates basic statistics around a folder synchronization process.
Represents a file folder in the file system.
Definition: FolderNode.cs:44
Defines a column in a table.
Definition: Column.cs:30
Class handling the reception of data from a query.
Definition: Query.cs:12
Defines a record in a table.
Definition: Record.cs:9
ColumnAlignment
Column alignment.
Definition: Column.cs:9