public override SensorDataClientRequest StartSensorDataFullReadout() { XmppAccountNode XmppAccountNode = this.XmppAccountNode; SensorClient SensorClient; if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null) { return(SensorClient.RequestReadout(this.RosterItem.LastPresenceFullJid, FieldType.All)); } else { throw new NotSupportedException(); } }
public override SensorDataClientRequest StartSensorDataMomentaryReadout() { XmppAccountNode XmppAccountNode = this.XmppAccountNode; SensorClient SensorClient; if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null) { return(SensorClient.RequestReadout(this.RosterItem.LastPresenceFullJid, FieldType.Momentary)); } else { return(null); } }
public override SensorDataClientRequest StartSensorDataFullReadout() { XmppConcentrator Concentrator = this.Concentrator; XmppAccountNode XmppAccountNode = Concentrator.XmppAccountNode; SensorClient SensorClient; if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null) { return(SensorClient.RequestReadout(Concentrator.RosterItem.LastPresenceFullJid, new ThingReference[] { new ThingReference(this.nodeInfo.NodeId, this.nodeInfo.SourceId, this.nodeInfo.Partition) }, FieldType.All)); } else { throw new NotSupportedException(); } }
public override SensorDataClientRequest StartSensorDataMomentaryReadout() { XmppConcentrator Concentrator = this.Concentrator; XmppAccountNode XmppAccountNode = Concentrator.XmppAccountNode; SensorClient SensorClient; if (XmppAccountNode != null && (SensorClient = XmppAccountNode.SensorClient) != null) { return(SensorClient.RequestReadout(Concentrator.RosterItem.LastPresenceFullJid, new ThingReference[] { new ThingReference(this.nodeInfo.NodeId, this.nodeInfo.SourceId, this.nodeInfo.ParentId) }, FieldType.Momentary)); } else { return(null); } }
/// <summary> /// Executes a node. /// </summary> /// <param name="Variables">Set of variables for the activity.</param> /// <returns>Next node of execution, if different from the default, otherwise null (for default).</returns> public override async Task <LinkedListNode <IActivityNode> > Execute(Variables Variables) { string To = this.to.GetValue(Variables); if (!(this.GetActorObject(this.actor, Variables) is SensorClient SensorClient)) { throw new Exception("Actor not an XMPP Sensor Client."); } if (XmppClient.BareJidRegEx.IsMatch(To)) { RosterItem Item = SensorClient.Client[To]; if (Item is null) { throw new Exception("No connection in roster with Bare JID: " + To); } if (!Item.HasLastPresence || !Item.LastPresence.IsOnline) { throw new Exception("Contact not online: " + To); } To = Item.LastPresenceFullJid; } TaskCompletionSource <bool> T = new TaskCompletionSource <bool>(); Dictionary <string, Field> FieldsAsObject = this.responseType == SensorDataResponseType.Object ? new Dictionary <string, Field>() : null; List <Field> FieldsAsArray = this.responseType == SensorDataResponseType.Array ? new List <Field>() : null; List <ThingError> Errors = new List <ThingError>(); SensorDataClientRequest Request = SensorClient.RequestReadout(To, this.nodeReferences, this.fields, this.fieldTypes); Request.OnErrorsReceived += (Sender, NewErrors) => { lock (Errors) { Errors.AddRange(NewErrors); } return(Task.CompletedTask); }; Request.OnFieldsReceived += (Sender, NewFields) => { if (this.responseType == SensorDataResponseType.Object) { lock (FieldsAsObject) { foreach (Field F in NewFields) { FieldsAsObject[F.Name] = F; } } } else { lock (FieldsAsArray) { FieldsAsArray.AddRange(NewFields); } } return(Task.CompletedTask); }; Request.OnStateChanged += (Sender, NewState) => { switch (NewState) { case SensorDataReadoutState.Done: T.TrySetResult(true); break; case SensorDataReadoutState.Failure: case SensorDataReadoutState.Cancelled: T.TrySetResult(false); break; } return(Task.CompletedTask); }; if (!await T.Task) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Sensor Data readout failed. Errors reported: "); sb.AppendLine(); foreach (ThingError Error in Errors) { sb.AppendLine(Error.ErrorMessage); // TODO: Node reference, if available. } throw new Exception(sb.ToString()); } Variables[this.responseVariable] = (object)FieldsAsObject ?? FieldsAsArray.ToArray(); return(null); }