Esempio n. 1
1
		/// <summary>
		/// Starts the export of sensor data values for a particular point in time. This call must be followed by a call to <see cref="EndExportTimestamp"/>.
		/// Use <see cref="ExportField"/> to export field  information to the Sensor Data TURTLE document.
		/// </summary>
		/// <param name="Turtle">TURTLE Output</param>
		/// <param name="Timestamp">Timestamp</param>
		public static void StartExportTimestamp (TurtleWriter Turtle, DateTime Timestamp)
		{
			Timestamp = Timestamp.ToUniversalTime ();

			Turtle.WritePredicateUri ("cl", "sample");
			Turtle.StartBlankNode ();

			Turtle.WritePredicateUri ("cl", "timestamp");
			Turtle.WriteObjectLiteralTyped (XmlUtilities.DateTimeToString (Timestamp), "xsd", "dateTime");
		}
Esempio n. 2
1
		/// <summary>
		/// <see cref="Field.ExportAsTurtleSensorData"/>
		/// </summary>
		public override void ExportAsTurtleSensorData(TurtleWriter w)
		{
			w.WritePredicateUri ("cl", "field");
			w.StartBlankNode ();

			this.ExportAsTurtleSensorDataCommonAttributes(w);

			w.WritePredicateUri ("cl", "enum");
			w.WriteObjectLiteral (this.value);

			w.WritePredicateUri ("cl", "dataType");
			w.WriteObjectLiteral (this.dataType);

			w.EndBlankNode ();
		}
Esempio n. 3
1
		/// <summary>
		/// <see cref="Field.ExportAsTurtleSensorData"/>
		/// </summary>
		public override void ExportAsTurtleSensorData(TurtleWriter w)
		{
			w.WritePredicateUri ("cl", "field");
			w.StartBlankNode ();

			this.ExportAsTurtleSensorDataCommonAttributes(w);

			w.WritePredicateUri ("cl", "dateTime");
			w.WriteObjectLiteralTyped (XmlUtilities.DateTimeToString(this.value), "xsd", "dateTime");

			w.EndBlankNode ();
		}
        private static void SaveGraph()
        {
            var turtleWriter = new TurtleWriter();

            //Save to a File
            turtleWriter.Save(g, filePath);
        }
Esempio n. 5
0
        /// <summary>
        /// <see cref="Field.ExportAsTurtleSensorData"/>
        /// </summary>
        public override void ExportAsTurtleSensorData(TurtleWriter w)
        {
            w.WritePredicateUri("cl", "field");
            w.StartBlankNode();

            this.ExportAsTurtleSensorDataCommonAttributes(w);

            w.WritePredicateUri("cl", "duration");
            w.WriteObjectLiteralTyped(this.value.ToDuration().ToString(), "xsd", "duration");

            w.EndBlankNode();
        }
Esempio n. 6
0
        /// <summary>
        /// <see cref="Field.ExportAsTurtleSensorData"/>
        /// </summary>
        public override void ExportAsTurtleSensorData(TurtleWriter w)
        {
            w.WritePredicateUri("cl", "field");
            w.StartBlankNode();

            this.ExportAsTurtleSensorDataCommonAttributes(w);

            w.WritePredicateUri("cl", "dateTime");
            w.WriteObjectLiteralTyped(XmlUtilities.DateTimeToString(this.value), "xsd", "dateTime");

            w.EndBlankNode();
        }
        /// <summary>
        /// <see cref="Field.ExportAsTurtleSensorData"/>
        /// </summary>
        public override void ExportAsTurtleSensorData(TurtleWriter w)
        {
            w.WritePredicateUri("cl", "field");
            w.StartBlankNode();

            this.ExportAsTurtleSensorDataCommonAttributes(w);

            w.WritePredicateUri("cl", "boolean");
            w.WriteObjectLiteralTyped(this.value);

            w.EndBlankNode();
        }
