2using System.Collections.Generic;
5using System.Threading.Tasks;
20 private readonly
string contentType;
28 this.fileNode = FileNode;
31 byte[] Bin = File.ReadAllBytes(FileNode.
FileName);
34 string s =
Encoding.GetString(Bin, BomLength, Bin.Length - BomLength);
35 string[] Rows = s.Replace(
"\r\n",
"\n").Replace(
'\r',
'\n').Split(
'\n');
44 [Page(7,
"File System", 100)]
45 [Header(30,
"Text Content:")]
46 [ToolTip(31,
"Text content in file.")]
54 [Page(7,
"File System", 100)]
55 [Header(32,
"Text Encoding:")]
56 [ToolTip(33,
"Encoding used to store text in file.")]
67 List<OptionAttribute> Encodings =
new List<OptionAttribute>();
69 foreach (EncodingInfo
Encoding in System.Text.Encoding.GetEncodings())
72 return Encodings.ToArray();
141 ??
throw new ArgumentException(
"Invalid encoding.", nameof(this.Encoding));
143 StringBuilder sb =
new StringBuilder();
146 foreach (
string Row
in this.
Content)
156 string Text = sb.ToString();
157 byte[] Bin =
Encoding.GetBytes(Text);
158 byte[] Bom =
Encoding.GetPreamble();
161 using (FileStream fs = File.OpenWrite(this.fileNode.FileName))
164 await fs.WriteAsync(Bom, 0, Bom.Length);
166 await fs.WriteAsync(Bin, 0, Bin.Length);
167 await fs.FlushAsync();
169 fs.SetLength(fs.Position);
173 internal static bool HasBom(
byte[] Bin,
byte[] Bom)
175 int i, c = Bom.Length;
185 for (i = 0; i < c; i++)
187 if (Bom[i] != Bin[i])
Helps with parsing of commong data types.
static Encoding GetEncoding(byte[] Data, Encoding DefaultEncoding, out int BomLength)
Gets the encoding of a string from a its binary representation, taking any Byte Order Mark (BOM) into...
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 ...
Edits the text of a text file.
string[] Content
Text content.
Task< string > GetSuccessStringAsync(Language Language)
Gets a success string, if any, of the command. If no specific success string is available,...
Task< string > GetConfirmationStringAsync(Language Language)
Gets a confirmation string, if any, of the command. If no confirmation is necessary,...
string CommandID
ID of command.
string Encoding
Text content.
Task< string > GetFailureStringAsync(Language Language)
Gets a failure string, if any, of the command. If no specific failure string is available,...
Task StartQueryExecutionAsync(Query Query, Language Language)
Starts the execution of a query.
Task< bool > CanExecuteAsync(RequestOrigin Caller)
If the command can be executed by the caller.
ICommand Copy()
Creates a copy of the command object.
OptionAttribute[] GetEncodingOptions()
Gets encoding options when editing Encoding.
async Task ExecuteCommandAsync()
Executes the command.
Task< string > GetNameAsync(Language Language)
Gets the name of data source.
ContentTypeAttribute GetContentType()
Gets the Content-Type of the Content property.
string SortKey
Sort Key, if available.
EditTextCommand(ProgramDataFile FileNode)
Edits the text of a text file.
CommandType Type
Type of command.
string SortCategory
Sort Category, if available.
Reference to a file in the ProgramData folder of the broker.
string ContentType
If the referenced file is a text file.
string FileName
File name.
Data source mirroring the ProgramData folder for the broker.
Service Module hosting the XMPP broker and its components.
Defines the Content-Type of a multi-row property. Acts as a hint to clients, on how the text can be e...
Defines an option to display when editing the parameter.
Class handling the reception of data from a query.
Tokens available in request.