2using System.Collections.Generic;
4using System.Threading.Tasks;
21 private readonly
string sourceName;
22 private readonly
bool containsWhiteSpace;
32 this.sourceName = SourceName;
34 this.containsWhiteSpace =
false;
36 foreach (
char ch
in SourceName)
38 if (
char.IsWhiteSpace(ch))
40 this.containsWhiteSpace =
true;
54 public string TypeName =>
throw InvalidOperation();
59 public string Name =>
string.Empty;
61 private static Exception InvalidOperation()
63 return new InvalidOperationException(
"Operation not permitted on MUC room sources.");
73 return Name == this.room.RoomId ||
Name == this.room.Jid;
83 return Task.FromResult(
false);
98 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node)
100 StringBuilder sql =
new StringBuilder();
102 sql.Append(
"SELECT");
104 if (Top <
int.MaxValue)
107 sql.Append(Top.ToString());
110 sql.Append(
" GENERIC * FROM ");
112 if (this.containsWhiteSpace)
115 sql.Append(this.sourceName.Replace(
"\"",
"\\\""));
119 sql.Append(this.sourceName.Replace(
"\"",
"\\\""));
121 if (!(Where is
null))
123 sql.Append(
" WHERE ");
127 if (!(Order is
null))
131 foreach (KeyValuePair<VariableReference, bool> P
in Order)
136 sql.Append(
" ORDER BY ");
141 sql.Append(P.Key.VariableName);
150 sql.Append(
" OFFSET ");
151 sql.Append(Offset.ToString());
154 ConsolidationState State =
new ConsolidationState()
156 ThreadId = Guid.NewGuid().ToString(),
157 N =
XmppServerModule.Instance.GetNrOccupants(this.room.Jid,
this.room.RoomId,
this.room.Domain,
true,
true)
164 Consolidator.Added += this.Consolidator_Updated;
165 Consolidator.Updated += this.Consolidator_Updated;
166 Consolidator.Disposed += this.Consolidator_Disposed;
170 Gateway.
XmppClient.SendMessage(Networking.XMPP.MessageType.GroupChat,
this.room.Jid,
string.Empty, sql.ToString(),
171 string.Empty,
string.Empty, State.ThreadId,
string.Empty);
173 return State.CompletionSource.Task;
176 private class ConsolidationState
178 public TaskCompletionSource<IResultSetEnumerator> CompletionSource =
new TaskCompletionSource<IResultSetEnumerator>();
179 public string ThreadId;
181 public bool Reported =
false;
184 private Task Consolidator_Disposed(
object Sender, EventArgs e)
192 return Task.CompletedTask;
195 private async Task Consolidator_Updated(
object Sender,
SourceEventArgs e)
205 private void Report(ScriptConsolidator
Consolidator, ConsolidationState State)
209 State.Reported =
true;
222 throw InvalidOperation();
230 throw InvalidOperation();
239 throw InvalidOperation();
255 throw InvalidOperation();
263 public Task
Insert(
bool Lazy,
object Object)
265 throw InvalidOperation();
273 public Task
Update(
bool Lazy, IEnumerable<object> Objects)
275 throw InvalidOperation();
Consolidates Markdown from multiple sources, sharing the same thread.
object Tag
External tag object that can be tagged to the object by its owner.
async Task< int > GetNrReportedSources()
Number of sources that have reported content.
Event arguments for source events.
Static class managing the runtime environment of the IoT Gateway.
static XmppClient XmppClient
XMPP Client connection of gateway.
Base class for all nodes in a parsed script tree.
string SubExpression
Sub-expression defining the node.
MUC Room, for script access to remote sources.
string TypeName
Name of corresponding type.
string CollectionName
Name of corresponding collection.
RoomSource(MucRoom Room, string SourceName)
MUC Room Data source.
Task Update(bool Lazy, IEnumerable< object > Objects)
Updates a set of objects.
Task CreateIndex(string Name, string[] Fields)
Creates an index in the source.
string Name
Collection name or alias.
Task< IResultSetEnumerator > Find(int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds objects matching filter conditions in Where .
Task< bool > DropIndex(string Name)
Drops an index from the source.
bool IsSource(string Name)
Checks if the name refers to the source.
Task< int?> FindDelete(bool Lazy, int Offset, int Top, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Finds and Deletes a set of objects.
Task Insert(bool Lazy, object Object)
Inserts an object.
Task DropCollection()
Drops the collection from the source.
Task< bool > IsLabel(string Label)
Checks if the label is a label in the source.
Consolidates responses from occupants in a MUC room.
Service Module hosting the XMPP broker and its components.
Basic interface for vectors.
ICollection< IElement > VectorElements
An enumeration of vector elements.
Interface for data sources that can be used in SQL statements.