Esempio n. 8
0
		/// <summary>
		/// Starts exporting Sensor Data TURTLE. This call must be followed by a call to <see cref="EndExportTurtle"/>.
		/// Use <see cref="StartExportNode"/> to export node information to the Sensor Data TURTLE document.
		/// </summary>
		/// <returns>TURTLE Writer, used for the export.</returns>
		/// <param name="Output">TURTLE will be output here.</param>
		/// <param name="Request">HTTP Request resulting in the generation of the TURTLE document.</param>
		public static TurtleWriter StartExportTurtle (StringBuilder Output, HttpServerRequest Request)
		{
			string HostUrl = GetHostUrl (Request);
			TurtleWriter Turtle = new TurtleWriter (Output);
			Turtle.WritePrefix ("l", HostUrl);
			Turtle.WritePrefix ("cl", "http://clayster.com/sw/");
			//Turtle.WritePrefix ("clu", "http://clayster.com/sw/u/");
			return Turtle;
		}
Esempio n. 9
0
		/// <summary>
		/// Exports an enumeration field.
		/// </summary>
		/// <param name="Turtle">TURTLE Output</param>
		/// <param name="FieldName">Field name.</param>
		/// <param name="Value">Value.</param>
		public static void ExportField (TurtleWriter Turtle, string FieldName, Enum Value)
		{
			ExportField (Turtle, new FieldEnum (string.Empty, FieldName, (FieldLanguageStep[])null, DateTime.MinValue, Value, ReadoutType.MomentaryValues, FieldStatus.AutomaticReadout));
		}
Esempio n. 10
0
		/// <summary>
		/// Exports a numerical field.
		/// </summary>
		/// <param name="Turtle">TURTLE Output</param>
		/// <param name="FieldName">Field name.</param>
		/// <param name="Value">Value.</param>
		/// <param name="NrDecimals">Number of decimals.</param>
		/// <param name="Unit">Unit.</param>
		public static void ExportField (TurtleWriter Turtle, string FieldName, double Value, int NrDecimals, string Unit)
		{
			ExportField (Turtle, new FieldNumeric (string.Empty, FieldName, (FieldLanguageStep[])null, DateTime.MinValue, Value, NrDecimals, Unit, ReadoutType.MomentaryValues, FieldStatus.AutomaticReadout));
		}
Esempio n. 11
0
		/// <summary>
		/// Exports a TimeSpan field.
		/// </summary>
		/// <param name="Turtle">TURTLE Output</param>
		/// <param name="FieldName">Field name.</param>
		/// <param name="Value">Value.</param>
		/// <param name="Type">Type.</param>
		public static void ExportField (TurtleWriter Turtle, string FieldName, TimeSpan Value, ReadoutType Type)
		{
			ExportField (Turtle, new FieldTimeSpan (string.Empty, FieldName, (FieldLanguageStep[])null, DateTime.MinValue, Value, Type, FieldStatus.AutomaticReadout));
		}
