Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmppProtocol.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
6using Waher.Things;
9
11{
12 public class XmppProtocol : INode
13 {
14 private readonly XmppServer server;
15
16 public XmppProtocol(XmppServer Server)
17 {
18 this.server = Server;
19 }
20
21 public string LocalId => this.NodeId;
22 public string LogId => this.NodeId;
23 public string NodeId => "XMPP";
24 public string SourceId => "Protocols";
25 public string Partition => string.Empty;
26 public bool HasChildren => false;
27 public bool ChildrenOrdered => false;
28 public bool IsReadable => false;
29 public bool IsControllable => false;
30 public INode Parent => null;
31 public DateTime LastChanged => DateTime.MinValue;
32 public Task<IEnumerable<INode>> ChildNodes => null;
33
35 {
36 get
37 {
38 return NodeState.None; // TODO: Check XMPP Server state.
39 }
40 }
41
42 public Task<bool> AcceptsChildAsync(INode Child)
43 {
44 return Task.FromResult(false);
45 }
46
47 public Task<bool> AcceptsParentAsync(INode Parent)
48 {
49 return Task.FromResult(false);
50 }
51
52 public Task AddAsync(INode Child)
53 {
54 throw new NotSupportedException();
55 }
56
57 public Task<bool> CanAddAsync(RequestOrigin Caller)
58 {
59 return Task.FromResult(false);
60 }
61
62 public Task<bool> CanDestroyAsync(RequestOrigin Caller)
63 {
64 return Task.FromResult(false);
65 }
66
67 public Task<bool> CanEditAsync(RequestOrigin Caller)
68 {
69 return Task.FromResult(false);
70 }
71
72 public Task<bool> CanViewAsync(RequestOrigin Caller)
73 {
74 return XmppServerModule.IsAdmin(Caller.From);
75 }
76
77 public Task DestroyAsync()
78 {
79 throw new NotSupportedException();
80 }
81
82 public async Task<IEnumerable<Parameter>> GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
83 {
84 LinkedList<Parameter> Parameters = new LinkedList<Parameter>();
85
86 Parameters.AddLast(new StringParameter("XmppPorts", await Language.GetStringAsync(typeof(XmppServerModule), 6, "C2S Ports"), HttpProtocol.PortsToString(this.server.OpenC2SPorts)));
87 Parameters.AddLast(new StringParameter("XmppsPorts", await Language.GetStringAsync(typeof(XmppServerModule), 7, "S2S Ports"), HttpProtocol.PortsToString(this.server.OpenS2SPorts)));
88
89 return Parameters;
90 }
91
92 public Task<IEnumerable<Message>> GetMessagesAsync(RequestOrigin Caller)
93 {
94 return Task.FromResult<IEnumerable<Message>>(null);
95 }
96
97 public Task<string> GetTypeNameAsync(Language Language)
98 {
99 return Language.GetStringAsync(typeof(XmppServerModule), 40, "XMPP Protocol");
100 }
101
102 public Task<bool> MoveDownAsync(RequestOrigin Caller)
103 {
104 return Task.FromResult(false);
105 }
106
107 public Task<bool> MoveUpAsync(RequestOrigin Caller)
108 {
109 return Task.FromResult(false);
110 }
111
112 public Task UpdateAsync()
113 {
114 return Task.CompletedTask;
115 }
116
117 public Task<bool> RemoveAsync(INode Child)
118 {
119 return Task.FromResult(false);
120 }
121
122 public bool HasCommands => true;
123
124 public Task<IEnumerable<ICommand>> Commands
125 {
126 get
127 {
128 return Task.FromResult<IEnumerable<ICommand>>(new ICommand[]
129 {
130 new XmppStatistics()
131 });
132 }
133 }
134 }
135}
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
bool HasCommands
If the node has registered commands or not.
NodeState State
Current overall state of the node.
Definition: XmppProtocol.cs:35
string LogId
If provided, an ID for the node, as it would appear or be used in system logs. Can be null,...
Definition: XmppProtocol.cs:22
Task AddAsync(INode Child)
Adds a new child to the node.
Definition: XmppProtocol.cs:52
Task< IEnumerable< Message > > GetMessagesAsync(RequestOrigin Caller)
Gets messages logged on the node.
Definition: XmppProtocol.cs:92
Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a presumptive parent, i.e. can be added to that parent (if that parent accepts th...
Definition: XmppProtocol.cs:47
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
Definition: XmppProtocol.cs:32
bool ChildrenOrdered
If the children of the node have an intrinsic order (true), or if the order is not important (false).
Definition: XmppProtocol.cs:27
string SourceId
Optional ID of source containing node.
Definition: XmppProtocol.cs:24
string Partition
Optional partition in which the Node ID is unique.
Definition: XmppProtocol.cs:25
Task< bool > MoveDownAsync(RequestOrigin Caller)
Tries to move the node down.
Task UpdateAsync()
Updates the node (in persisted storage).
Task< bool > CanDestroyAsync(RequestOrigin Caller)
If the node can be destroyed to by the caller.
Definition: XmppProtocol.cs:62
string LocalId
If provided, an ID for the node, but unique locally between siblings. Can be null,...
Definition: XmppProtocol.cs:21
Task DestroyAsync()
Destroys the node. If it is a child to a parent node, it is removed from the parent first.
Definition: XmppProtocol.cs:77
async Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
Definition: XmppProtocol.cs:82
Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
Definition: XmppProtocol.cs:97
Task< bool > RemoveAsync(INode Child)
Removes a child from the node.
bool HasChildren
If the source has any child sources.
Definition: XmppProtocol.cs:26
bool IsControllable
If the node can be controlled.
Definition: XmppProtocol.cs:29
Task< bool > CanAddAsync(RequestOrigin Caller)
If the node can be added to by the caller.
Definition: XmppProtocol.cs:57
Task< bool > AcceptsChildAsync(INode Child)
If the node accepts a presumptive child, i.e. can receive as a child (if that child accepts the node ...
Definition: XmppProtocol.cs:42
INode Parent
Parent Node, or null if a root node.
Definition: XmppProtocol.cs:30
Task< bool > CanViewAsync(RequestOrigin Caller)
If the node is visible to the caller.
Definition: XmppProtocol.cs:72
Task< IEnumerable< ICommand > > Commands
Available command objects. If no commands are available, null is returned.
DateTime LastChanged
When the node was last updated.
Definition: XmppProtocol.cs:31
Task< bool > CanEditAsync(RequestOrigin Caller)
If the node can be edited by the caller.
Definition: XmppProtocol.cs:67
Task< bool > MoveUpAsync(RequestOrigin Caller)
Tries to move the node up.
Service Module hosting the XMPP broker and its components.
Tokens available in request.
Definition: RequestOrigin.cs:9
string From
Address of caller.
Interface for commands.
Definition: ICommand.cs:32
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
NodeState
State of a node.
Definition: INode.cs:13