4using System.Threading.Tasks;
25 private readonly
string gatewayConfigFile;
26 private readonly
string wafFile;
27 private FileSystemWatcher watcher;
39 this.delayedUpdates.Removed += this.DelayedUpdates_Removed;
43 IncludeSubdirectories =
true,
44 EnableRaisingEvents =
true,
45 InternalBufferSize = 65536,
47 NotifyFilters.Attributes |
48 NotifyFilters.CreationTime |
49 NotifyFilters.DirectoryName |
50 NotifyFilters.FileName |
51 NotifyFilters.LastAccess |
52 NotifyFilters.LastWrite |
53 NotifyFilters.Security |
57 this.watcher.Changed += this.Watcher_Changed;
58 this.watcher.Created += this.Watcher_Created;
59 this.watcher.Deleted += this.Watcher_Deleted;
60 this.watcher.Renamed += this.Watcher_Renamed;
61 this.watcher.Error += this.Watcher_Error;
69 if (!(this.delayedUpdates is
null))
71 this.delayedUpdates.Removed -= this.DelayedUpdates_Removed;
73 this.delayedUpdates =
null;
76 if (!(this.watcher is
null))
78 this.watcher.Changed -= this.Watcher_Changed;
79 this.watcher.Created -= this.Watcher_Created;
80 this.watcher.Deleted -= this.Watcher_Deleted;
81 this.watcher.Renamed -= this.Watcher_Renamed;
82 this.watcher.Error -= this.Watcher_Error;
84 this.watcher.Dispose();
92 string IDataSource.SourceID =>
SourceID;
122 if (FolderPath != Path.GetFullPath(FolderPath))
123 return Array.Empty<
INode>();
126 return Array.Empty<
INode>();
128 SortedDictionary<string, INode> Result1 =
new SortedDictionary<string, INode>(StringComparer.InvariantCultureIgnoreCase);
129 SortedDictionary<string, INode> Result2 =
new SortedDictionary<string, INode>(StringComparer.InvariantCultureIgnoreCase);
133 DirectoryInfo DirInfo =
new DirectoryInfo(FolderPath);
136 DirectoryInfo[] Directories = DirInfo.GetDirectories();
137 FileInfo[] Files = DirInfo.GetFiles();
139 foreach (DirectoryInfo Directory
in Directories)
140 Result1[Directory.Name] =
new ProgramDataFolder(Directory.FullName, FolderNode, Directory.CreationTimeUtc, Directory.LastWriteTimeUtc);
142 foreach (FileInfo File
in Files)
143 Result2[File.Name] =
new ProgramDataFile(File.FullName, FolderNode, File.CreationTimeUtc, File.LastAccessTimeUtc, File.Length);
146 List<INode> Result =
new List<INode>();
148 Result.AddRange(Result1.Values);
149 Result.AddRange(Result2.Values);
157 public event EventHandlerAsync<SourceEvent>
OnEvent;
187 return Task.FromResult<
INode>(
null);
201 if (Path !=
System.IO.Path.GetFullPath(Path))
208 string ParentFolder = Directory.GetParent(Path).FullName;
214 if (FileReference && File.Exists(Path))
217 if (FolderReference && Directory.Exists(Path))
225 return this.OnEvent.Raise(
this,
Event);
241 await this.RaiseSourceEvent(e.
Value);
251 private async Task RaiseSourceEventFlushDelayed(
NodeEvent Event,
bool DiscardDelayed)
258 await this.RaiseSourceEvent(PrevEvent);
261 await this.RaiseSourceEvent(
Event);
264 private void Watcher_Error(
object Sender, ErrorEventArgs e)
266 Exception Exception = e.GetException();
270 private async
void Watcher_Renamed(
object Sender, RenamedEventArgs e)
274 if (!(this.OnEvent is
null))
298 private async
void Watcher_Deleted(
object Sender, FileSystemEventArgs e)
302 if (!(this.OnEvent is
null))
307 ??
new ProgramDataFile(e.FullPath,
null,
null,
null,
null);
323 private async
void Watcher_Created(
object Sender, FileSystemEventArgs e)
327 if (!(this.OnEvent is
null))
348 private async
void Watcher_Changed(
object Sender, FileSystemEventArgs e)
352 if (!(this.OnEvent is
null))
367 if (
string.Compare(e.FullPath,
this.gatewayConfigFile,
true) == 0)
369 else if (
string.Compare(e.FullPath,
this.wafFile,
true) == 0)
378 private async Task ReloadWafDefinition(
object _)
Class representing an event.
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.
Static class managing the runtime environment of the IoT Gateway.
const string WebApplicationFirewallLocalFileName
WAF.xml
static string AppDataFolder
Application data folder.
static DateTime ScheduleEvent(Action< object > Callback, DateTime When, object State)
Schedules a one-time event.
static async Task CheckWAF()
Checks the Web Application Firewall file and loads or reloads it if necessary.
const string GatewayConfigLocalFileName
Gateway.config
Implements an in-memory cache.
void Dispose()
IDisposable.Dispose
bool Remove(KeyType Key)
Removes an item from the cache.
bool TryGetValue(KeyType Key, out ValueType Value)
Tries to get a value from the cache.
Event arguments for cache item removal events.
ValueType Value
Value of item that was removed.
RemovedReason Reason
Reason for removing the item.
Contains information about a language.
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 ...
Basic access point for runtime language localization.
static async Task< Language > GetDefaultLanguageAsync()
Gets the default language.
Data source mirroring the Gateway.config file.
Reference to a file in the ProgramData folder of the broker.
Reference to a folder in the ProgramData folder of the broker.
Data source mirroring the ProgramData folder for the broker.
Task< string > GetNameAsync(Language Language)
Gets the displayable name of the command.
static IEnumerable< INode > GetChildNodes(ProgramDataFolder FolderNode, string FolderPath)
Gets a set of program data child nodes, for a folder.
const string SourceID
Data Source ID for the ProgramData source.
Task< INode > GetNodeAsync(IThingReference NodeRef)
Gets the node, given a reference to it.
IEnumerable< INode > RootNodes
Root node references. If no root nodes are available, null is returned.
void Dispose()
IDisposable.Dispose
Task< bool > CanViewAsync(RequestOrigin Caller)
If the data source is visible to the caller.
DateTime LastChanged
When the source was last updated.
EventHandlerAsync< SourceEvent > OnEvent
Event raised when a data source event has been raised.
ProgramDataSource()
Data source mirroring the ProgramData folder for the broker.
IEnumerable< IDataSource > ChildSources
Child sources. If no child sources are available, null is returned.
bool HasChildren
If the source has any child sources.
static INode GetProgramDataNode(string Path, bool FileReference, bool FolderReference)
Gets a node, given a program data path.
Tokens available in request.
static readonly RequestOrigin Empty
Empty request origin.
bool HasPrivilege(string Privilege)
If the origin has a given privilege.
static Task< NodeAdded > FromNode(INode Node, Language Language, RequestOrigin Caller, bool Sniffable)
Creates an event object from a node object.
Abstract base class for all node events.
static NodeRemoved FromNode(INode Node)
Creates an event object from a node object.
static Task< NodeUpdated > FromNode(INode Node, Language Language, RequestOrigin Caller)
Creates an event object from a node object.
Abstract base class for all data source events.
Interface for datasources that are published through the concentrator interface.
Interface for nodes that are published through the concentrator interface.
Interface for thing references.
string Partition
Optional partition in which the Node ID is unique.
string SourceId
Optional ID of source containing node.
RemovedReason
Reason for removing the item.