Esempio n. 12
0
		/// <summary>
		/// Exports common Field attributes, similar to XEP-0323 Sensor data, but using TURTLE.
		/// </summary>
		/// <param name="w">TURTLE Output</param>
		protected void ExportAsTurtleSensorDataCommonAttributes (TurtleWriter w)
		{
			w.WritePredicateUri ("cl", "name");
			w.WriteObjectLiteral (this.fieldName);

			if ((this.type & ReadoutType.MomentaryValues) != 0)
			{
				w.WritePredicateUri ("cl", "momentary");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.PeakValues) != 0)
			{
				w.WritePredicateUri ("cl", "peak");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.StatusValues) != 0)
			{
				w.WritePredicateUri ("cl", "status");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.Computed) != 0)
			{
				w.WritePredicateUri ("cl", "computed");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.Identity) != 0)
			{
				w.WritePredicateUri ("cl", "identity");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesSecond) != 0)
			{
				w.WritePredicateUri ("cl", "historicalSecond");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesMinute) != 0)
			{
				w.WritePredicateUri ("cl", "historicalMinute");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesHour) != 0)
			{
				w.WritePredicateUri ("cl", "historicalHour");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesDay) != 0)
			{
				w.WritePredicateUri ("cl", "historicalDay");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesWeek) != 0)
			{
				w.WritePredicateUri ("cl", "historicalWeek");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesMonth) != 0)
			{
				w.WritePredicateUri ("cl", "historicalMonth");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesQuarter) != 0)
			{
				w.WritePredicateUri ("cl", "historicalQuarter");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesYear) != 0)
			{
				w.WritePredicateUri ("cl", "historicalYear");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.type & ReadoutType.HistoricalValuesOther) != 0)
			{
				w.WritePredicateUri ("cl", "historicalOther");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.Missing) != 0)
			{
				w.WritePredicateUri ("cl", "missing");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.AutomaticEstimate) != 0)
			{
				w.WritePredicateUri ("cl", "automaticEstimate");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.ManualEstimate) != 0)
			{
				w.WritePredicateUri ("cl", "manualEstimate");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.ManualReadout) != 0)
			{
				w.WritePredicateUri ("cl", "manualReadout");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.AutomaticReadout) != 0)
			{
				w.WritePredicateUri ("cl", "automaticReadout");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.TimeOffset) != 0)
			{
				w.WritePredicateUri ("cl", "timeOffset");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.Warning) != 0)
			{
				w.WritePredicateUri ("cl", "warning");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.Error) != 0)
			{
				w.WritePredicateUri ("cl", "error");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.Signed) != 0)
			{
				w.WritePredicateUri ("cl", "signed");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.Invoiced) != 0)
			{
				w.WritePredicateUri ("cl", "invoiced");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.EndOfSeries) != 0)
			{
				w.WritePredicateUri ("cl", "endOfSeries");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.PowerFailure) != 0)
			{
				w.WritePredicateUri ("cl", "powerFailure");
				w.WriteObjectLiteralTyped (true);
			}

			if ((this.status & FieldStatus.InvoicedConfirmed) != 0)
			{
				w.WritePredicateUri ("cl", "invoiceConfirmed");
				w.WriteObjectLiteralTyped (true);
			}

			if (this.stringIds != null && this.stringIds.Length > 0)
			{
				if (!string.IsNullOrEmpty (this.languageModule))
				{
					w.WritePredicateUri ("cl", "module");
					w.WriteObjectLiteral (this.languageModule);
				}

				w.WritePredicateUri ("cl", "stringIds");
				w.StartObjectSeq ();

				foreach (FieldLanguageStep Step in this.stringIds)
				{
					w.AddItemStartBlankNode ();

					w.WritePredicateUri ("cl", "stringId");
					w.WriteObjectLiteralTyped (Step.StringId);

					if (Step.Seed != null)
					{
						w.WritePredicateUri ("cl", "seed");
						w.WriteObjectLiteral (Step.Seed.ToString ());
					}

					if (!string.IsNullOrEmpty (Step.LanguageModule))
					{
						w.WritePredicateUri ("cl", "module");
						w.WriteObjectLiteral (Step.LanguageModule);
					}

					w.EndBlankNode ();
				}

				w.EndObjectSeq ();
			}
		}
Esempio n. 13
0
		/// <summary>
		/// Exports a field.
		/// </summary>
		/// <param name="Field">Field.</param>
		/// <param name="Turtle">TURTLE Output</param>
		public static void ExportField (TurtleWriter Turtle, Field Field)
		{
			Field.ExportAsTurtleSensorData (Turtle);
		}
		/// <summary>
		/// Initializes the export module.
		/// </summary>
		/// <param name="Output">TURTLE will be output here.</param>
		/// <param name="Request">HTTP Request resulting in the generation of the TURTLE document.</param>
		protected void Init(StringBuilder Output, HttpServerRequest Request)
		{
			this.turtle = new TurtleWriter (Output);
			this.request = Request;
		}
 /// <summary>
 /// Class handling export of sensor data to TURTLE.
 /// </summary>
 protected SensorDataTurtleExport()
 {
     this.turtle = null;
 }
Esempio n. 16
0
		/// <summary>
		/// Starts exporting Sensor Data TURTLE. This call must be followed by a call to <see cref="EndExportTurtle"/>.
		/// Use <see cref="StartExportNode"/> to export node information to the Sensor Data TURTLE document.
		/// </summary>
		/// <param name="Output">TURTLE will be output here.</param>
		/// <param name="Request">HTTP Request resulting in the generation of the TURTLE document.</param>
		public static void StartExportTurtle (TurtleWriter Output, HttpServerRequest Request)
		{
			string HostUrl = GetHostUrl (Request);
			Output.WritePrefix ("l", HostUrl);
			Output.WritePrefix ("cl", "http://clayster.com/sw/");
			//Output.WritePrefix ("clu", "http://clayster.com/sw/u/");
		}
