Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ClearQueueCommand.cs
1using System;
2using System.Threading.Tasks;
5using Waher.Things;
7
9{
14 {
15 private readonly string queueName;
16
21 public ClearQueueCommand(string QueueName)
22 {
23 this.queueName = QueueName;
24 }
25
29 public string CommandID => "Clear";
30
34 public CommandType Type => CommandType.Simple;
35
39 public string SortCategory => "Queue";
40
44 public string SortKey => "Clear";
45
50 public Task<string> GetNameAsync(Language Language) =>
51 Language.GetStringAsync(typeof(GatewayConfigSource), 254, "Clear Queue");
52
59 "Are you sure you want to clear all messages in the queue?");
60
65 public Task<string> GetFailureStringAsync(Language Language) =>
67 "Unable to clear messages in queue.");
68
73 public Task<string> GetSuccessStringAsync(Language Language) =>
75 "Queue successfully cleared.");
76
82 public Task<bool> CanExecuteAsync(RequestOrigin Caller)
83 {
84 return Task.FromResult(Caller.HasPrivilege("Admin.Queues." + this.queueName + ".Clear"));
85 }
86
90 public async Task ExecuteCommandAsync()
91 {
92 IPersistedQueue Queue = await Database.GetQueue(this.queueName);
93 await Queue.Clear();
94 }
95
102 throw new InvalidOperationException();
103
108 public ICommand Copy() => new ClearQueueCommand(this.queueName);
109 }
110}
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static Task< IPersistedQueue > GetQueue(string QueueName)
Gets a persistent dictionary containing objects in a collection.
Definition: Database.cs:2326
Contains information about a language.
Definition: Language.cs:17
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 ...
Definition: Language.cs:209
Task< string > GetNameAsync(Language Language)
Gets the displayable name of the command.
Task< string > GetConfirmationStringAsync(Language Language)
Gets a confirmation string, if any, of the command. If no confirmation is necessary,...
Task< bool > CanExecuteAsync(RequestOrigin Caller)
If the command can be executed by the caller.
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,...
Task< string > GetFailureStringAsync(Language Language)
Gets a failure string, if any, of the command. If no specific failure string is available,...
Class handling the reception of data from a query.
Definition: Query.cs:12
Tokens available in request.
Definition: RequestOrigin.cs:9
bool HasPrivilege(string Privilege)
If the origin has a given privilege.
Inteface for persisted queues.
Task Clear()
Clears the queue.
Interface for commands.
Definition: ICommand.cs:32
CommandType
Command type.
Definition: ICommand.cs:11