2using System.Collections.Generic;
5using System.Threading.Tasks;
19 private static readonly Dictionary<string, KeyValuePair<FolderNode, FileSystemWatcher>> watchers =
new Dictionary<string, KeyValuePair<FolderNode, FileSystemWatcher>>();
20 private static readonly SemaphoreSlim synchObj =
new SemaphoreSlim(1);
37 private async Task CheckNode(
INode Node)
62 await synchObj.WaitAsync();
65 foreach (KeyValuePair<FolderNode, FileSystemWatcher> P
in watchers.Values)
76 internal static async Task StopSynchronization(
string FolderPath)
78 await synchObj.WaitAsync();
81 if (watchers.TryGetValue(FolderPath, out KeyValuePair<FolderNode, FileSystemWatcher> P))
83 watchers.Remove(FolderPath);
93 internal static async Task CheckSynchronization(FolderNode Node)
97 FileSystemWatcher Watcher;
99 await synchObj.WaitAsync();
102 if (watchers.TryGetValue(Node.FolderPath, out KeyValuePair<FolderNode, FileSystemWatcher> P))
104 P.Value.Changed -= Node.Watcher_Changed;
105 P.Value.Created -= Node.Watcher_Created;
106 P.Value.Deleted -= Node.Watcher_Deleted;
107 P.Value.Renamed -= Node.Watcher_Renamed;
108 P.Value.Error -= Node.Watcher_Error;
110 P.Value.EnableRaisingEvents =
false;
112 watchers.Remove(Node.FolderPath);
116 if (!Directory.Exists(Node.FolderPath))
117 Directory.CreateDirectory(Node.FolderPath);
121 if (
string.IsNullOrEmpty(Node.FileFilter))
122 Watcher =
new FileSystemWatcher(Node.FolderPath);
124 Watcher =
new FileSystemWatcher(Node.FolderPath, Node.FileFilter);
126 watchers[Node.FolderPath] =
new KeyValuePair<FolderNode, FileSystemWatcher>(Node, Watcher);
128 Watcher.NotifyFilter =
129 NotifyFilters.Attributes |
130 NotifyFilters.CreationTime |
131 NotifyFilters.DirectoryName |
132 NotifyFilters.FileName |
133 NotifyFilters.LastAccess |
134 NotifyFilters.LastWrite |
135 NotifyFilters.Security |
138 Watcher.Changed += Node.Watcher_Changed;
139 Watcher.Created += Node.Watcher_Created;
140 Watcher.Deleted += Node.Watcher_Deleted;
141 Watcher.Renamed += Node.Watcher_Renamed;
142 Watcher.Error += Node.Watcher_Error;
145 Watcher.EnableRaisingEvents =
true;
153 await Node.SynchFolder();
154 await Node.RemoveErrorAsync(
"SynchError");
158 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.