Esempio n. 17
0
		/// <summary>
		/// <see cref="Field.ExportAsTurtleSensorData"/>
		/// </summary>
		public override void ExportAsTurtleSensorData(TurtleWriter w)
		{
			w.WritePredicateUri ("cl", "field");
			w.StartBlankNode ();

			this.ExportAsTurtleSensorDataCommonAttributes (w);

			w.WritePredicateUri ("cl", "numeric");
			w.WriteObjectLiteralTyped (this.value);

			//string EncodedUnit = HttpUtilities.UrlEncode (this.unit);
			//
			//if (EncodedUnit == this.unit)
			//	w.WriteObjectLiteralTyped (XmlUtilities.DoubleToString (this.value, this.nrDecimals), "clu", this.unit);
			//else
			//	w.WriteObjectLiteralTyped (XmlUtilities.DoubleToString (this.value, this.nrDecimals), "http://clayster.com/sw/u/" + EncodedUnit);

			w.WritePredicateUri ("cl", "unit");
			w.WriteObjectLiteral (this.unit);

			w.WritePredicateUri ("cl", "nrDec");
			w.WriteObjectLiteralTyped (this.nrDecimals);

			w.EndBlankNode ();
		}
Esempio n. 18
0
		/// <summary>
		/// <see cref="Field.ExportAsTurtleSensorData"/>
		/// </summary>
		public override void ExportAsTurtleSensorData(TurtleWriter w)
		{
			w.WritePredicateUri ("cl", "field");
			w.StartBlankNode ();

			this.ExportAsTurtleSensorDataCommonAttributes(w);

			w.WritePredicateUri ("cl", "duration");
			w.WriteObjectLiteralTyped (this.value.ToDuration().ToString(), "xsd", "duration");

			w.EndBlankNode ();
		}
Esempio n. 19
0
        static void Main(string[] args)
        {
            //Going to create a Graph and assert some stuff into it
            Graph g = new Graph();

            //Try to read from a file
            TurtleParser parser = new TurtleParser();

            parser.TraceTokeniser = true;
            parser.TraceParsing   = true;
            try
            {
                StreamReader input = new StreamReader("test.n3");
                parser.Load(g, input);
            }
            catch (RDFException rdfEx)
            {
                reportError("RDF Exception", rdfEx);
            }
            catch (IOException ioEx)
            {
                reportError("IO Exception", ioEx);
            }
            catch (Exception ex)
            {
                reportError("Other Exception", ex);
            }

            Console.WriteLine();
            Console.WriteLine();

            //Show Namespaces
            Console.WriteLine("All Namespaces");
            foreach (String pre in g.NamespaceMap.Prefixes)
            {
                Console.WriteLine(pre + " = " + g.NamespaceMap.GetNamespaceURI(pre));
            }

            Console.WriteLine();

            //Now print all the Statements
            Console.WriteLine("All Statements");
            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString());
            }


            System.Threading.Thread.Sleep(60000);
            return;



            g.NamespaceMap.AddNamespace("vds", new Uri("http://www.vdesign-studios.com/dotNetRDF#"));
            g.NamespaceMap.AddNamespace("ecs", new Uri("http://id.ecs.soton.ac.uk/person/"));
            //g.BaseURI = g.NamespaceMap.GetNamespaceURI("vds");

            URINode rav08r, wh, lac, hcd;

            rav08r = g.CreateURINode("ecs:11471");
            wh     = g.CreateURINode("ecs:1650");
            hcd    = g.CreateURINode("ecs:46");
            lac    = g.CreateURINode("ecs:60");

            BlankNode blank = g.CreateBlankNode();
            URINode   a, b, c, d, has;

            a   = g.CreateURINode("vds:someRel");
            b   = g.CreateURINode("vds:someOtherRel");
            c   = g.CreateURINode("vds:someObj");
            d   = g.CreateURINode("vds:someOtherObj");
            has = g.CreateURINode("vds:has");

            URINode supervises, collaborates, advises;

            supervises   = g.CreateURINode("vds:supervises");
            collaborates = g.CreateURINode("vds:collaborates");
            advises      = g.CreateURINode("vds:advises");

            LiteralNode singleLine = g.CreateLiteralNode("Some string");
            LiteralNode multiLine  = g.CreateLiteralNode("This goes over\n\nseveral\n\nlines");
            LiteralNode french     = g.CreateLiteralNode("Bonjour", "fr");

            g.Assert(new Triple(wh, supervises, rav08r));
            g.Assert(new Triple(lac, supervises, rav08r));
            g.Assert(new Triple(hcd, advises, rav08r));
            g.Assert(new Triple(wh, collaborates, lac));
            g.Assert(new Triple(wh, collaborates, hcd));
            g.Assert(new Triple(lac, collaborates, hcd));
            //g.Assert(new Triple(rav08r, blank, c));
            //g.Assert(new Triple(rav08r, blank, d));
            g.Assert(new Triple(rav08r, has, singleLine));
            g.Assert(new Triple(rav08r, has, multiLine));
            g.Assert(new Triple(rav08r, has, french));


            //Now print all the Statements
            Console.WriteLine("All Statements");
            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString());
            }

            //Get statements about Rob Vesse
            Console.WriteLine();
            Console.WriteLine("Statements about Rob Vesse");
            foreach (Triple t in g.GetTriples(rav08r))
            {
                Console.WriteLine(t.ToString());
            }

            //Get Statements about Collaboration
            Console.WriteLine();
            Console.WriteLine("Statements about Collaboration");
            foreach (Triple t in g.GetTriples(collaborates))
            {
                Console.WriteLine(t.ToString());
            }

            //Show Namespaces for URINodes
            Console.WriteLine();
            Console.WriteLine("Namespaces for URI Nodes");
            foreach (URINode u in g.Nodes.URINodes)
            {
                Console.WriteLine(u.Namespace + " = " + u.URI);
            }

            //Attempt to output Notation 3 for this Graph
            try
            {
                TurtleWriter n3writer = new TurtleWriter();
                n3writer.Save(g, "test.n3");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }



            System.Threading.Thread.Sleep(30000);
        }
 /// <summary>
 /// Class handling export of sensor data to TURTLE.
 /// </summary>
 /// <param name="Output">TURTLE will be output here.</param>
 /// <param name="Request">HTTP Request resulting in the generation of the TURTLE document.</param>
 public SensorDataTurtleExport(StringBuilder Output, HttpServerRequest Request)
 {
     this.turtle  = new TurtleWriter(Output);
     this.request = Request;
 }
 /// <summary>
 /// Initializes the export module.
 /// </summary>
 /// <param name="Output">TURTLE will be output here.</param>
 /// <param name="Request">HTTP Request resulting in the generation of the TURTLE document.</param>
 protected void Init(StringBuilder Output, HttpServerRequest Request)
 {
     this.turtle  = new TurtleWriter(Output);
     this.request = Request;
 }
