5using System.Threading.Tasks;
19 private readonly
string contentType;
20 private readonly
string extension;
21 private readonly
int nameStringId;
22 private readonly
string nameDefault;
23 private readonly
string commandId;
24 private readonly
string sortKey;
39 this.folderNode = FolderNode;
40 this.contentType = ContentType;
41 this.extension = Extension;
42 this.nameStringId = NameStringId;
43 this.nameDefault = NameDefault;
44 this.commandId = CommandId;
47 this.FileLocalName = Extension;
48 this.Content = Array.Empty<
string>();
49 this.Encoding =
System.Text.Encoding.UTF8.BodyName;
52 [Page(7,
"File System", 100)]
53 [Header(12,
"File Name:")]
54 [ToolTip(13,
"Local file name.")]
56 public string FileLocalName {
get;
set; }
61 [Page(7,
"File System", 100)]
62 [Header(30,
"Text Content:")]
63 [ToolTip(31,
"Text content in file.")]
71 [Page(7,
"File System", 100)]
72 [Header(32,
"Text Encoding:")]
73 [ToolTip(33,
"Encoding used to store text in file.")]
84 List<OptionAttribute> Encodings =
new List<OptionAttribute>();
86 foreach (EncodingInfo
Encoding in System.Text.Encoding.GetEncodings())
89 return Encodings.ToArray();
161 ??
throw new ArgumentException(
"Invalid encoding.", nameof(this.Encoding));
163 string FullPath = Path.Combine(this.folderNode.FolderName,
this.FileLocalName);
164 if (!FullPath.StartsWith(
this.folderNode.FolderName, StringComparison.CurrentCultureIgnoreCase))
165 throw new Exception(
"Invalid local file name.");
167 StringBuilder sb =
new StringBuilder();
170 foreach (
string Row
in this.
Content)
180 string Text = sb.ToString();
181 byte[] Bin =
Encoding.GetBytes(Text);
182 byte[] Bom =
Encoding.GetPreamble();
185 using FileStream fs = File.Create(FullPath);
188 await fs.WriteAsync(Bom, 0, Bom.Length);
190 await fs.WriteAsync(Bin, 0, Bin.Length);
191 await fs.FlushAsync();
207 return new CreateTextFileCommand(this.folderNode, this.contentType, this.extension, this.nameStringId, this.nameDefault,
208 this.commandId, this.sortKey);
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 ...
Creates a text file in a folder.
Task< string > GetFailureStringAsync(Language Language)
Gets a failure string, if any, of the command. If no specific failure string is available,...
Task< string > GetNameAsync(Language Language)
Gets the displayable name of the command.
string[] Content
Text content.
string SortCategory
Sort Category, if available.
CreateTextFileCommand(ProgramDataFolder FolderNode, string ContentType, string Extension, int NameStringId, string NameDefault, string CommandId, string SortKey)
Creates a text file in a folder.
CommandType Type
Type of command.
string Encoding
Text content.
OptionAttribute[] GetEncodingOptions()
Gets encoding options when editing Encoding.
Task< bool > CanExecuteAsync(RequestOrigin Caller)
If the command can be executed by the caller.
string SortKey
Sort Key, if available.
ICommand Copy()
Creates a copy of the command object.
Task< string > GetConfirmationStringAsync(Language Language)
Gets a confirmation string, if any, of the command. If no confirmation is necessary,...
string CommandID
ID of command.
async Task ExecuteCommandAsync()
Executes the command.
Task StartQueryExecutionAsync(Query Query, Language Language)
Starts the execution of a query.
Task< string > GetSuccessStringAsync(Language Language)
Gets a success string, if any, of the command. If no specific success string is available,...
ContentTypeAttribute GetContentType()
Gets the Content-Type of the Content property.
Edits the text of a text file.
Reference to a folder in the ProgramData folder of the broker.
Data source mirroring the ProgramData folder for the broker.
const string SourceID
Data Source ID for the ProgramData source.
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.
bool HasPrivilege(string Privilege)
If the origin has a given privilege.