2using System.Collections.Generic;
4using System.Threading.Tasks;
26 private readonly
string gatewayConfigFile;
27 private FileSystemWatcher watcher;
38 this.delayedUpdates.Removed += this.DelayedUpdates_Removed;
42 IncludeSubdirectories =
true,
43 EnableRaisingEvents =
true,
45 NotifyFilters.Attributes |
46 NotifyFilters.CreationTime |
47 NotifyFilters.DirectoryName |
48 NotifyFilters.FileName |
49 NotifyFilters.LastAccess |
50 NotifyFilters.LastWrite |
51 NotifyFilters.Security |
55 this.watcher.Changed += this.Watcher_Changed;
56 this.watcher.Created += this.Watcher_Created;
57 this.watcher.Deleted += this.Watcher_Deleted;
58 this.watcher.Renamed += this.Watcher_Renamed;
59 this.watcher.Error += this.Watcher_Error;
67 if (!(this.delayedUpdates is
null))
69 this.delayedUpdates.Removed -= this.DelayedUpdates_Removed;
71 this.delayedUpdates =
null;
74 if (!(this.watcher is
null))
76 this.watcher.Changed -= this.Watcher_Changed;
77 this.watcher.Created -= this.Watcher_Created;
78 this.watcher.Deleted -= this.Watcher_Deleted;
79 this.watcher.Renamed -= this.Watcher_Renamed;
80 this.watcher.Error -= this.Watcher_Error;
82 this.watcher.Dispose();
120 if (FolderPath != Path.GetFullPath(FolderPath))
126 SortedDictionary<string, INode> Result1 =
new SortedDictionary<string, INode>(StringComparer.InvariantCultureIgnoreCase);
127 SortedDictionary<string, INode> Result2 =
new SortedDictionary<string, INode>(StringComparer.InvariantCultureIgnoreCase);
129 if (FolderNode is
null)
132 DirectoryInfo DirInfo =
new DirectoryInfo(FolderPath);
135 DirectoryInfo[] Directories = DirInfo.GetDirectories();
136 FileInfo[] Files = DirInfo.GetFiles();
138 foreach (DirectoryInfo Directory
in Directories)
139 Result1[Directory.Name] =
new ProgramDataFolder(Directory.FullName, FolderNode, Directory.CreationTimeUtc, Directory.LastWriteTimeUtc);
141 foreach (FileInfo File
in Files)
142 Result2[File.Name] =
new ProgramDataFile(File.FullName, FolderNode, File.CreationTimeUtc, File.LastAccessTimeUtc, File.Length);
145 List<INode> Result =
new List<INode>();
147 Result.AddRange(Result1.Values);
148 Result.AddRange(Result2.Values);
156 public event EventHandlerAsync<SourceEvent>
OnEvent;
185 if (NodeRef.
SourceId !=
this.SourceID || !
string.IsNullOrEmpty(NodeRef.
Partition))
186 return Task.FromResult<
INode>(
null);
200 if (Path != System.IO.Path.GetFullPath(Path))
207 string ParentFolder = Directory.GetParent(Path).FullName;
213 if (FileReference && File.Exists(Path))
216 if (FolderReference && Directory.Exists(Path))
224 return this.OnEvent.Raise(
this,
Event);
240 await this.RaiseSourceEvent(e.
Value);
250 private async Task RaiseSourceEventFlushDelayed(
NodeEvent Event,
bool DiscardDelayed)
257 await this.RaiseSourceEvent(PrevEvent);
260 await this.RaiseSourceEvent(
Event);
263 private void Watcher_Error(
object Sender, ErrorEventArgs e)
265 Exception Exception = e.GetException();
269 private async
void Watcher_Renamed(
object Sender, RenamedEventArgs e)
273 if (!(this.OnEvent is
null))
297 private async
void Watcher_Deleted(
object Sender, FileSystemEventArgs e)
301 if (!(this.OnEvent is
null))
306 ??
new ProgramDataFile(e.FullPath,
null,
null,
null,
null);
322 private async
void Watcher_Created(
object Sender, FileSystemEventArgs e)
326 if (!(this.OnEvent is
null))
347 private async
void Watcher_Changed(
object Sender, FileSystemEventArgs e)
351 if (!(this.OnEvent is
null))
366 if (
string.Compare(e.FullPath,
this.gatewayConfigFile,
true) == 0)
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.
static string AppDataFolder
Application data folder.
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 name of data source.
static IEnumerable< INode > GetChildNodes(ProgramDataFolder FolderNode, string FolderPath)
Gets a set of program data child nodes, for a folder.
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.
const string ProgramDataSourceID
Data Source ID for the ProgramData source.
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.
string SourceID
ID of data source.
static INode GetProgramDataNode(string Path, bool FileReference, bool FolderReference)
Gets a node, given a program data path.
Service Module hosting the XMPP broker and its components.
Tokens available in request.
static readonly RequestOrigin Empty
Empty request origin.
string From
Address of caller.
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.