Esempio n. 22
0
		/// <summary>
		/// Stops exporting Sensor Data TURTLE. This call must be made for every call made to <see cref="StartExportTurtle"/>.
		/// </summary>
		/// <param name="Turtle">TURTLE Output</param>
		public static void EndExportTurtle (TurtleWriter Turtle)
		{
			Turtle.Flush ();
		}
Esempio n. 23
0
		/// <summary>
		/// Starts the export of sensor data values for a particular node. This call must be followed by a call to <see cref="EndExportNode"/>.
		/// Use <see cref="StartExportTimestamp"/> to export node information pertaining to a given point in time to the Sensor Data TURTLE document.
		/// </summary>
		/// <param name="Turtle">TURTLE Output</param>
		/// <param name="NodeId">Node ID.</param>
		public static void StartExportNode (TurtleWriter Turtle, string NodeId)
		{
			StartExportNode (Turtle, NodeId, string.Empty, string.Empty);
		}
		/// <summary>
		/// Class handling export of sensor data to TURTLE.
		/// </summary>
		protected SensorDataTurtleExport ()
		{
			this.turtle = null;
		}
Esempio n. 25
0
		/// <summary>
		/// Stops exporting a timestamp. This call must be made for every call made to <see cref="StartExportTimestamp"/>.
		/// </summary>
		/// <param name="Turtle">TURTLE Output</param>
		public static void EndExportTimestamp (TurtleWriter Turtle)
		{
			Turtle.EndBlankNode ();
		}
		/// <summary>
		/// Class handling export of sensor data to TURTLE.
		/// </summary>
		/// <param name="Output">TURTLE will be output here.</param>
		/// <param name="Request">HTTP Request resulting in the generation of the TURTLE document.</param>
		public SensorDataTurtleExport (StringBuilder Output, HttpServerRequest Request)
		{
			this.turtle = new TurtleWriter (Output);
			this.request = Request;
		}
