Ejemplo n.º 1
0
        private void Done(XmppClient Client, XmlElement Element, string From, string To)
        {
            SensorDataEventArgs e = this.GetReceiver(Element, true);

            if (e == null)
            {
                return;
            }

            e.Receiving();
            e.DoCallback(this);
        }
Ejemplo n.º 2
0
        private void Started(XmppClient Client, XmlElement Element, string From, string To)
        {
            SensorDataEventArgs e = this.GetReceiver(Element, false);

            if (e == null)
            {
                return;
            }

            e.StartReadout();
            e.DoCallback(this);
        }
Ejemplo n.º 3
0
        private void Fields(XmppClient Client, XmlElement Element, string From, string To)
        {
            SensorDataEventArgs e = this.GetReceiver(Element, true);

            if (e == null)
            {
                return;
            }

            e.Receiving();

            bool Done;

            Field[] Fields = Import.Parse(Element, out Done);
            foreach (Field Field in Fields)
            {
                e.AddField(Field);
            }

            e.DoCallback(this);
        }
Ejemplo n.º 4
0
        private void Failure(XmppClient Client, XmlElement Element, string From, string To)
        {
            SensorDataEventArgs e = this.GetReceiver(Element, false);

            if (e == null)
            {
                return;
            }

            e.Receiving();

            XmlElement ErrorElement;
            DateTime   Timestamp;

            foreach (XmlNode N in Element.ChildNodes)
            {
                ErrorElement = N as XmlElement;
                if (ErrorElement == null || ErrorElement.LocalName != "error")
                {
                    continue;
                }

                Timestamp = XmlUtilities.GetAttribute(ErrorElement, "timestamp", DateTime.MinValue);
                if (Timestamp == DateTime.MinValue)
                {
                    continue;
                }

                string NodeId    = XmlUtilities.GetAttribute(ErrorElement, "nodeId", string.Empty);
                string SourceId  = XmlUtilities.GetAttribute(ErrorElement, "sourceId", string.Empty);
                string CacheType = XmlUtilities.GetAttribute(ErrorElement, "cacheType", string.Empty);

                e.AddReadoutError(new ReadoutError(Timestamp, ErrorElement.InnerText.Trim(), NodeId, CacheType, SourceId));
            }

            e.DoCallback(this);
        }
Ejemplo n.º 5
0
        private void ReqResponse(XmppClient Client, string Type, XmlNodeList Response, ref StanzaError Error, object State)
        {
            SensorDataEventArgs e = (SensorDataEventArgs)State;
            XmlElement          E;

            if (Error != null)
            {
                if (!string.IsNullOrEmpty(Error.Text))
                {
                    e.SetError(Error.Text);
                }
                else
                {
                    e.SetError("Readout rejected by remote device.");
                }

                Error = null;
            }
            else
            {
                foreach (XmlNode N in Response)
                {
                    E = N as XmlElement;
                    if (E == null)
                    {
                        continue;
                    }

                    if (E.LocalName == "accepted")
                    {
                        int SeqNr = XmlUtilities.GetAttribute(E, "seqnr", 0);

                        if (SeqNr == e.SeqNr)
                        {
                            e.ReadoutState = ReadoutState.Accepted;

                            lock (this.synchObj)
                            {
                                this.receiving [SeqNr] = e;
                            }
                        }
                        else
                        {
                            e.SetError("Invalid sequence number returned in response.");
                        }
                    }
                    else if (E.LocalName == "rejected")
                    {
                        e.ReadoutState = ReadoutState.Rejected;
                        e.Done         = true;

                        foreach (XmlNode N2 in E.ChildNodes)
                        {
                            if (N2.LocalName == "error")
                            {
                                if (string.IsNullOrEmpty(e.ErrorMessage))
                                {
                                    e.ErrorMessage = N2.InnerText;
                                }
                                else
                                {
                                    e.ErrorMessage += "\r\n" + N2.InnerText;
                                }
                            }
                        }

                        if (string.IsNullOrEmpty(e.ErrorMessage))
                        {
                            e.ErrorMessage = "Readout rejected by remote device.";
                        }
                    }
                }
            }

            e.DoCallback(this);
        }