コード例 #1
0
        private void BooleansResponse(IqResultEventArgs e, string ExpectedElement, BooleansResponseEventHandler Callback, object State)
        {
            List <bool> Responses = new List <bool>();
            XmlElement  E;

            if (e.Ok && (E = e.FirstElement) != null && E.LocalName == ExpectedElement && E.NamespaceURI == ConcentratorServer.NamespaceConcentrator)
            {
                foreach (XmlNode N in E)
                {
                    if (N is XmlElement E2 && E2.LocalName == "value")
                    {
                        if (CommonTypes.TryParse(E2.InnerText, out bool Value))
                        {
                            Responses.Add(Value);
                        }
                        else
                        {
                            e.Ok = false;
                        }
                    }
                }
            }
            else
            {
                e.Ok = false;
            }

            if (Callback != null)
            {
                try
                {
                    Callback(this, new BooleansResponseEventArgs(Responses.ToArray(), e));
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Checks if the concentrator contains a set of nodes (that the user is allowed to see).
        /// </summary>
        /// <param name="To">Address of server.</param>
        /// <param name="Nodes">Nodes</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 ContainsNodes(string To, IThingReference[] Nodes, string ServiceToken, string DeviceToken, string UserToken,
                                  BooleansResponseEventHandler Callback, object State)
        {
            StringBuilder Xml = new StringBuilder();

            Xml.Append("<containsNodes xmlns='");
            Xml.Append(ConcentratorServer.NamespaceConcentrator);
            this.AppendTokenAttributes(Xml, ServiceToken, DeviceToken, UserToken);
            Xml.Append("'>");

            foreach (IThingReference Node in Nodes)
            {
                this.AppendNode(Xml, Node);
            }

            Xml.Append("</containsNodes>");

            this.client.SendIqGet(To, Xml.ToString(), (sender, e) =>
            {
                this.BooleansResponse(e, "containsNodesResponse", Callback, State);
            }, State);
        }