1using System.Collections.Generic;
3using 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)
219 internal void FileUpdated()
234 LinkedList<Parameter> Parameters =
new LinkedList<Parameter>();
236 if (!this.size.HasValue)
240 using (FileStream fs = File.OpenRead(this.fileName))
242 this.size = fs.Length;
251 if (this.created is
null)
255 this.created = File.GetCreationTimeUtc(this.fileName);
263 if (this.updated is
null)
267 this.updated = File.GetLastWriteTimeUtc(this.fileName);
275 if (this.size.HasValue)
281 if (this.created.HasValue)
284 this.created.Value));
286 if (this.updated.HasValue &&
this.updated.Value >
this.created.Value)
289 this.updated.Value));
302 return Task.FromResult<IEnumerable<Message>>(
null);
327 return Task.FromResult(
true);
330 return Task.FromResult(
false);
332 if (this.parent is
null &&
string.IsNullOrEmpty(this.fileName))
333 this.parent = ParentFolder;
335 return Task.FromResult(
true);
345 return Task.FromResult(
false);
354 throw new NotSupportedException();
374 if (this.parent is
null)
375 throw new UnauthorizedAccessException(
"File is protected against deletion.");
377 if (File.Exists(
this.fileName))
378 File.Delete(this.fileName);
380 return Task.CompletedTask;
390 return this.IsTextFile
392 : Task.FromResult<IEnumerable<ICommand>>(
null);
403 if (this.fileName.EndsWith(
".config", StringComparison.CurrentCultureIgnoreCase))
406 string FileExtension = Path.GetExtension(this.fileName);
411 if (
ContentType.StartsWith(
"text/", StringComparison.OrdinalIgnoreCase))
418 case "application/json":
419 case "application/x-tex":
420 case "application/x-webscript":
421 case "application/x-turtle":
422 case "application/link-format":
423 case "application/sparql-query":
427 if (
ContentType.StartsWith(
"application/", StringComparison.OrdinalIgnoreCase) &&
428 (
ContentType.EndsWith(
"+xml", StringComparison.OrdinalIgnoreCase) ||
429 ContentType.EndsWith(
"+json", StringComparison.OrdinalIgnoreCase)))
445 if (this.fileName.EndsWith(
".config", StringComparison.CurrentCultureIgnoreCase))
448 string FileExtension = Path.GetExtension(
this.fileName);
463 List<ControlParameter> Parameters =
new List<ControlParameter>();
464 FileAttributes Attributes = File.GetAttributes(this.FileName);
472 GetReadOnly, SetReadOnly));
477 GetHidden, SetHidden));
482 GetSystem, SetSystem));
487 GetArchive, SetArchive));
489 return Parameters.ToArray();
494 return GetAttribute(Node, FileAttributes.ReadOnly);
499 return SetAttribute(Node, Value, FileAttributes.ReadOnly);
504 return GetAttribute(Node, FileAttributes.Hidden);
509 return SetAttribute(Node, Value, FileAttributes.Hidden);
514 return GetAttribute(Node, FileAttributes.System);
519 return SetAttribute(Node, Value, FileAttributes.System);
524 return GetAttribute(Node, FileAttributes.Archive);
529 return SetAttribute(Node, Value, FileAttributes.Archive);
532 private static Task<bool?> GetAttribute(
IThingReference Node, FileAttributes Attribute)
535 return Task.FromResult<
bool?>(
null);
537 FileAttributes Attr = File.GetAttributes(FileNode.FileName);
539 return Task.FromResult<
bool?>(Attr.HasFlag(Attribute));
542 private static Task SetAttribute(
IThingReference Node,
bool Value, FileAttributes Attribute)
545 throw new ArgumentException(
"Unexpected node type.", nameof(Node));
547 FileAttributes Attr = File.GetAttributes(FileNode.FileName);
548 FileAttributes Bak = Attr;
556 File.SetAttributes(FileNode.FileName, Attr);
558 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 > 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,...
async Task< bool > CanDestroyAsync(RequestOrigin Caller)
If the node can be destroyed to by the caller.
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 ProgramDataSourceID
Data Source ID for the ProgramData source.
Service Module hosting the XMPP broker and its components.
Boolean control parameter.
DateTime-valued parameter.
Tokens available in request.
string From
Address of caller.
Interface for actuator nodes.
Interface for nodes that are published through the concentrator interface.
Interface for thing references.
NodeState
State of a node.