4using System.Threading.Tasks;
23 private string fileName;
24 private string fileLocalName;
25 private DateTime? created;
26 private DateTime? updated;
33 : this(string.Empty, null, null, null, null)
46 this.created = Created;
47 this.updated = Updated;
50 if (
string.IsNullOrEmpty(this.fileName))
51 this.fileLocalName =
null;
53 this.fileLocalName = Path.GetFileName(this.fileName);
56 [Page(7,
"File System", 100)]
57 [Header(12,
"File Name:")]
58 [ToolTip(13,
"Local file name.")]
60 public string FileLocalName
62 get => this.fileLocalName;
65 if (this.fileLocalName != value)
67 if (this.parent is
null)
68 throw new Exception(
"You are not allowed to change the file name.");
70 string FullPath = Path.Combine(this.parent.
FolderName, value);
71 if (!FullPath.StartsWith(
this.parent.FolderName, StringComparison.CurrentCultureIgnoreCase))
72 throw new Exception(
"Invalid local file name.");
74 if (!
string.IsNullOrEmpty(this.fileName))
76 if (File.Exists(FullPath) || Directory.Exists(FullPath))
77 throw new Exception(
"File or folder already exists.");
79 File.Move(this.fileName, FullPath);
82 this.fileLocalName = value;
83 this.fileName = FullPath;
91 [Page(7,
"File System", 100)]
92 [Header(10,
"Full Path:")]
93 [ToolTip(15,
"Full path to file.")]
115 public string LocalId => Path.GetFileName(this.fileName);
120 public string LogId => this.fileName;
164 public DateTime
LastChanged => File.GetLastWriteTimeUtc(this.fileName);
174 public Task<IEnumerable<INode>>
ChildNodes => Task.FromResult<IEnumerable<INode>>(
null);
213 if (this.parent is
null)
214 return Task.FromResult(
false);
219 internal void FileUpdated()
234 LinkedList<Parameter> Parameters =
new LinkedList<Parameter>();
236 if (!this.size.HasValue)
240 FileInfo FileInfo =
new FileInfo(this.fileName);
241 this.size = FileInfo.Length;
249 if (this.created is
null)
253 this.created = File.GetCreationTimeUtc(this.fileName);
261 if (this.updated is
null)
265 this.updated = File.GetLastWriteTimeUtc(this.fileName);
273 if (this.size.HasValue)
279 if (this.created.HasValue)
282 this.created.Value));
284 if (this.updated.HasValue &&
this.updated.Value >
this.created.Value)
287 this.updated.Value));
300 return Task.FromResult<IEnumerable<Message>>(
null);
325 return Task.FromResult(
true);
328 return Task.FromResult(
false);
330 if (this.parent is
null &&
string.IsNullOrEmpty(this.fileName))
331 this.parent = ParentFolder;
333 return Task.FromResult(
true);
343 return Task.FromResult(
false);
352 throw new NotSupportedException();
372 if (this.parent is
null)
373 throw new UnauthorizedAccessException(
"File is protected against deletion.");
375 if (File.Exists(
this.fileName))
376 File.Delete(this.fileName);
378 return Task.CompletedTask;
388 return this.IsTextFile
390 : Task.FromResult<IEnumerable<ICommand>>(
null);
401 if (this.fileName.EndsWith(
".config", StringComparison.CurrentCultureIgnoreCase))
404 string FileExtension = Path.GetExtension(this.fileName);
409 if (
ContentType.StartsWith(
"text/", StringComparison.OrdinalIgnoreCase))
416 case "application/json":
417 case "application/x-tex":
418 case "application/x-webscript":
419 case "application/x-turtle":
420 case "application/link-format":
421 case "application/sparql-query":
425 if (
ContentType.StartsWith(
"application/", StringComparison.OrdinalIgnoreCase) &&
426 (
ContentType.EndsWith(
"+xml", StringComparison.OrdinalIgnoreCase) ||
427 ContentType.EndsWith(
"+json", StringComparison.OrdinalIgnoreCase)))
443 if (this.fileName.EndsWith(
".config", StringComparison.CurrentCultureIgnoreCase))
446 string FileExtension = Path.GetExtension(
this.fileName);
461 List<ControlParameter> Parameters =
new List<ControlParameter>();
462 FileAttributes Attributes = File.GetAttributes(this.FileName);
470 GetReadOnly, SetReadOnly));
475 GetHidden, SetHidden));
480 GetSystem, SetSystem));
485 GetArchive, SetArchive));
487 return Parameters.ToArray();
492 return GetAttribute(Node, FileAttributes.ReadOnly);
497 return SetAttribute(Node, Value, FileAttributes.ReadOnly);
502 return GetAttribute(Node, FileAttributes.Hidden);
507 return SetAttribute(Node, Value, FileAttributes.Hidden);
512 return GetAttribute(Node, FileAttributes.System);
517 return SetAttribute(Node, Value, FileAttributes.System);
522 return GetAttribute(Node, FileAttributes.Archive);
527 return SetAttribute(Node, Value, FileAttributes.Archive);
530 private static Task<bool?> GetAttribute(
IThingReference Node, FileAttributes Attribute)
533 return Task.FromResult<
bool?>(
null);
535 FileAttributes Attr = File.GetAttributes(FileNode.FileName);
537 return Task.FromResult<
bool?>(Attr.HasFlag(Attribute));
540 private static Task SetAttribute(
IThingReference Node,
bool Value, FileAttributes Attribute)
543 throw new ArgumentException(
"Unexpected node type.", nameof(Node));
545 FileAttributes Attr = File.GetAttributes(FileNode.FileName);
546 FileAttributes Bak = Attr;
554 File.SetAttributes(FileNode.FileName, Attr);
556 return Task.CompletedTask;
JavaScript encoder/decoder.
const string DefaultContentType
application/javascript
Static class managing encoding and decoding of internet content.
static bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Plain text encoder/decoder.
const string DefaultContentType
text/plain
const string DefaultContentType
Default content type for XML documents.
const string SchemaContentType
Default content type for XML schema documents.
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 ...
async Task< Namespace > GetNamespaceAsync(string Name)
Gets the namespace object, given its name, if available.
Contains information about a namespace in a language.
Task< LanguageString > GetStringAsync(int Id)
Gets the string object, given its ID, if available.
Basic access point for runtime language localization.
static async Task< Language > GetDefaultLanguageAsync()
Gets the default language.
Edits the text of a text file.
Reference to a file in the ProgramData folder of the broker.
Task AddAsync(INode Child)
Adds a new child to the node.
bool HasChildren
If the source has any child sources.
string ContentType
If the referenced file is a text file.
Task UpdateAsync()
Updates the node (in persisted storage).
string Partition
Optional partition in which the Node ID is unique.
Task< bool > CanDestroyAsync(RequestOrigin Caller)
If the node can be destroyed to by the caller.
Task< bool > MoveUpAsync(RequestOrigin Caller)
Tries to move the node up.
Task< bool > MoveDownAsync(RequestOrigin Caller)
Tries to move the node down.
Task< bool > AcceptsChildAsync(INode Child)
If the node accepts a presumptive child, i.e. can receive as a child (if that child accepts the node ...
INode Parent
Parent Node, or null if a root node.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
string LocalId
If provided, an ID for the node, but unique locally between siblings. Can be null,...
async Task< ControlParameter[]> GetControlParameters()
Get control parameters for the actuator.
async Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
Task< bool > CanAddAsync(RequestOrigin Caller)
If the node can be added to by the caller.
Task< bool > CanViewAsync(RequestOrigin Caller)
If the node is visible to the caller.
ProgramDataFile()
Reference to a file in the ProgramData folder of the broker.
NodeState State
Current overall state of the node.
ProgramDataFile(string FileName, ProgramDataFolder Parent, DateTime? Created, DateTime? Updated, long? Size)
Reference to a file in the ProgramData folder of the broker.
Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
Task DestroyAsync()
Destroys the node. If it is a child to a parent node, it is removed from the parent first.
Task< bool > CanEditAsync(RequestOrigin Caller)
If the node can be edited by the caller.
DateTime LastChanged
When the node was last updated.
string LogId
If provided, an ID for the node, as it would appear or be used in system logs. Can be null,...
bool IsReadable
If the node can be read.
bool IsTextFile
If the referenced file is a text file.
bool ChildrenOrdered
If the children of the node have an intrinsic order (true), or if the order is not important (false).
string SourceId
Optional ID of source containing node.
Task< IEnumerable< Message > > GetMessagesAsync(RequestOrigin Caller)
Gets messages logged on the node.
Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a presumptive parent, i.e. can be added to that parent (if that parent accepts th...
Task< bool > RemoveAsync(INode Child)
Removes a child from the node.
string FileName
File name.
Task< IEnumerable< ICommand > > Commands
Available command objects. If no commands are available, null is returned.
bool HasCommands
If the node has registered commands or not.
bool IsControllable
If the node can be controlled.
Reference to a folder in the ProgramData folder of the broker.
string FolderName
Full Folder name.
Data source mirroring the ProgramData folder for the broker.
const string SourceID
Data Source ID for the ProgramData source.
Boolean control parameter.
DateTime-valued parameter.
Tokens available in request.
bool HasPrivilege(string Privilege)
If the origin has a given privilege.
Interface for actuator nodes.
Interface for nodes that are published through the concentrator interface.
Interface for thing references.
NodeState
State of a node.