private void SendFields(int SeqNr, string From, ReadoutRequest Request) { try { StringBuilder sb = new StringBuilder(); SensorDataXmlExport Export = new SensorDataXmlExport(sb, false, true); string Xml100; PartitionedExport Partitioner = new PartitionedExport(sb, Export, 5000, (Partition, State) => { Xml100 = Partition.Substring(0, System.Math.Min(100, Partition.Length)); if (Xml100.Contains("<fields xmlns=\"urn:xmpp:iot:sensordata\"")) { Partition = Xml100.Replace("<fields xmlns=\"urn:xmpp:iot:sensordata\"", "<fields xmlns=\"urn:xmpp:iot:sensordata\" seqnr=\"" + SeqNr.ToString() + "\"") + Partition.Substring(Xml100.Length); } this.client.SendMessage(From, string.Empty, MessageType.Normal, Partition); }, null); this.DoReadout(Request, Partitioner); string Xml = sb.ToString(); Xml100 = Xml.Substring(0, System.Math.Min(100, Xml.Length)); if (Xml100.Contains("<fields xmlns=\"urn:xmpp:iot:sensordata\"")) { Xml = Xml100.Replace("<fields xmlns=\"urn:xmpp:iot:sensordata\"", "<fields xmlns=\"urn:xmpp:iot:sensordata\" done=\"true\" seqnr=\"" + SeqNr.ToString() + "\"") + Xml.Substring(Xml100.Length); this.client.SendMessage(From, string.Empty, MessageType.Normal, Xml); } else { this.client.SendMessage(From, string.Empty, MessageType.Normal, Xml); this.Done(SeqNr, From); } } catch (Exception ex2) { StringBuilder sb = new StringBuilder(); XmlWriter w = XmlWriter.Create(sb, XmlUtilities.GetXmlWriterSettings(false, true, true)); w.WriteStartElement("failure", "urn:xmpp:iot:sensordata"); w.WriteAttributeString("seqnr", SeqNr.ToString()); w.WriteAttributeString("done", "true"); w.WriteStartElement("error"); w.WriteValue(ex2.Message); w.WriteEndElement(); w.WriteEndElement(); w.Flush(); string Xml = sb.ToString(); this.client.SendMessage(From, string.Empty, MessageType.Normal, Xml); } }
private static object CoapGetXml(CoapRequest Request, object Payload) { StringBuilder sb = new StringBuilder(); ISensorDataExport SensorDataExport = new SensorDataXmlExport(sb, false, true); ExportSensorData(SensorDataExport, new ReadoutRequest(Request.ToHttpRequest())); XmlDocument Xml = new XmlDocument(); Xml.LoadXml(sb.ToString()); return(Xml); }