4using System.Threading.Tasks;
22 private readonly
string sourceName;
23 private readonly
bool containsWhiteSpace;
33 this.sourceName = SourceName;
35 this.containsWhiteSpace =
false;
37 foreach (
char ch
in SourceName)
39 if (
char.IsWhiteSpace(ch))
41 this.containsWhiteSpace =
true;
55 public string TypeName =>
throw InvalidOperation();
60 public string Name =>
string.Empty;
62 private static Exception InvalidOperation()
64 return new InvalidOperationException(
"Operation not permitted on MUC room sources.");
74 return Name == this.room.RoomId ||
Name == this.room.Jid;
84 return Task.FromResult(
false);
99 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node)
101 StringBuilder sql =
new StringBuilder();
103 sql.Append(
"SELECT");
105 if (Top <
int.MaxValue)
108 sql.Append(Top.ToString());
111 sql.Append(
" GENERIC * FROM ");
113 if (this.containsWhiteSpace)
116 sql.Append(this.sourceName.Replace(
"\"",
"\\\""));
120 sql.Append(this.sourceName.Replace(
"\"",
"\\\""));
122 if (!(Where is
null))
124 sql.Append(
" WHERE ");
128 if (!(Order is
null))
132 foreach (KeyValuePair<VariableReference, bool> P
in Order)
137 sql.Append(
" ORDER BY ");
142 sql.Append(P.Key.VariableName);
151 sql.Append(
" OFFSET ");
152 sql.Append(Offset.ToString());
155 ConsolidationState State =
new ConsolidationState()
157 ThreadId = Guid.NewGuid().ToString(),
158 N =
XmppServerModule.Instance.GetNrOccupants(this.room.Jid,
this.room.RoomId,
this.room.Domain,
true,
true)
165 Consolidator.Added += this.Consolidator_Updated;
166 Consolidator.Updated += this.Consolidator_Updated;
167 Consolidator.Disposed += this.Consolidator_Disposed;
171 Gateway.
XmppClient.SendMessage(Networking.XMPP.MessageType.GroupChat,
this.room.Jid,
string.Empty, sql.ToString(),
172 string.Empty,
string.Empty, State.ThreadId,
string.Empty);
174 return State.CompletionSource.Task;
177 private class ConsolidationState
179 public TaskCompletionSource<IResultSetEnumerator> CompletionSource =
new TaskCompletionSource<IResultSetEnumerator>();
180 public string ThreadId;
182 public bool Reported =
false;
185 private Task Consolidator_Disposed(
object Sender, EventArgs e)
193 return Task.CompletedTask;
196 private async Task Consolidator_Updated(
object Sender,
SourceEventArgs e)
206 private void Report(ScriptConsolidator
Consolidator, ConsolidationState State)
210 State.Reported =
true;
223 throw InvalidOperation();
231 throw InvalidOperation();
240 throw InvalidOperation();
256 throw InvalidOperation();
264 public Task
Insert(
bool Lazy,
object Object)
266 throw InvalidOperation();
274 public Task
Update(
bool Lazy, IEnumerable<object> Objects)
276 throw InvalidOperation();
308 if (!Processor.
Process(e.Current))
328 KeyValuePair<VariableReference, bool>[] Order,
ScriptNode Node)
330 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.
Task< int?> Delete(bool Lazy, int Offset, int Top, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Deletes a set of objects.
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.
async Task< bool > Process(IProcessor< object > Processor, int Offset, int Top, bool Generic, ScriptNode Where, Variables Variables, KeyValuePair< VariableReference, bool >[] Order, ScriptNode Node)
Processes objects matching filter conditions in Where .
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.
Task< bool > MoveNextAsync()
Advances the enumerator to the next element of the collection.
Interface for processors of objects.
bool Process(T Object)
Processes an object synchronously.
bool IsAsynchronous
If the processor operates asynchronously.
Task< bool > ProcessAsync(T Object)
Processes an object asynchronously.
Basic interface for vectors.
ICollection< IElement > VectorElements
An enumeration of vector elements.
Interface for result-set enumerators.
Interface for data sources that can be used in SQL statements.