示例#1
0
        /// <summary>
        /// Saves the given Triple Store to the SQL Store that this class was instantiated with
        /// </summary>
        /// <param name="store">Store you wish to Save</param>
        /// <param name="parameters">Parameters for the Store</param>
        public virtual void Save(ITripleStore store, IStoreParams parameters)
        {
            if (parameters is ISQLIOParams)
            {
                SqlIOParams writeParams = (SqlIOParams)parameters;
                writeParams.Manager.PreserveState = true;
                SqlWriter writer = new SqlWriter(writeParams.Manager);

                foreach (IGraph g in store.Graphs)
                {
                    writer.Save(g, writeParams.ClearIfExists);
                }
            }
            else
            {
                throw new RdfStorageException("Parameters for the SQLStoreWriter must implement the interface ISQLIOParams");
            }
        }
示例#2
0
        /// <summary>
        /// Saves the given Triple Store to the SQL Store that this class was instantiated with
        /// </summary>
        /// <param name="store">Store you wish to Save</param>
        /// <param name="parameters">Parameters for the Store</param>
        public virtual void Save(ITripleStore store, IStoreParams parameters)
        {
            if (parameters is ISQLIOParams)
            {
                SqlIOParams writeParams = (SqlIOParams)parameters;
                writeParams.Manager.PreserveState = true;
                SqlWriter writer = new SqlWriter(writeParams.Manager);

                foreach (IGraph g in store.Graphs)
                {
                    writer.Save(g, writeParams.ClearIfExists);
                }
            }
            else
            {
                throw new RdfStorageException("Parameters for the SQLStoreWriter must implement the interface ISQLIOParams");
            }
        }
        private void btnImportFile_Click(object sender, EventArgs e)
        {
            if (!this.txtImportFile.Text.Equals(String.Empty))
            {
                try
                {
                    IRdfReader parser = MimeTypesHelper.GetParser(MimeTypesHelper.GetMimeType(Path.GetExtension(this.txtImportFile.Text)));
                    Graph g = new Graph();
                    parser.Load(g, this.txtImportFile.Text);

                    SqlWriter writer = new SqlWriter(this._connection.Manager);
                    writer.Save(g, true);

                    MessageBox.Show("Successfully imported a Graph into the Store", "Import Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.ShowDatabaseInformation();
                }
                catch (RdfParserSelectionException)
                {
                    //Should be an RDF dataset instead?
                    try
                    {
                        //Push into a Background Thread here and show a modal dialog while it's processing
                        Thread importer = new Thread(new ThreadStart(delegate { this.ImportStore(this.txtImportFile.Text); }));
                        fclsPleaseWait wait = new fclsPleaseWait("Import", importer);
                        wait.ShowDialog();

                        this.ShowDatabaseInformation();
                    }
                    catch (RdfParserSelectionException)
                    {
                        MessageBox.Show("Unable to perform an input as the format of the file could not be determined", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (RdfParseException)
                    {
                        MessageBox.Show("Unable to parse RDF Graphs from the selected file as a Parsing Error occurred", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (RdfParseException)
                {
                    MessageBox.Show("Unable to parse an RDF Graph from the selected file as a Parsing Error occurred", "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (RdfStorageException storeEx)
                {
                    MessageBox.Show("Import failed due to the following error:\n" + storeEx.Message, "Import Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#4
0
        public static void Main(string[] args)
        {
            StreamWriter output = new StreamWriter("SQLStoreTest.txt");
            Console.SetOut(output);
            Console.WriteLine("## SQL Store Test");

            //Set default parameters if insufficient supplied
            if (args.Length < 5)
            {
                args = new string[] { "read", "10", "false", "false", "8" };
            }

            try
            {
                //Read in the Parameters
                String testMode = args[0].ToLower();
                if (testMode != "read" && testMode != "write")
                {
                    testMode = "read";
                }
                int runs = Int32.Parse(args[1]);
                if (runs < 1) runs = 1;
                bool reuseManager = Boolean.Parse(args[2]);
                bool useThreadedManager = Boolean.Parse(args[3]);
                int threads = Int32.Parse(args[4]);
                if (threads < 1) threads = 4;

                #region Basic Tests

                //Do some basic operations
                Console.WriteLine("# Basic Read and Write of normal Graphs");

                //Read in a Test Graph from a Turtle File
                Graph g = new Graph();
                g.BaseUri = new Uri("http://www.dotnetrdf.org/Tests/SQLStore/");
                TurtleParser ttlparser = new TurtleParser();
                ttlparser.Load(g, "InferenceTest.ttl");

                Console.WriteLine("Loaded the InferenceTest.ttl file as the Test Graph");
                Console.WriteLine("Attempting to save into the SQL Store");

                //Save to a Store using SqlWriter
                SqlWriter sqlwriter = new SqlWriter("dotnetrdf_experimental", "sa", "20sQl08");
                sqlwriter.Save(g, false);

                Console.WriteLine("Saved to the SQL Store");

                //Read back from the Store using SqlReader
                IGraph h = new Graph();
                Console.WriteLine("Trying to read the Graph back from the SQL Store");
                SqlReader sqlreader = new SqlReader("dotnetrdf_experimental", "sa", "20sQl08");
                h = sqlreader.Load("http://www.dotnetrdf.org/Tests/SQLStore/");

                Console.WriteLine("Read from SQL Store OK");

                foreach (String prefix in h.NamespaceMap.Prefixes)
                {
                    Console.WriteLine(prefix + ": <" + h.NamespaceMap.GetNamespaceUri(prefix).ToString() + ">");
                }
                Console.WriteLine();
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Console.WriteLine("# Test Passed");
                Console.WriteLine();

                //Demonstrate that the SqlGraph persists stuff to the Store
                Console.WriteLine("# Advanced Read and Write with a SQLGraph");

                SqlGraph s = new SqlGraph(new Uri("http://www.dotnetrdf.org/Tests/SQLStore"), "dotnetrdf_experimental", "sa", "20sQl08");
                Console.WriteLine("Opened the SQL Graph OK");

                INode type = s.CreateUriNode("rdf:type");

                s.Assert(new Triple(type, type, type));

                Console.WriteLine("Asserted something");

                s.NamespaceMap.AddNamespace("ex", new Uri("http://www.example.org/"));
                Console.WriteLine("Added a Namespace");

                s.NamespaceMap.AddNamespace("ex", new Uri("http://www.example.org/changedNamespace/"));
                Console.WriteLine("Changed a Namespace");

                Console.WriteLine("Reopening to see if stuff gets loaded correctly");
                s = new SqlGraph(new Uri("http://www.dotnetrdf.org/Tests/SQLStore"), "dotnetrdf_experimental", "sa", "20sQl08");

                foreach (String prefix in s.NamespaceMap.Prefixes)
                {
                    Console.WriteLine(prefix + ": <" + s.NamespaceMap.GetNamespaceUri(prefix).ToString() + ">");
                }
                Console.WriteLine();
                foreach (Triple t in s.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                s.Retract(new Triple(type, type, type));
                Console.WriteLine("Retracted something");

                foreach (Triple t in s.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                #endregion

                #region Benchmarking Tests

                Console.WriteLine();
                Console.WriteLine("# Performance Benchmarking for a Large TripleStore");
                Console.WriteLine("Performing " + runs + " Runs to gauge average performance");

                int totalTriples = 0;
                long totalTime = 0;
                long diff;
                DateTime start, finish;
                int triples;

                if (testMode.Equals("read"))
                {
                    //Read Benchmark
                    Console.WriteLine("Read Benchmarking");

                    if (reuseManager)
                    {
                        Console.WriteLine("Reusing ISQLIOManager which should improve performance");
                    }
                    if (useThreadedManager)
                    {
                        Console.WriteLine("Using IThreadedSQLIOManager which should improve perfomance");
                    }

                    //Create the Manager
                    IThreadedSqlIOManager manager;
                    manager = new MicrosoftSqlStoreManager("localhost", "bbcone", "sa", "20sQl08");
                    if (reuseManager)
                    {
                        manager.PreserveState = true;
                    }

                    //Perform the Runs
                    for (int i = 1; i <= runs; i++)
                    {
                        Console.WriteLine("Run #" + i);
                        Debug.WriteLine("Run #" + i);

                        //Start Profiling
                        start = DateTime.Now;
                        Console.WriteLine("Starting Loading @ " + start.ToString(TestSuite.TestSuiteTimeFormat));
                        Debug.WriteLine("Start @ " + start.ToString(TestSuite.TestSuiteTimeFormat));

                        //Set-up the Manager as required by the Test Options
                        ITripleStore bigstore;
                        if (reuseManager)
                        {
                            if (useThreadedManager)
                            {
                                bigstore = new ThreadedSqlTripleStore((IThreadedSqlIOManager)manager, threads);
                            }
                            else
                            {
                                bigstore = new SqlTripleStore(manager);
                            }
                        }
                        else
                        {
                            if (useThreadedManager)
                            {
                                bigstore = new ThreadedSqlTripleStore(manager, threads);
                            }
                            else
                            {
                                bigstore = new SqlTripleStore(manager);
                            }
                        }

                        //End Profiling
                        finish = DateTime.Now;
                        Console.WriteLine("Finished Loading @ " + finish.ToString(TestSuite.TestSuiteTimeFormat));
                        Debug.WriteLine("Finish @ " + finish.ToString(TestSuite.TestSuiteTimeFormat));

                        //Increment Totals for final average calculations later
                        triples = bigstore.Triples.Count();
                        totalTriples += triples;
                        Console.WriteLine(triples + " Triples loaded");

                        //Compute Load Rate
                        diff = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, start, finish, Microsoft.VisualBasic.FirstDayOfWeek.Monday, Microsoft.VisualBasic.FirstWeekOfYear.System);
                        totalTime += diff;
                        Console.WriteLine("Load took " + diff + " seconds");
                        Console.WriteLine("Load Rate was " + triples / diff + " Triples/Second");
                        Debug.WriteLine("Load Rate was " + triples / diff + " Triples/Second");
                        Console.WriteLine();

                        bigstore.Dispose();
                    }
                }
                else
                {
                    //Write Benchmark
                    Console.WriteLine("Write Benchmarking");

                    //Load in the Source Data from our Test Store
                    ITripleStore origstore;
                    IThreadedSqlIOManager readManager = new MicrosoftSqlStoreManager("localhost", "dotnetrdf_experimental", "sa", "20sQl08");
                    Console.WriteLine();
                    Console.WriteLine("Obtaining Test Data");

                    start = DateTime.Now;
                    Console.WriteLine("Starting Loading @ " + start.ToString(TestSuite.TestSuiteTimeFormat));
                    Debug.WriteLine("Start @ " + start.ToString(TestSuite.TestSuiteTimeFormat));

                    //Do the Load
                    origstore = new ThreadedSqlTripleStore(readManager,8);
                    finish = DateTime.Now;
                    triples = origstore.Triples.Count();

                    Console.WriteLine("Finished Loading @ " + finish.ToString(TestSuite.TestSuiteTimeFormat));
                    Debug.WriteLine("Finish @ " + finish.ToString(TestSuite.TestSuiteTimeFormat));

                    //Compute Load Rate
                    diff = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, start, finish, Microsoft.VisualBasic.FirstDayOfWeek.Monday, Microsoft.VisualBasic.FirstWeekOfYear.System);
                    Console.WriteLine("Load took " + diff + " seconds");
                    if (diff > 0)
                    {
                        Console.WriteLine("Load Rate was " + triples / diff + " Triples/Second");
                        Debug.WriteLine("Load Rate was " + triples / diff + " Triples/Second");
                    }
                    Console.WriteLine();

                    IThreadedSqlIOManager writeManager;

                    for (int i = 1; i <= runs; i++) 
                    {
                        Console.WriteLine("Run #" + i);
                        Debug.WriteLine("Run #" + i);

                        //Create a New Manager for every write
                        writeManager = new MicrosoftSqlStoreManager("localhost", "write_test", "sa", "20sQl08");

                        //Create SqlWriter
                        ThreadedSqlStoreWriter writer = new ThreadedSqlStoreWriter();

                        //Start Profiling
                        start = DateTime.Now;
                        Console.WriteLine("Starting Loading @ " + start.ToString(TestSuite.TestSuiteTimeFormat));
                        Debug.WriteLine("Start @ " + start.ToString(TestSuite.TestSuiteTimeFormat));

                        //Write the Store
                        writer.Save(origstore, new ThreadedSqlIOParams(writeManager,threads));
                        
                        //End Profiling
                        finish = DateTime.Now;
                        Console.WriteLine("Finished Loading @ " + finish.ToString(TestSuite.TestSuiteTimeFormat));
                        Debug.WriteLine("Finish @ " + finish.ToString(TestSuite.TestSuiteTimeFormat));

                        //Compute Load Rate
                        diff = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Second, start, finish, Microsoft.VisualBasic.FirstDayOfWeek.Monday, Microsoft.VisualBasic.FirstWeekOfYear.System);
                        totalTime += diff;
                        Console.WriteLine("Writing took " + diff + " seconds");
                        if (diff > 0)
                        {
                            Console.WriteLine("Write Rate was " + triples / diff + " Triples/Second");
                            Debug.WriteLine("Write Rate was " + triples / diff + " Triples/Second");
                        }
                        Console.WriteLine();

                        //Now need to clear the Database for the next Test
                        writeManager.Open(true);
                        writeManager.ExecuteNonQuery("DELETE FROM NODES");
                        writeManager.ExecuteNonQuery("DELETE FROM TRIPLES");
                        writeManager.ExecuteNonQuery("DELETE FROM GRAPH_TRIPLES");
                        writeManager.ExecuteNonQuery("DELETE FROM GRAPHS");
                        writeManager.ExecuteNonQuery("DELETE FROM NAMESPACES");
                        writeManager.ExecuteNonQuery("DELETE FROM NS_PREFIXES");
                        writeManager.ExecuteNonQuery("DELETE FROM NS_URIS");
                        writeManager.Close(true);
                    }
                }

                //Final Average Calculations
                Console.WriteLine();
                Console.WriteLine("Average Load Time was " + totalTime / runs + " seconds");
                Console.WriteLine("Average Load Rate was " + totalTriples / totalTime + " Triples/Second");

                #endregion

                Console.WriteLine("# Tests Passed");
                

            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                reportError(output, "SQL Exception", sqlEx);
            }
            catch (IOException ioEx)
            {
                reportError(output, "IO Exception", ioEx);
            }
            catch (RdfParseException parseEx)
            {
                reportError(output, "Parsing Exception", parseEx);
            }
            catch (RdfException rdfEx)
            {
                reportError(output, "RDF Exception", rdfEx);
            }
            catch (Exception ex)
            {
                reportError(output, "Other Exception", ex);
            }

            output.Close();
        }
示例#5
0
        public static void Main(String[] args)
        {
            StreamWriter output = new StreamWriter("VirtuosoTest.txt");
            Console.SetOut(output);
            try
            {
                Console.WriteLine("##Virtuoso Test Suite");
                Console.WriteLine();

                //Do some basic operations
                Console.WriteLine("# Basic Read and Write of normal Graphs");

                //Read in a Test Graph from a Turtle File
                Graph g = new Graph();
                g.BaseURI = new Uri("http://www.dotnetrdf.org/Tests/SQLStore/");
                TurtleParser ttlparser = new TurtleParser();
                ttlparser.Load(g, "InferenceTest.ttl");

                Console.WriteLine("Loaded the InferenceTest.ttl file as the Test Graph");
                Console.WriteLine("Attempting to save into the SQL Store");

                //Get the Non Native Virtuoso Manager
                NonNativeVirtuosoManager manager = new NonNativeVirtuosoManager("localhost", 1111, "dotnetrdf_experimental", "dba", "20sQl09");

                //Save to a Store using SqlWriter
                SqlWriter sqlwriter = new SqlWriter(manager);
                sqlwriter.Save(g, false);

                Console.WriteLine("Saved to the SQL Store");

                //Read back from the Store using SqlReader
                Graph h = new Graph();
                Console.WriteLine("Trying to read the Graph back from the SQL Store");
                SqlReader sqlreader = new SqlReader(manager);
                h = sqlreader.Load("http://www.dotnetrdf.org/Tests/SQLStore/");

                Console.WriteLine("Read from SQL Store OK");

                foreach (String prefix in h.NamespaceMap.Prefixes)
                {
                    Console.WriteLine(prefix + ": <" + h.NamespaceMap.GetNamespaceURI(prefix).ToString() + ">");
                }
                Console.WriteLine();
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Console.WriteLine("# Test Passed");
                Console.WriteLine();

                //Demonstrate that the SqlGraph persists stuff to the Store
                Console.WriteLine("# Advanced Read and Write with a SQLGraph");

                SqlGraph s = new SqlGraph(new Uri("http://www.dotnetrdf.org/Tests/SQLStore"), manager);
                Console.WriteLine("Opened the SQL Graph OK");

                INode type = s.CreateURINode("rdf:type");

                s.Assert(new Triple(type, type, type));

                Console.WriteLine("Asserted something");

                s.NamespaceMap.AddNamespace("ex", new Uri("http://www.example.org/"));
                Console.WriteLine("Added a Namespace");

                s.NamespaceMap.AddNamespace("ex", new Uri("http://www.example.org/changedNamespace/"));
                Console.WriteLine("Changed a Namespace");

                Console.WriteLine("Reopening to see if stuff gets loaded correctly");
                s = new SqlGraph(new Uri("http://www.dotnetrdf.org/Tests/SQLStore"), "dotnetrdf_experimental", "sa", "20sQl08");

                foreach (String prefix in s.NamespaceMap.Prefixes)
                {
                    Console.WriteLine(prefix + ": <" + s.NamespaceMap.GetNamespaceURI(prefix).ToString() + ">");
                }
                Console.WriteLine();
                foreach (Triple t in s.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                s.Retract(new Triple(type, type, type));
                Console.WriteLine("Retracted something");

                foreach (Triple t in s.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
            }
            catch (OpenLink.Data.Virtuoso.VirtuosoException virtEx)
            {
                reportError(output, "Virtuoso Exception", virtEx);
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                reportError(output, "SQL Exception", sqlEx);
            }
            catch (IOException ioEx)
            {
                reportError(output, "IO Exception", ioEx);
            }
            catch (RDFParseException parseEx)
            {
                reportError(output, "Parsing Exception", parseEx);
            }
            catch (RDFException rdfEx)
            {
                reportError(output, "RDF Exception", rdfEx);
            }
            catch (Exception ex)
            {
                reportError(output, "Other Exception", ex);
            }
            finally
            {
                output.Close();
            }
        }
示例#6
0
        /// <summary>
        /// Internal Worker method for Writer Threads
        /// </summary>
        private void WriteGraphs(ThreadedSqlStoreWriterContext context)
        {
            try
            {
                int thread = Thread.CurrentThread.ManagedThreadId;
                SqlWriter writer = new SqlWriter(context.Manager);

                IGraph g = context.GetNextGraph();
                while (g != null)
                {
                    //Write the Graph to the Target Store
                    writer.Save(g, context.ClearIfExists);

                    //Get Next Graph
                    g = context.GetNextGraph();
                } 
            }
            catch (ThreadAbortException)
            {
                //We've been terminated, don't do anything
                Thread.ResetAbort();
            }
            catch (Exception ex)
            {
                throw new RdfStorageException("Error in Threaded Writer in Thread ID " + Thread.CurrentThread.ManagedThreadId, ex);
            }
        }