private void TestDumpStorePrimed(IStorageProvider manager)
        {
            this.EnsureTestDataset(manager);

            PersistentTripleStore store = new PersistentTripleStore(manager);

            try
            {
                // First prime the persistent store by loading a bunch of stuff
                Assert.True(store.HasGraph(new Uri(TestGraphUri1)), "URI 1 should return true for HasGraph()");
                Assert.True(store.Graphs.Contains(new Uri(TestGraphUri1)), "URI 1 should return true for Graphs.Contains()");
                Assert.True(store.HasGraph(new Uri(TestGraphUri2)), "URI 2 should return true for HasGraph()");
                Assert.True(store.Graphs.Contains(new Uri(TestGraphUri2)), "URI 2 should return true for Graphs.Contains()");
                Assert.True(store.HasGraph(new Uri(TestGraphUri3)), "URI 3 should return true for HasGraph()");
                Assert.True(store.Graphs.Contains(new Uri(TestGraphUri3)), "URI 3 should return true for Graphs.Contains()");

                Uri noSuchThing = new Uri("http://example.org/persistence/graphs/noSuchGraph");
                Assert.False(store.HasGraph(noSuchThing), "Bad URI should return false for HasGraph()");
                Assert.False(store.Graphs.Contains(noSuchThing), "Bad URI should return false for Graphs.Contains()");

                // Then try and dump
                StringWriter strWriter = new StringWriter();
                TriGWriter   writer    = new TriGWriter();
                writer.UseMultiThreadedWriting = false;

                writer.Save(store, strWriter);
                Console.WriteLine("TriG output:");
                Console.WriteLine(strWriter.ToString());
                Assert.False(String.IsNullOrEmpty(strWriter.ToString()));
            }
            finally
            {
                store.Dispose();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Write a graph containing the ontology to a file
 /// </summary>
 /// <param name="filename">File to write the ontology to</param>
 public static void WriteOntology(string filename)
 {
     using (TripleStore store = new TripleStore())
         using (IGraph g = new Graph())
         {
             AssertOntologyTriples(g);
             g.BaseUri = Ontology.ContextUri;
             store.Add(g);
             TriGWriter writer = new TriGWriter();
             writer.PrettyPrintMode = true;
             writer.Save(store, filename);
         }
 }
        private void TestDumpStoreEmpty(IStorageProvider manager)
        {
            this.EnsureTestDataset(manager);

            PersistentTripleStore store = new PersistentTripleStore(manager);

            try
            {
                // Try and dump
                StringWriter strWriter = new StringWriter();
                TriGWriter   writer    = new TriGWriter();
                writer.UseMultiThreadedWriting = false;

                writer.Save(store, strWriter);
                Console.WriteLine("TriG output:");
                Console.WriteLine(strWriter.ToString());
                Assert.True(String.IsNullOrEmpty(strWriter.ToString()));
            }
            finally
            {
                store.Dispose();
            }
        }
Exemplo n.º 4
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();
            }
        }