private void NodesResponse(IqResultEventArgs e, string ExpectedElement, bool Parameters, bool Messages, NodesInformationEventHandler Callback, object State) { XmlElement E; NodeInformation[] NodeInfo; if (e.Ok && (E = e.FirstElement) != null && E.LocalName == ExpectedElement) { List <NodeInformation> Nodes = new List <NodeInformation>(); foreach (XmlNode N in E.ChildNodes) { if (N is XmlElement E2 && E2.LocalName == "nd") { Nodes.Add(this.GetNodeInformation(E2, Parameters, Messages)); } } NodeInfo = Nodes.ToArray(); } else { e.Ok = false; NodeInfo = null; } if (Callback != null) { try { Callback(this, new NodesInformationEventArgs(NodeInfo, e)); } catch (Exception ex) { Log.Critical(ex); } } }
/// <summary> /// Gets information about all nodes in a data source. /// </summary> /// <param name="To">Address of server.</param> /// <param name="SourceID">Data source ID.</param> /// <param name="OnlyIfDerivedFrom">Array of types nodes must be derived from, to be included in the response.</param> /// <param name="Parameters">If node parameters should be included in response.</param> /// <param name="Messages">If messages should be included in the response.</param> /// <param name="Language">Code of desired language.</param> /// <param name="ServiceToken">Optional Service token.</param> /// <param name="DeviceToken">Optional Device token.</param> /// <param name="UserToken">Optional User token.</param> /// <param name="Callback">Method to call when response is returned.</param> /// <param name="State">State object to pass on to callback method.</param> public void GetAllNodes(string To, string SourceID, string[] OnlyIfDerivedFrom, bool Parameters, bool Messages, string Language, string ServiceToken, string DeviceToken, string UserToken, NodesInformationEventHandler Callback, object State) { StringBuilder Xml = new StringBuilder(); Xml.Append("<getAllNodes xmlns='"); Xml.Append(ConcentratorServer.NamespaceConcentrator); this.AppendTokenAttributes(Xml, ServiceToken, DeviceToken, UserToken); Xml.Append("' src='"); Xml.Append(XML.Encode(SourceID)); this.AppendNodeInfoAttributes(Xml, Parameters, Messages, Language); if (OnlyIfDerivedFrom != null) { Xml.Append("'>"); foreach (string TypeName in OnlyIfDerivedFrom) { Xml.Append("<onlyIfDerivedFrom>"); Xml.Append(XML.Encode(TypeName)); Xml.Append("</onlyIfDerivedFrom>"); } Xml.Append("</getAllNodes>"); } else { Xml.Append("'/>"); } this.client.SendIqGet(To, Xml.ToString(), (sender, e) => { this.NodesResponse(e, "getAllNodesResponse", Parameters, Messages, Callback, State); }, State); }
/// <summary> /// Gets information about all nodes in a data source. /// </summary> /// <param name="To">Address of server.</param> /// <param name="SourceID">Data source ID.</param> /// <param name="Parameters">If node parameters should be included in response.</param> /// <param name="Messages">If messages should be included in the response.</param> /// <param name="Language">Code of desired language.</param> /// <param name="ServiceToken">Optional Service token.</param> /// <param name="DeviceToken">Optional Device token.</param> /// <param name="UserToken">Optional User token.</param> /// <param name="Callback">Method to call when response is returned.</param> /// <param name="State">State object to pass on to callback method.</param> public void GetAllNodes(string To, string SourceID, bool Parameters, bool Messages, string Language, string ServiceToken, string DeviceToken, string UserToken, NodesInformationEventHandler Callback, object State) { this.GetAllNodes(To, SourceID, null, Parameters, Messages, Language, ServiceToken, DeviceToken, UserToken, Callback, State); }
/// <summary> /// Gets information about a set of nodes in the concentrator. /// </summary> /// <param name="To">Address of server.</param> /// <param name="Nodes">Node references.</param> /// <param name="Parameters">If node parameters should be included in response.</param> /// <param name="Messages">If messages should be included in the response.</param> /// <param name="Language">Code of desired language.</param> /// <param name="ServiceToken">Optional Service token.</param> /// <param name="DeviceToken">Optional Device token.</param> /// <param name="UserToken">Optional User token.</param> /// <param name="Callback">Method to call when response is returned.</param> /// <param name="State">State object to pass on to callback method.</param> public void GetNodes(string To, IThingReference[] Nodes, bool Parameters, bool Messages, string Language, string ServiceToken, string DeviceToken, string UserToken, NodesInformationEventHandler Callback, object State) { StringBuilder Xml = new StringBuilder(); Xml.Append("<getNodes xmlns='"); Xml.Append(ConcentratorServer.NamespaceConcentrator); this.AppendTokenAttributes(Xml, ServiceToken, DeviceToken, UserToken); this.AppendNodeInfoAttributes(Xml, Parameters, Messages, Language); Xml.Append("'>"); foreach (IThingReference Node in Nodes) { this.AppendNode(Xml, Node); } Xml.Append("</getNodes>"); this.client.SendIqGet(To, Xml.ToString(), (sender, e) => { this.NodesResponse(e, "getNodesResponse", Parameters, Messages, Callback, State); }, State); }