Esempio n. 27
0
        public void Dispose()
        {
            //Create all of the directories required for the file
            var f = new FileInfo(_outputPath);

            f.Directory.Create();

            if (this._outputFormat == ERdfFormat.RdfXml)
            {
                using (XmlTextWriter xmlWriter = new XmlTextWriter(_outputPath, new UTF8Encoding(false)))
                //Set encoding
                {
                    _output.Save(xmlWriter);
                }
            }
            else if (this._outputFormat == ERdfFormat.TriG)
            {
                string fileNameAsTrig = GetFilePathBasedOnFormat();
                var    outparams      = new StreamParams(fileNameAsTrig);
                outparams.Encoding = Encoding.UTF8;
                var writer = new TriGWriter();

                if (_store == null)
                {
                    var g = GetXmlDocumentAsGraph();
                    _store = new TripleStore();
                    _store.Add(g, true);
                }

                writer.Save(_store, outparams);
            }
            else if (this._outputFormat == ERdfFormat.Turtle)
            {
                var    g = GetXmlDocumentAsGraph();
                string filePathForFormat = GetFilePathBasedOnFormat();
                var    writer            = new TurtleWriter(TurtleSyntax.W3C);
                writer.Save(g, filePathForFormat);
            }
            else if (this._outputFormat == ERdfFormat.NTriples)
            {
                var    g = GetXmlDocumentAsGraph();
                string filePathForFormat = GetFilePathBasedOnFormat();
                var    writer            = new NTriplesWriter();
                writer.Save(g, filePathForFormat);
            }
            else if (this._outputFormat == ERdfFormat.N3)
            {
                var    g = GetXmlDocumentAsGraph();
                string filePathForFormat = GetFilePathBasedOnFormat();
                var    writer            = new Notation3Writer();
                writer.Save(g, filePathForFormat);
            }
            else if (this._outputFormat == ERdfFormat.NQuads)
            {
                string filePathForFormat = GetFilePathBasedOnFormat();
                var    outparams         = new StreamParams(filePathForFormat);
                outparams.Encoding = Encoding.UTF8;

                if (_store == null)
                {
                    var g = GetXmlDocumentAsGraph();
                    _store = new TripleStore();
                    _store.Add(g, true);
                }

                var writer = new NQuadsWriter();
                writer.Save(_store, outparams);
            }

            //make sure it's not null - can happen if no graphs have yet to be asserted!!
            if (_store != null)
            {
                foreach (var graph in _store.Graphs)
                {
                    graph.Dispose();
                }
                _store.Dispose();
                GC.Collect();
            }
        }
Esempio n. 28
0
		/// <summary>
		/// Exports an enumeration field.
		/// </summary>
		/// <param name="Turtle">TURTLE Output</param>
		/// <param name="FieldName">Field name.</param>
		/// <param name="Value">Value.</param>
		/// <param name="Type">Type.</param>
		/// <param name="Status">Status.</param>
		public static void ExportField (TurtleWriter Turtle, string FieldName, Enum Value, ReadoutType Type, FieldStatus Status)
		{
			ExportField (Turtle, new FieldEnum (string.Empty, FieldName, (FieldLanguageStep[])null, DateTime.MinValue, Value, Type, Status));
		}
Esempio n. 29
0
		/// <summary>
		/// Exports the field to TURTLE in a similar fashion as XEP-0323 Sensor Data.
		/// </summary>
		/// <param name="w">TURTLE Output</param>
		public abstract void ExportAsTurtleSensorData (TurtleWriter w);
