Пример #1
0
 private void appendResult(string[] result)
 {
     if (this.logTextBox.InvokeRequired)
     {
         SetResultCallback d = new SetResultCallback(appendResult);
         this.Invoke(d, new object[] { result });
     }
     else
     {
         logTextBox.AppendText("<" + result[0] + "><" + result[1] + ">: RESULT <" + result[2] + ">;\r\n");
     }
 }
Пример #2
0
        /// <summary>
        /// Sets a control parameter in a remote actuator.
        /// </summary>
        /// <param name="To">Full JID of remote actuator.</param>
        /// <param name="ControlParameterName">Control parameter name.</param>
        /// <param name="Value">Value to set.</param>
        /// <param name="ServiceToken">Service token of original sender, if available.</param>
        /// <param name="DeviceToken">Device token of original sender, if available.</param>
        /// <param name="UserToken">User token of original sender, if available.</param>
        /// <param name="Callback">Method called when set operation completes or fails.</param>
        /// <param name="State">State object to pass on to the callback method.</param>
        /// <param name="Nodes">Node(s) to set the parameter on, if residing behind a concentrator.</param>
        public void Set(string To, string ControlParameterName, bool Value, string ServiceToken, string DeviceToken, string UserToken,
                        SetResultCallback Callback, object State, params ThingReference[] Nodes)
        {
            StringBuilder Xml = this.SetHeader(ServiceToken, DeviceToken, UserToken, Nodes);

            Xml.Append("<b n='");
            Xml.Append(XML.Encode(ControlParameterName));
            Xml.Append("' v='");
            Xml.Append(CommonTypes.Encode(Value));
            Xml.Append("'/></set>");

            this.client.SendIqSet(To, Xml.ToString(), SetResultCallback, new object[] { Callback, State });
        }
Пример #3
0
        /// <summary>
        /// Sets control parameters from a data form, previously fetched using any of the GetForm methods.
        /// </summary>
        /// <param name="Form">Data form.</param>
        /// <param name="Callback">Callback method.</param>
        /// <param name="State">State object to pass on to callback method.</param>
        /// <param name="Nodes">Any nodes to control.</param>
        public void Set(DataForm Form, SetResultCallback Callback, object State, params ThingReference[] Nodes)
        {
            StringBuilder Xml = new StringBuilder();

            Xml.Append("<set xmlns='");
            Xml.Append(NamespaceControl);
            Xml.Append("'>");

            this.Serialize(Xml, Nodes);
            Form.SerializeSubmit(Xml);

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

            Form.Client.SendIqSet(Form.From, Xml.ToString(), SetResultCallback, new object[] { Callback, State });
        }
Пример #4
0
 private void SetResult(List <string> products)
 {
     if (categoryItems.InvokeRequired)
     {
         var d = new SetResultCallback(SetResult);
         Invoke(d, products);
     }
     else
     {
         if (products != null)
         {
             products.ForEach(item => categoryItems.Items.Add(item));
             ItemLabel.Text          = "";
             addGrocery.Visible      = false;
             addGroceryCount.Visible = false;
         }
     }
 }
Пример #5
0
 /// <summary>
 /// Sets a control parameter in a remote actuator.
 /// </summary>
 /// <param name="To">Full JID of remote actuator.</param>
 /// <param name="ControlParameterName">Control parameter name.</param>
 /// <param name="Value">Value to set.</param>
 /// <param name="Callback">Method called when set operation completes or fails.</param>
 /// <param name="State">State object to pass on to the callback method.</param>
 /// <param name="Nodes">Node(s) to set the parameter on, if residing behind a concentrator.</param>
 public void Set(string To, string ControlParameterName, bool Value, SetResultCallback Callback, object State, params ThingReference[] Nodes)
 {
     this.Set(To, ControlParameterName, Value, string.Empty, string.Empty, string.Empty, Callback, State, Nodes);
 }
Пример #6
0
        private void SetResultCallback(object Sender, IqResultEventArgs e)
        {
            object[]          P        = (object[])e.State;
            SetResultCallback Callback = (SetResultCallback)P[0];

            if (Callback == null)
            {
                return;
            }

            object             State = P[1];
            XmlElement         E     = e.FirstElement;
            XmlElement         E2;
            SetResultEventArgs e2;

            if (e.Ok)
            {
                if (E != null && E.LocalName == "resp" && E.NamespaceURI == NamespaceControl)
                {
                    List <ThingReference> Nodes          = null;
                    List <string>         ParameterNames = null;

                    foreach (XmlNode N in E.ChildNodes)
                    {
                        E2 = N as XmlElement;
                        if (E2 == null)
                        {
                            continue;
                        }

                        switch (N.LocalName)
                        {
                        case "nd":
                            if (Nodes == null)
                            {
                                Nodes = new List <ThingReference>();
                            }

                            Nodes.Add(new ThingReference(
                                          XML.Attribute(E2, "id"),
                                          XML.Attribute(E2, "src"),
                                          XML.Attribute(E2, "pt")));

                            break;

                        case "p":
                            if (ParameterNames == null)
                            {
                                ParameterNames = new List <string>();
                            }

                            ParameterNames.Add(XML.Attribute(E2, "n"));
                            break;
                        }
                    }

                    e2 = new SetResultEventArgs(e, true, Nodes?.ToArray(), ParameterNames?.ToArray(), State);
                }
                else
                {
                    e2 = new SetResultEventArgs(e, true, null, null, State);
                }
            }
            else
            {
                e2 = new SetResultEventArgs(e, false, null, null, State);
            }

            try
            {
                Callback(this, e2);
            }
            catch (Exception ex)
            {
                Log.Critical(ex);
            }
        }