2using System.Collections.Generic;
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 =
new string[0];
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();
158 ??
throw new ArgumentException(
"Invalid encoding.", nameof(this.Encoding));
160 string FullPath = Path.Combine(this.folderNode.FolderName,
this.FileLocalName);
161 if (!FullPath.StartsWith(
this.folderNode.FolderName, StringComparison.CurrentCultureIgnoreCase))
162 throw new Exception(
"Invalid local file name.");
164 StringBuilder sb =
new StringBuilder();
167 foreach (
string Row
in this.
Content)
177 string Text = sb.ToString();
178 byte[] Bin =
Encoding.GetBytes(Text);
179 byte[] Bom =
Encoding.GetPreamble();
182 using (FileStream fs = File.Create(FullPath))
185 await fs.WriteAsync(Bom, 0, Bom.Length);
187 await fs.WriteAsync(Bin, 0, Bin.Length);
188 await fs.FlushAsync();
205 return new CreateTextFileCommand(this.folderNode, this.contentType, this.extension, this.nameStringId, this.nameDefault,
206 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 name of data source.
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.
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.