Esempio n. 30
0
        public void GraphCreation1()
        {
            //Create a new Empty Graph
            Graph g = new Graph();

            Assert.NotNull(g);

            //Define Namespaces
            g.NamespaceMap.AddNamespace("vds", new Uri("http://www.vdesign-studios.com/dotNetRDF#"));
            g.NamespaceMap.AddNamespace("ecs", new Uri("http://id.ecs.soton.ac.uk/person/"));

            //Check we set the Namespace OK
            Assert.True(g.NamespaceMap.HasNamespace("vds"), "Failed to set a Namespace");

            //Set Base Uri
            g.BaseUri = g.NamespaceMap.GetNamespaceUri("vds");
            Assert.NotNull(g.BaseUri);
            Assert.Equal(g.NamespaceMap.GetNamespaceUri("vds"), g.BaseUri);

            //Create Uri Nodes
            IUriNode rav08r, wh, lac, hcd;

            rav08r = g.CreateUriNode("ecs:11471");
            wh     = g.CreateUriNode("ecs:1650");
            hcd    = g.CreateUriNode("ecs:46");
            lac    = g.CreateUriNode("ecs:60");

            //Create Uri Nodes for some Predicates
            IUriNode supervises, collaborates, advises, has;

            supervises   = g.CreateUriNode("vds:supervises");
            collaborates = g.CreateUriNode("vds:collaborates");
            advises      = g.CreateUriNode("vds:advises");
            has          = g.CreateUriNode("vds:has");

            //Create some Literal Nodes
            ILiteralNode singleLine = g.CreateLiteralNode("Some string");
            ILiteralNode multiLine  = g.CreateLiteralNode("This goes over\n\nseveral\n\nlines");
            ILiteralNode french     = g.CreateLiteralNode("Bonjour", "fr");
            ILiteralNode number     = g.CreateLiteralNode("12", new Uri(g.NamespaceMap.GetNamespaceUri("xsd") + "integer"));

            g.Assert(new Triple(wh, supervises, rav08r));
            g.Assert(new Triple(lac, supervises, rav08r));
            g.Assert(new Triple(hcd, advises, rav08r));
            g.Assert(new Triple(wh, collaborates, lac));
            g.Assert(new Triple(wh, collaborates, hcd));
            g.Assert(new Triple(lac, collaborates, hcd));
            g.Assert(new Triple(rav08r, has, singleLine));
            g.Assert(new Triple(rav08r, has, multiLine));
            g.Assert(new Triple(rav08r, has, french));
            g.Assert(new Triple(rav08r, has, number));

            //Now print all the Statements
            Console.WriteLine("All Statements");
            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString());
            }

            //Get statements about Rob Vesse
            Console.WriteLine();
            Console.WriteLine("Statements about Rob Vesse");
            foreach (Triple t in g.GetTriples(rav08r))
            {
                Console.WriteLine(t.ToString());
            }

            //Get Statements about Collaboration
            Console.WriteLine();
            Console.WriteLine("Statements about Collaboration");
            foreach (Triple t in g.GetTriples(collaborates))
            {
                Console.WriteLine(t.ToString());
            }

            //Attempt to output Turtle for this Graph
            try
            {
                Console.WriteLine("Writing Turtle file graph_building_example.ttl");
                TurtleWriter ttlwriter = new TurtleWriter();
                ttlwriter.Save(g, "graph_building_example.ttl");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
        /// <summary>
        /// Write a .NET object to an output stream
        /// </summary>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <param name="writeStream"></param>
        /// <param name="content"></param>
        /// <param name="transportContext"></param>
        /// <returns></returns>
        public override Task  WriteToStreamAsync(
            Type type,
            object value,
            Stream writeStream,
            HttpContent content,
            TransportContext transportContext
            )
        {
            return(Task.Factory.StartNew(() =>
            {
                if ((Graph == null) || (Graph.IsEmpty) || RebuildGraph)
                {
                    if (ImplementsGenericType(typeof(FilteredResource <>), type))
                    {
                        PropertyInfo resourceProp = value.GetType().GetProperty("Resource");
                        Type[] actualTypeArguments = GetChildClassParameterArguments(typeof(FilteredResource <>), type);
                        object objects = resourceProp.GetValue(value, null);
                        PropertyInfo propertiesProp = value.GetType().GetProperty("Properties");

                        if (!ImplementsICollection(actualTypeArguments[0]))
                        {
                            objects = new EnumerableWrapper(objects);
                        }

                        if (ImplementsGenericType(typeof(ResponseInfo <>), type))
                        {
                            //Subject URI for the collection is the query capability
                            //TODO:  should this be set by the app based on service provider info
                            int portNum = httpRequest.RequestUri.Port;
                            string portString = null;
                            if (portNum == 80 || portNum == 443)
                            {
                                portString = "";
                            }
                            else
                            {
                                portString = ":" + portNum.ToString();
                            }

                            string descriptionAbout = httpRequest.RequestUri.Scheme + "://" +
                                                      httpRequest.RequestUri.Host +
                                                      portString +
                                                      httpRequest.RequestUri.LocalPath;

                            //Subject URI for the responseInfo is the full request URI
                            string responseInfoAbout = httpRequest.RequestUri.ToString();

                            PropertyInfo totalCountProp = value.GetType().GetProperty("TotalCount");
                            PropertyInfo nextPageProp = value.GetType().GetProperty("NextPage");

                            Graph = DotNetRdfHelper.CreateDotNetRdfGraph(descriptionAbout, responseInfoAbout,
                                                                         (string)nextPageProp.GetValue(value, null),
                                                                         (int)totalCountProp.GetValue(value, null),
                                                                         objects as IEnumerable <object>,
                                                                         (IDictionary <string, object>)propertiesProp.GetValue(value, null));
                        }
                        else
                        {
                            Graph = DotNetRdfHelper.CreateDotNetRdfGraph(null, null, null, null, objects as IEnumerable <object>,
                                                                         (IDictionary <string, object>)propertiesProp.GetValue(value, null));
                        }
                    }
                    else if (InheritedGenericInterfacesHelper.ImplementsGenericInterface(typeof(IEnumerable <>), value.GetType()))
                    {
                        Graph = DotNetRdfHelper.CreateDotNetRdfGraph(value as IEnumerable <object>);
                    }
                    else if (type.GetCustomAttributes(typeof(OslcResourceShape), false).Length > 0)
                    {
                        Graph = DotNetRdfHelper.CreateDotNetRdfGraph(new object[] { value });
                    }
                    else
                    {
                        Graph = DotNetRdfHelper.CreateDotNetRdfGraph(new EnumerableWrapper(value));
                    }
                }

                IRdfWriter rdfWriter;

                if (content == null || content.Headers == null || content.Headers.ContentType.MediaType.Equals(OslcMediaType.APPLICATION_RDF_XML))
                {
                    RdfXmlWriter rdfXmlWriter = new RdfXmlWriter();

                    rdfXmlWriter.UseDtd = false;
                    rdfXmlWriter.PrettyPrintMode = false;
                    rdfXmlWriter.CompressionLevel = 20;
                    //turtlelWriter.UseTypedNodes = false;

                    rdfWriter = rdfXmlWriter;
                }
                else if (content.Headers.ContentType.MediaType.Equals(OslcMediaType.TEXT_TURTLE))
                {
                    TurtleWriter turtlelWriter = new TurtleWriter(TurtleSyntax.W3C);

                    turtlelWriter.PrettyPrintMode = false;

                    rdfWriter = turtlelWriter;
                }
                else
                {
                    //For now, use the dotNetRDF RdfXmlWriter for application/xml
                    //OslcXmlWriter oslcXmlWriter = new OslcXmlWriter();
                    RdfXmlWriter oslcXmlWriter = new RdfXmlWriter();

                    oslcXmlWriter.UseDtd = false;
                    oslcXmlWriter.PrettyPrintMode = false;
                    oslcXmlWriter.CompressionLevel = 20;

                    rdfWriter = oslcXmlWriter;
                }

                StreamWriter streamWriter = new NonClosingStreamWriter(writeStream);

                rdfWriter.Save(Graph, streamWriter);
            }));
        }
Esempio n. 32
-1
		/// <summary>
		/// Starts the export of sensor data values for a particular node. This call must be followed by a call to <see cref="EndExportNode"/>.
		/// Use <see cref="StartExportTimestamp"/> to export node information pertaining to a given point in time to the Sensor Data TURTLE document.
		/// </summary>
		/// <param name="Turtle">TURTLE Output</param>
		/// <param name="NodeId">Node ID.</param>
		/// <param name="CacheType">Cache Type</param> 
		/// <param name="SourceId">Source ID.</param>
		public static void StartExportNode (TurtleWriter Turtle, string NodeId, string CacheType, string SourceId)
		{
			Turtle.WriteSubjectUri ("l", string.Empty);
			Turtle.WritePredicateUri ("cl", "node");
			Turtle.StartBlankNode ();

			Turtle.WritePredicateUri ("cl", "nodeId");
			Turtle.WriteObjectLiteral (NodeId);

			if (!string.IsNullOrEmpty (CacheType))
			{
				Turtle.WritePredicateUri ("cl", "cacheType");
				Turtle.WriteObjectLiteral (CacheType);
			}

			if (!string.IsNullOrEmpty (SourceId))
			{
				Turtle.WritePredicateUri ("cl", "sourceId");
				Turtle.WriteObjectLiteral (SourceId);
			}
		}