Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConnectedDeviceCommand.cs
1using System;
2using System.Threading.Tasks;
6
8{
12 public abstract class ConnectedDeviceCommand : ICommand
13 {
14 private readonly ConnectedDevice connectedDevice;
15 private readonly string sortKey;
16
23 {
24 this.connectedDevice = ConnectedDevice;
25 this.sortKey = SortKey;
26 }
27
31 public ConnectedDevice ConnectedDevice => this.connectedDevice;
32
36 public abstract string CommandID { get; }
37
41 public virtual CommandType Type => CommandType.Simple;
42
46 public string SortCategory => "XMPP";
47
51 public string SortKey => this.sortKey;
52
57 public abstract Task<string> GetNameAsync(Language Language);
58
63 public virtual Task<string> GetConfirmationStringAsync(Language Language)
64 {
65 return Task.FromResult(string.Empty);
66 }
67
72 public virtual Task<string> GetFailureStringAsync(Language Language)
73 {
74 return Task.FromResult(string.Empty);
75 }
76
81 public virtual Task<string> GetSuccessStringAsync(Language Language)
82 {
83 return Task.FromResult(string.Empty);
84 }
85
91 public virtual Task<bool> CanExecuteAsync(RequestOrigin Caller)
92 {
93 return Task.FromResult(true);
94 }
95
99 public virtual Task ExecuteCommandAsync() => Task.CompletedTask;
100
106 public virtual Task StartQueryExecutionAsync(Query Query, Language Language) => Task.CompletedTask;
107
112 public abstract ICommand Copy();
113
119 public async Task<XmppClient> GetXmppClient()
120 {
121 XmppClient Client = await this.connectedDevice.GetClient()
122 ?? throw new Exception("XMPP client not found.");
123
124 return Client;
125 }
126
133 public string GetRemoteFullJid(XmppClient Client)
134 {
135 string FullJid = this.connectedDevice.GetRemoteFullJid(Client, out bool HasContact, out bool HasSubscription);
136
137 if (!HasContact)
138 throw new Exception(this.connectedDevice.JID + " is not in the list of contacts.");
139
140 if (!HasSubscription)
141 throw new Exception("Not subscribed to the precense of " + this.connectedDevice.JID);
142
143 if (string.IsNullOrEmpty(FullJid))
144 throw new Exception(this.connectedDevice.JID + " is not online.");
145
146 return FullJid;
147 }
148 }
149}
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:59
Contains information about a language.
Definition: Language.cs:17
Class handling the reception of data from a query.
Definition: Query.cs:12
Tokens available in request.
Definition: RequestOrigin.cs:9
Abstract base class for commands on connected devices.
async Task< XmppClient > GetXmppClient()
Gets the concentrator client, if it exists.
string GetRemoteFullJid(XmppClient Client)
Gets the Full JID of the connected device.
abstract ICommand Copy()
Creates a copy of the command object.
ConnectedDevice ConnectedDevice
Reference to the connected device.
virtual Task< string > GetFailureStringAsync(Language Language)
Gets a failure string, if any, of the command. If no specific failure string is available,...
abstract Task< string > GetNameAsync(Language Language)
Gets the name of data source.
virtual Task< string > GetSuccessStringAsync(Language Language)
Gets a success string, if any, of the command. If no specific success string is available,...
virtual Task< string > GetConfirmationStringAsync(Language Language)
Gets a confirmation string, if any, of the command. If no confirmation is necessary,...
virtual Task ExecuteCommandAsync()
Executes the command.
virtual Task StartQueryExecutionAsync(Query Query, Language Language)
Starts the execution of a query.
ConnectedDeviceCommand(ConnectedDevice ConnectedDevice, string SortKey)
Abstract base class for commands on connected devices.
virtual Task< bool > CanExecuteAsync(RequestOrigin Caller)
If the command can be executed by the caller.
Node representing a device that is connected to XMPP.
Interface for commands.
Definition: ICommand.cs:32
CommandType
Command type.
Definition: ICommand.cs:11