/// <summary> /// Stops exporting Sensor Data. /// </summary> public override void End () { base.End (); TurtleDocument TurtleDoc = new TurtleDocument (this.turtle.ToString ()); RdfDocument.GenerateRdfXml (this.xml, TurtleDoc.GetPrefixedNamespaces (null), TurtleDoc.Triples, false); }
/// <summary> /// Stops exporting Sensor Data. /// </summary> public override void End() { base.End(); TurtleDocument TurtleDoc = new TurtleDocument(this.turtle.ToString()); RdfDocument.GenerateRdfXml(this.xml, TurtleDoc.GetPrefixedNamespaces(null), TurtleDoc.Triples, false); }
private void Scan(object Parameter) { object[] P = (object[])Parameter; User User = (User)P[0]; Language UserLanguage = (Language)P[1]; try { CoapEndpoint Endpoint = this.Endpoint; CoapResponse Response; LinkFormatDocument LinkDoc; Response = Endpoint.GET(true, this.Host, this.Port, ".well-known/core", string.Empty, 20000); LinkDoc = Response.Response as LinkFormatDocument; if (LinkDoc == null) { throw new Exception(CoapNode.String(28, "Unexpected response returned.")); } foreach (Link Link in LinkDoc.Links) { Uri Uri = new Uri(Link.Url); string[] Parts = Uri.PathAndQuery.Split('/'); EditableTreeNode Node = this; int i, c = Parts.Length; string Segment; object Obj; CoapContent Content; CoapFolder Folder; CoapNode Found; StringBuilder Path = null; for (i = 0; i < c - 1; i++) { Segment = Parts[i]; if (string.IsNullOrEmpty(Segment)) { continue; } if (i <= 1 && Segment == ".well-known") { break; } Found = null; if (Path == null) { Path = new StringBuilder(); } else { Path.Append('/'); } Path.Append(Segment); foreach (EditableTreeNode Child in Node.AllChildren) { if ((Folder = Child as CoapFolder) != null && Folder.Folder == Segment) { Found = Folder; break; } } if (Found == null) { Parameters Param = EditableObject.GetParametersForNewObject(typeof(CoapFolder), true, User.AllPrivileges); Param[Clayster.Library.Meters.Node.DefaultIdParameterId] = this.Id + "/" + Path.ToString(); Param["folder"] = Segment; Found = (CoapNode)EditableObject.CreateNewObject(typeof(CoapFolder), Param, UserLanguage, true, Topology.Source, User); Node.Add(Found); } Node = Found; } Segment = Parts[c - 1]; if (!string.IsNullOrEmpty(Segment)) { Found = null; if (Path == null) { Path = new StringBuilder(); } else { Path.Append('/'); } Path.Append(Segment); foreach (EditableTreeNode Child in Node.AllChildren) { if ((Content = Child as CoapContent) != null && Content.Resource == Segment) { Found = Content; break; } } if (Found == null) { try { Type T = null; Response = Endpoint.GET(true, this.Host, this.Port, Path.ToString(), string.Empty, 20000); Obj = Response.Response; if (Obj is string) { string s = (string)Obj; PhysicalMagnitude M; Duration D; DateTime TP; double d; int NrDec; bool b; if (XmlUtilities.TryParseBoolean(s, out b)) { T = typeof(CoapBoolean); } else if (XmlUtilities.TryParseDuration(s, out D)) { T = typeof(CoapDuration); } else if (XmlUtilities.TryParseDateTimeXml(s, out TP) || (TP = Web.ParseDateTimeRfc822(s)) != DateTime.MinValue) { T = typeof(CoapDateTime); } else if (XmlUtilities.TryParseDouble(s, out d, out NrDec)) { T = typeof(CoapNumber); } else if (PhysicalMagnitude.TryParse(s, out M)) { T = typeof(CoapPhysicalMagnitude); } else { try { TurtleDocument TurtleDoc = new TurtleDocument((string)Obj, "coap://" + this.Host + ":" + this.Port.ToString() + "/" + Path.ToString()); } catch (Exception) { T = typeof(CoapString); } } } else if (Obj is XmlDocument) { XmlDocument Doc = (XmlDocument)Obj; if (Doc.DocumentElement.LocalName == "FieldsRoot" && Doc.DocumentElement.NamespaceURI == "http://clayster.com/schema/Fields/v1.xsd") { T = typeof(CoapFields); } else if ((Doc.DocumentElement.LocalName == "fields" || Doc.DocumentElement.LocalName == "failure") && Doc.DocumentElement.NamespaceURI == "urn:xmpp:iot:sensordata") { T = typeof(CoapXep0323); } else { T = typeof(CoapXml); } } else if (Obj is LinkFormatDocument) { // Ignore } else if (Obj is byte[]) { // Ignore } else { T = typeof(CoapJson); } if (T != null) { Parameters Param = EditableObject.GetParametersForNewObject(T, true, User.AllPrivileges); Param[Clayster.Library.Meters.Node.DefaultIdParameterId] = this.Id + "/" + Path.ToString(); Param["resource"] = Segment; if (Param.ContainsParameter("fieldName")) { Param["fieldName"] = Segment; } Found = (CoapNode)EditableObject.CreateNewObject(T, Param, UserLanguage, true, Topology.Source, User); Node.Add(Found); } } catch (Exception ex) { this.LogException(ex); } } } } } catch (Exception ex) { this.LogException(ex); } finally { this.scanning = false; } }