5using System.Threading.Tasks;
20 private static readonly Dictionary<string, KeyValuePair<FolderNode, FileSystemWatcher>> watchers =
new Dictionary<string, KeyValuePair<FolderNode, FileSystemWatcher>>();
21 private static readonly SemaphoreSlim synchObj =
new SemaphoreSlim(1);
38 private async Task CheckNode(
INode Node)
54 await this.CheckNode(Child);
63 await synchObj.WaitAsync();
66 foreach (KeyValuePair<FolderNode, FileSystemWatcher> P
in watchers.Values)
77 internal static async Task StopSynchronization(
string FolderPath)
79 await synchObj.WaitAsync();
82 if (watchers.TryGetValue(FolderPath, out KeyValuePair<FolderNode, FileSystemWatcher> P))
84 watchers.Remove(FolderPath);
94 internal static async Task CheckSynchronization(FolderNode Node)
98 FileSystemWatcher Watcher;
100 await synchObj.WaitAsync();
103 if (watchers.TryGetValue(Node.FolderPath, out KeyValuePair<FolderNode, FileSystemWatcher> P))
105 P.Value.Changed -= Node.Watcher_Changed;
106 P.Value.Created -= Node.Watcher_Created;
107 P.Value.Deleted -= Node.Watcher_Deleted;
108 P.Value.Renamed -= Node.Watcher_Renamed;
109 P.Value.Error -= Node.Watcher_Error;
111 P.Value.EnableRaisingEvents =
false;
113 watchers.Remove(Node.FolderPath);
117 if (!Directory.Exists(Node.FolderPath))
118 Directory.CreateDirectory(Node.FolderPath);
122 if (
string.IsNullOrEmpty(Node.FileFilter))
123 Watcher =
new FileSystemWatcher(Node.FolderPath);
125 Watcher =
new FileSystemWatcher(Node.FolderPath, Node.FileFilter);
127 watchers[Node.FolderPath] =
new KeyValuePair<FolderNode, FileSystemWatcher>(Node, Watcher);
129 Watcher.InternalBufferSize = 65536;
130 Watcher.NotifyFilter =
131 NotifyFilters.Attributes |
132 NotifyFilters.CreationTime |
133 NotifyFilters.DirectoryName |
134 NotifyFilters.FileName |
135 NotifyFilters.LastAccess |
136 NotifyFilters.LastWrite |
137 NotifyFilters.Security |
140 Watcher.Changed += Node.Watcher_Changed;
141 Watcher.Created += Node.Watcher_Created;
142 Watcher.Deleted += Node.Watcher_Deleted;
143 Watcher.Renamed += Node.Watcher_Renamed;
144 Watcher.Error += Node.Watcher_Error;
147 Watcher.EnableRaisingEvents =
true;
155 await Node.SynchFolder();
156 await Node.RemoveErrorAsync(
"SynchError");
160 await Node.LogErrorAsync(
"SynchError", ex.Message);
Static class managing the application event log. Applications and services log events on this static ...
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.
Module maintaining active file system watchers.
async Task Stop()
Stops the module.
async Task Start()
Starts the module.
Represents a file folder in the file system.
Task Synchronize()
Synchronizes folder, subfolders, files and nodes.
Defines the Metering Topology data source. This data source contains a tree structure of persistent r...
static Root Root
Root node.
Virtual node, that can be used as a placeholder for services.
Interface for late-bound modules loaded at runtime.
Interface for nodes that are published through the concentrator interface.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
SynchronizationOptions
How a folder will synchronize nodes with contents of folders.