-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathConcentratorDevice.cs
More file actions
84 lines (73 loc) · 2.33 KB
/
ConcentratorDevice.cs
File metadata and controls
84 lines (73 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System.Collections.Generic;
using System.Threading.Tasks;
using Waher.Networking.XMPP;
using Waher.Networking.XMPP.Concentrator;
using Waher.Runtime.Language;
using Waher.Things.Xmpp.Commands;
namespace Waher.Things.Xmpp
{
/// <summary>
/// Node representing an XMPP concentrator.
/// </summary>
public class ConcentratorDevice : ConnectedDevice
{
/// <summary>
/// Node representing an XMPP concentrator.
/// </summary>
public ConcentratorDevice()
: base()
{
}
/// <summary>
/// Gets the type name of the node.
/// </summary>
/// <param name="Language">Language to use.</param>
/// <returns>Localized type node.</returns>
public override Task<string> GetTypeNameAsync(Language Language)
{
return Language.GetStringAsync(typeof(ConcentratorDevice), 1, "XMPP Concentrator");
}
/// <summary>
/// If the node accepts a presumptive child, i.e. can receive as a child (if that child accepts the node as a parent).
/// </summary>
/// <param name="Child">Presumptive child node.</param>
/// <returns>If the child is acceptable.</returns>
public override Task<bool> AcceptsChildAsync(INode Child)
{
return Task.FromResult(
Child is ConcentratorSourceNode ||
Child is ConcentratorNode);
}
/// <summary>
/// Available command objects. If no commands are available, null is returned.
/// </summary>
public override Task<IEnumerable<ICommand>> Commands => this.GetCommands();
private async Task<IEnumerable<ICommand>> GetCommands()
{
List<ICommand> Result = new List<ICommand>();
Result.AddRange(await base.Commands);
XmppClient Client = await this.GetClient();
if (!(Client is null))
{
this.GetRemoteFullJid(Client, out bool HasContact, out bool HasSubscription);
if (HasContact && HasSubscription)
Result.Add(new ScanRootSources(this));
}
return Result.ToArray();
}
/// <summary>
/// Gets the concentrator client associated with the XMPP client associated
/// with the node.
/// </summary>
/// <returns>Concentrator Client, if found, null otherwise.</returns>
public async Task<ConcentratorClient> GetConcentratorClient()
{
XmppClient Client = await this.GetClient();
if (Client is null)
return null;
if (!Client.TryGetExtension(out ConcentratorClient ConcentratorClient))
return null;
return ConcentratorClient;
}
}
}