public fclsGraphBrowser()
        {
            InitializeComponent();

            //Connect to Virtuoso
            this._manager = new VirtuosoManager(Properties.Settings.Default.Server, Properties.Settings.Default.Port, VirtuosoQuadStoreDB, Properties.Settings.Default.Username, Properties.Settings.Default.Password);

            //Add some fake test data
            DataTable data = new DataTable();
            data.Columns.Add("Subject");
            data.Columns.Add("Predicate");
            data.Columns.Add("Object");
            data.Columns["Subject"].DataType = typeof(INode);
            data.Columns["Predicate"].DataType = typeof(INode);
            data.Columns["Object"].DataType = typeof(INode);

            Graph g = new Graph();
            DataRow row = data.NewRow();
            row["Subject"] = g.CreateUriNode(new Uri("http://example.org/subject"));
            row["Predicate"] = g.CreateUriNode(new Uri("http://example.org/predicate"));
            row["Object"] = g.CreateUriNode(new Uri("http://example.org/object"));
            data.Rows.Add(row);

            this.BindGraph(data);
        }
        public void InteropSesameContextsForVirtuoso()
        {
            VirtuosoManager virtuoso = new VirtuosoManager("DB", "dba", "dba");

            DotNetRdfGenericRepository repo = new DotNetRdfGenericRepository(virtuoso);

            dotSesameRepo.RepositoryConnection conn = repo.getConnection();

            dotSesameRepo.RepositoryResult result = conn.getContextIDs();
            while (result.hasNext())
            {
                dotSesame.Resource r = result.next() as dotSesame.Resource;
                Assert.IsTrue(r != null, "Should not be null");
                Console.WriteLine(r.ToString());
            }
        }
        public void InteropSesameLoadFromVirtuoso()
        {
            VirtuosoManager virtuoso = new VirtuosoManager("DB", "dba", "dba");

            DotNetRdfGenericRepository repo = new DotNetRdfGenericRepository(virtuoso);

            dotSesameRepo.RepositoryConnection conn = repo.getConnection();

            dotSesame.Resource[] contexts = new dotSesame.Resource[] { repo.getValueFactory().createURI("http://localhost/TurtleImportTest") };

            dotSesameRepo.RepositoryResult result = conn.getStatements(null, null, null, true, contexts);
            while (result.hasNext())
            {
                dotSesame.Statement r = result.next() as dotSesame.Statement;
                Assert.IsTrue(r != null, "Should not be null");
                Console.WriteLine(r.ToString());
            }
        }
示例#4
0
        public void StorageVirtuosoNativeQuery()
        {
            NTriplesFormatter formatter = new NTriplesFormatter();
            try
            {
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                Object result = null;

                Console.WriteLine("ASKing if there's any Triples");

                //Try an ASK query
                result = manager.Query("ASK {?s ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("CONSTRUCTing a Graph");

                //Try a CONSTRUCT
                result = manager.Query("CONSTRUCT {?s ?p ?o} FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, false);

                Console.WriteLine("SELECTing the same Graph");

                //Try a SELECT query
                result = manager.Query("SELECT * FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("SELECTing the same Graph using Project Expressions");

                //Try a SELECT query
                result = manager.Query("SELECT (?s AS ?Subject) (?P as ?Predicate) (?o AS ?Object) FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("Now we'll delete a Triple");

                //Try a DELETE DATA
                result = manager.Query("DELETE DATA FROM <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}");
                CheckQueryResult(result, true);

                Console.WriteLine("Triple with subject <http://example.org/seven> should be missing - ASKing for it...");

                //Try a SELECT query
                result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("Now we'll add the Triple back again");

                //Try a INSERT DATA
                result = manager.Query("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}");
                CheckQueryResult(result, true);

                Console.WriteLine("Triple with subject <http://example.org/seven> should be restored - ASKing for it again...");

                //Try a SELECT query
                result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("DESCRIBE things which are classes");

                //Try a DESCRIBE
                result = manager.Query("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> DESCRIBE ?s WHERE {?s a rdfs:Class} LIMIT 1");
                CheckQueryResult(result, false);

                Console.WriteLine("Another CONSTRUCT");

                //Try a CONSTRUCT
                result = manager.Query("CONSTRUCT {?s ?p ?o} FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, false);

                Console.WriteLine("COUNT subjects");

                //Try a SELECT using an aggregate function
                result = manager.Query("SELECT COUNT(?s) FROM <http://example.org/> WHERE {?s ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("AVG integer objects");
               
                //Try another SELECT using an aggregate function
                result = manager.Query("SELECT AVG(?o) FROM <http://example.org/> WHERE {?s ?p ?o. FILTER(DATATYPE(?o) = <http://www.w3.org/2001/XMLSchema#integer>)}");
                CheckQueryResult(result, true);

                Console.WriteLine("AVG decimal objects");

                //Try yet another SELECT using an aggregate function
                result = manager.Query("SELECT AVG(?o) FROM <http://example.org/> WHERE {?s ?p ?o. FILTER(DATATYPE(?o) = <http://www.w3c.org/2001/XMLSchema#decimal>)}");
                CheckQueryResult(result, true);
            }
            catch (RdfQueryException queryEx)
            {
                TestTools.ReportError("RDF Query Error", queryEx, true);
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
示例#5
0
        public void StorageVirtuosoUpdateGraph()
        {
            try
            {
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                //Make some Triples to add to the Graph
                Graph g = new Graph();
                g.BaseUri = new Uri("http://example.org/");
                List<Triple> additions = new List<Triple>();
                additions.Add(new Triple(g.CreateUriNode(":seven"), g.CreateUriNode("rdf:type"), g.CreateUriNode(":addedTriple")));
                List<Triple> removals = new List<Triple>();
                removals.Add(new Triple(g.CreateUriNode(":five"), g.CreateUriNode(":property"), g.CreateUriNode(":value")));

                //Try to Update
                manager.UpdateGraph(g.BaseUri, additions, removals);

                Console.WriteLine("Updated OK");

                //Retrieve to see what's in the Graph
                Graph h = new Graph();
                manager.LoadGraph(h, g.BaseUri);

                Console.WriteLine("Retrieved OK");
                Console.WriteLine("Graph contents are:");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                Assert.IsTrue(h.Triples.Contains(additions[0]), "Added Triple should be in the retrieved Graph");
                Assert.IsFalse(h.Triples.Contains(removals[0]), "Removed Triple should not be in the retrieved Graph");
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
示例#6
0
        /// <summary>
        /// Tests retrieving the Default Graph
        /// </summary>
        /// <remarks>Excluded from Unit Tests because while this works it takes an extremely long time since the Default Graph will potentially have a very large number of Triples and the Virtuoso Manager only reads in a single threaded manner</remarks>
        //[TestMethod]
        public void StorageVirtuosoDefaultGraph()
        {
            Stopwatch timer = new Stopwatch();
            try
            {                
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                //Try to get the Default Graph
                Graph g = new Graph();
                timer.Start();
                manager.LoadGraph(g, (Uri)null);
                timer.Stop();

                Console.WriteLine();
                Console.WriteLine("Default Graph Contains:");
                foreach (Triple t in g.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();
            }
            catch (VirtuosoException virtEx)
            {
                timer.Stop();
                Console.WriteLine(timer.ElapsedMilliseconds + "ms Elapsed");
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                timer.Stop();
                Console.WriteLine(timer.ElapsedMilliseconds + "ms Elapsed");
                TestTools.ReportError("Other Error", ex, true);
            }
        }
示例#7
0
        public void StorageVirtuosoBlankNodePersistence()
        {
            try
            {
                //Create our Test Graph
                Graph g = new Graph();
                g.BaseUri = new Uri("http://example.org/bnodes/");

                IBlankNode b = g.CreateBlankNode("blank");
                IUriNode rdfType = g.CreateUriNode("rdf:type");
                IUriNode bnode = g.CreateUriNode(":BlankNode");

                g.Assert(new Triple(b, rdfType, bnode));

                Assert.AreEqual(1, g.Triples.Count, "Should only be 1 Triple in the Test Graph");

                //Connect to Virtuoso
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);

                //Save Graph
                manager.SaveGraph(g);

                //Retrieve
                Graph h = new Graph();
                Graph i = new Graph();
                manager.LoadGraph(h, g.BaseUri);
                manager.LoadGraph(i, g.BaseUri);

                Assert.AreEqual(1, h.Triples.Count, "Retrieved Graph should only contain 1 Triple");
                Assert.AreEqual(1, i.Triples.Count, "Retrieved Graph should only contain 1 Triple");

                Console.WriteLine("Contents of Retrieved Graph:");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                TestTools.CompareGraphs(h, i, true);

                //Save back again
                manager.SaveGraph(h);

                //Retrieve again
                Graph j = new Graph();
                manager.LoadGraph(j, g.BaseUri);

                Console.WriteLine("Contents of Retrieved Graph (Retrieved after saving original Retrieval):");
                foreach (Triple t in j.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                TestTools.CompareGraphs(h, j, false);
                TestTools.CompareGraphs(i, j, false);

                //Save back yet again
                manager.SaveGraph(j);

                //Retrieve yet again
                Graph k = new Graph();
                manager.LoadGraph(k, g.BaseUri);

                Console.WriteLine("Contents of Retrieved Graph (Retrieved after saving second Retrieval):");
                foreach (Triple t in k.Triples)
                {
                    Console.WriteLine(t.ToString());
                }
                Console.WriteLine();

                TestTools.CompareGraphs(j, k, false);
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
        /// <summary>
        /// Attempts to load an Object of the given type identified by the given Node and returned as the Type that this loader generates
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        /// <param name="targetType">Target Type</param>
        /// <param name="obj">Created Object</param>
        /// <returns>True if the loader succeeded in creating an Object</returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            obj = null;

            String server, port, db, user, pwd;
            int p = -1;

            //Create the URI Nodes we're going to use to search for things
            INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer),
                  propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase);

            //Get Server and Database details
            server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
            if (server == null) server = "localhost";
            db = ConfigurationLoader.GetConfigurationString(g, objNode, propDb);
            if (db == null) db = VirtuosoManager.DefaultDB;

            //Get Port
            port = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPort));
            if (!Int32.TryParse(port, out p)) p = VirtuosoManager.DefaultPort;

            //Get user credentials
            ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
            if (user == null || pwd == null) return false;

            //Based on this information create a Manager if possible
            switch (targetType.FullName)
            {
                case NonNativeVirtuosoManager:
                    obj = new NonNativeVirtuosoManager(server, p, db, user, pwd);
                    break;

                case Virtuoso:
                    //Get Server settings
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;

                    obj = new VirtuosoManager(server, p, db, user, pwd);

                    break;
            }

            return (obj != null);
        }
示例#9
0
 /// <summary>
 /// starts connection with the server
 /// </summary>
 public static void startConnection()
 {
     //Initiating the manager(to be added to constructor?)
     if (!isConnectionStarted)
     {
         manager = new VirtuosoManager("Server=192.168.33.2;Uid=dba;pwd=dba;Connection Timeout=500");
         isConnectionStarted = true;
     }
 }
示例#10
0
        public void StorageVirtuosoSaveGraph()
        {
            NTriplesFormatter formatter = new NTriplesFormatter();
            try
            {
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                //Load in our Test Graph
                TurtleParser ttlparser = new TurtleParser();
                Graph g = new Graph();
                ttlparser.Load(g, "Turtle.ttl");

                Console.WriteLine();
                Console.WriteLine("Loaded Test Graph OK");
                Console.WriteLine("Test Graph contains:");

                Assert.IsFalse(g.IsEmpty, "Test Graph should be non-empty");

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

                //Try to save to Virtuoso
                manager.SaveGraph(g);
                Console.WriteLine("Saved OK");
                Console.WriteLine();

                //Try to retrieve
                Graph h = new Graph();
                manager.LoadGraph(h, "http://example.org");

                Assert.IsFalse(h.IsEmpty, "Retrieved Graph should be non-empty");

                Console.WriteLine("Retrieved the Graph from Virtuoso OK");
                Console.WriteLine("Retrieved Graph contains:");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString(formatter));
                }

                Assert.AreEqual(g.Triples.Count, h.Triples.Count, "Graph should have same number of Triples before and after saving");

                GraphDiffReport diff = h.Difference(g);

                Console.WriteLine();
                if (!diff.AreEqual)
                {
                    Console.WriteLine("Some Differences in Graphs detected (should only be due to Virtuoso not running xsd:boolean as true/false");
                    Console.WriteLine();

                    TestTools.ShowDifferences(diff);

                    IUriNode allowedDiffSubject = g.CreateUriNode(":four");
                    IUriNode allowedDiffSubject2 = g.CreateUriNode(":six");
                    Assert.IsTrue(diff.RemovedTriples.All(t => t.Subject.Equals(allowedDiffSubject2) || (t.Subject.Equals(allowedDiffSubject) && (t.Object.ToString().Equals("true^^" + XmlSpecsHelper.XmlSchemaDataTypeBoolean) || t.Object.ToString().Equals("false^^" + XmlSpecsHelper.XmlSchemaDataTypeBoolean)))), "Removed Triples should only be those with subject :four and boolean object");
                    Assert.IsTrue(diff.AddedTriples.All(t => t.Subject.Equals(allowedDiffSubject2) || (t.Subject.Equals(allowedDiffSubject) && (t.Object.ToString().Equals("1") || t.Object.ToString().Equals("0")))), "Added Triples should only be those with subject :four and 1/0 in place of boolean object");
                }
                else
                {
                    Console.WriteLine("Graphs are equal");
                }
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
 /// <summary>
 /// Creates a new instance of a Virtuoso Triple Store which uses the given <see cref="VirtuosoManager">VirtuosoManager</see> to connect to a Virtuoso Triple Store
 /// </summary>
 /// <param name="manager">Manager for the connection to Virtuoso</param>
 public VirtuosoTripleStore(VirtuosoManager manager)
     : base(new GraphCollection())
 {
     this._manager = manager;
 }
        /// <summary>
        /// Tries to load a Generic IO Manager based on information from the Configuration Graph
        /// </summary>
        /// <param name="g">Configuration Graph</param>
        /// <param name="objNode">Object Node</param>
        /// <param name="targetType">Target Type</param>
        /// <param name="obj">Output Object</param>
        /// <returns></returns>
        public bool TryLoadObject(IGraph g, INode objNode, Type targetType, out object obj)
        {
            IGenericIOManager manager = null;
            obj = null;

            String server, user, pwd, store;
            bool async;

            Object temp;
            INode storeObj;

            //Create the URI Nodes we're going to use to search for things
            INode propServer = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyServer),
                  propDb = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDatabase),
                  propStore = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyStore),
                  propAsync = ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyAsync);

            switch (targetType.FullName)
            {
                case AllegroGraph:
                    //Get the Server, Catalog and Store
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    String catalog = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog));
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;

                    //Get User Credentials
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                    if (user != null && pwd != null)
                    {
                        manager = new AllegroGraphConnector(server, catalog, store, user, pwd);
                    }
                    else
                    {
                        manager = new AllegroGraphConnector(server, catalog, store);
                    }
                    break;

                case DatasetFile:
                    //Get the Filename and whether the loading should be done asynchronously
                    String file = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyFromFile));
                    if (file == null) return false;
                    file = ConfigurationLoader.ResolvePath(file);
                    async = ConfigurationLoader.GetConfigurationBoolean(g, objNode, propAsync, false);
                    manager = new DatasetFileManager(file, async);
                    break;

                case Dydra:
                    //Get the Account Name and Store
                    String account = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyCatalog));
                    if (account == null) return false;
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;

                    //Get User Credentials
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                    if (user != null)
                    {
                        manager = new DydraConnector(account, store, user);
                    }
                    else
                    {
                        manager = new DydraConnector(account, store);
                    }
                    break;

                case FourStore:
                    //Get the Server and whether Updates are enabled
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    bool enableUpdates = ConfigurationLoader.GetConfigurationBoolean(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEnableUpdates), true);
                    manager = new FourStoreConnector(server, enableUpdates);
                    break;

                case Fuseki:
                    //Get the Server URI
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    manager = new FusekiConnector(server);
                    break;

                case InMemory:
                    //Get the Dataset/Store
                    INode datasetObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingDataset));
                    if (datasetObj != null)
                    {
                        temp = ConfigurationLoader.LoadObject(g, datasetObj);
                        if (temp is ISparqlDataset)
                        {
                            manager = new InMemoryManager((ISparqlDataset)temp);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingDataset property points to an Object that cannot be loaded as an object which implements the ISparqlDataset interface");
                        }
                    }
                    else
                    {
                        //If no dnr:usingDataset try dnr:usingStore instead
                        storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUsingStore));
                        if (storeObj != null)
                        {
                            temp = ConfigurationLoader.LoadObject(g, storeObj);
                            if (temp is IInMemoryQueryableStore)
                            {
                                manager = new InMemoryManager((IInMemoryQueryableStore)temp);
                            }
                            else
                            {
                                throw new DotNetRdfConfigurationException("Unable to load the In-Memory Manager identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:usingStore property points to an Object that cannot be loaded as an object which implements the IInMemoryQueryableStore interface");
                            }
                        }
                        else
                        {
                            //If no dnr:usingStore either then create a new empty store
                            manager = new InMemoryManager();
                        }
                    }
                    break;

                case Joseki:
                    //Get the Query and Update URIs
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    String queryService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyQueryPath));
                    if (queryService == null) return false;
                    String updateService = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyUpdatePath));
                    if (updateService == null)
                    {
                        manager = new JosekiConnector(server, queryService);
                    }
                    else
                    {
                        manager = new JosekiConnector(server, queryService, updateService);
                    }
                    break;

                case ReadOnly:
                    //Get the actual Manager we are wrapping
                    storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager));
                    temp = ConfigurationLoader.LoadObject(g, storeObj);
                    if (temp is IGenericIOManager)
                    {
                        manager = new ReadOnlyConnector((IGenericIOManager)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IGenericIOManager interface");
                    }
                    break;

                case ReadOnlyQueryable:
                    //Get the actual Manager we are wrapping
                    storeObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyGenericManager));
                    temp = ConfigurationLoader.LoadObject(g, storeObj);
                    if (temp is IQueryableGenericIOManager)
                    {
                        manager = new QueryableReadOnlyConnector((IQueryableGenericIOManager)temp);
                    }
                    else
                    {
                        throw new DotNetRdfConfigurationException("Unable to load the Queryable Read-Only Connector identified by the Node '" + objNode.ToString() + "' as the value given for the dnr:genericManager property points to an Object which cannot be loaded as an object which implements the required IQueryableGenericIOManager interface");
                    }
                    break;

                case Sesame:
                    //Get the Server and Store ID
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
                    if (user != null && pwd != null)
                    {
                        manager = new SesameHttpProtocolConnector(server, store, user, pwd);
                    }
                    else
                    {
                        manager = new SesameHttpProtocolConnector(server, store);
                    }
                    break;

                case Sparql:
                    //Get the Endpoint URI or the Endpoint
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpointUri));

                    //What's the load mode?
                    String loadModeRaw = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyLoadMode));
                    SparqlConnectorLoadMethod loadMode = SparqlConnectorLoadMethod.Construct;
                    if (loadModeRaw != null)
                    {
                        try
                        {
#if SILVERLIGHT
                            loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw, false);
#else
                            loadMode = (SparqlConnectorLoadMethod)Enum.Parse(typeof(SparqlConnectorLoadMethod), loadModeRaw);
#endif
                        }
                        catch
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:loadMode is not valid");
                        }
                    }

                    if (server == null)
                    {
                        INode endpointObj = ConfigurationLoader.GetConfigurationNode(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyEndpoint));
                        if (endpointObj == null) return false;
                        temp = ConfigurationLoader.LoadObject(g, endpointObj);
                        if (temp is SparqlRemoteEndpoint)
                        {
                            manager = new SparqlConnector((SparqlRemoteEndpoint)temp, loadMode);
                        }
                        else
                        {
                            throw new DotNetRdfConfigurationException("Unable to load the SparqlConnector identified by the Node '" + objNode.ToString() + "' as the value given for the property dnr:endpoint points to an Object which cannot be loaded as an object which is of the type SparqlRemoteEndpoint");
                        }
                    }
                    else
                    {
                        //Are there any Named/Default Graph URIs
                        IEnumerable<Uri> defGraphs = from def in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyDefaultGraphUri))
                                                     where def.NodeType == NodeType.Uri
                                                     select ((IUriNode)def).Uri;
                        IEnumerable<Uri> namedGraphs = from named in ConfigurationLoader.GetConfigurationData(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyNamedGraphUri))
                                                       where named.NodeType == NodeType.Uri
                                                       select ((IUriNode)named).Uri;
                        if (defGraphs.Any() || namedGraphs.Any())
                        {
                            manager = new SparqlConnector(new SparqlRemoteEndpoint(new Uri(server), defGraphs, namedGraphs), loadMode);
                        }
                        else
                        {
                            manager = new SparqlConnector(new Uri(server), loadMode);
                        }                        
                    }
                    break;

                case SparqlHttpProtocol:
                    //Get the Service URI
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    manager = new SparqlHttpProtocolConnector(new Uri(server));
                    break;

                case Stardog:
                    //Get the Server and Store
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;

                    //Get User Credentials
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);

                    if (user != null && pwd != null)
                    {
                        manager = new StardogConnector(server, store, user, pwd);
                    }
                    else
                    {
                        manager = new StardogConnector(server, store);
                    }
                    break;

                case Talis:
                    //Get the Store Name and User credentials
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) return false;
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
                    if (user != null && pwd != null)
                    {
                        manager = new TalisPlatformConnector(store, user, pwd);
                    }
                    else
                    {
                        manager = new TalisPlatformConnector(store);
                    }
                    break;

#if !NO_DATA
                case Virtuoso:
                    //Get Server settings
                    server = ConfigurationLoader.GetConfigurationString(g, objNode, propServer);
                    if (server == null) return false;
                    String port = ConfigurationLoader.GetConfigurationString(g, objNode, ConfigurationLoader.CreateConfigurationNode(g, ConfigurationLoader.PropertyPort));
                    store = ConfigurationLoader.GetConfigurationString(g, objNode, propStore);
                    if (store == null) store = VirtuosoManager.DefaultDB;

                    //Get User Credentials
                    ConfigurationLoader.GetUsernameAndPassword(g, objNode, true, out user, out pwd);
                    if (user == null || pwd == null) return false;

                    if (port != null)
                    {
                        int p = -1;
                        if (Int32.TryParse(port, out p))
                        {
                            manager = new VirtuosoManager(server, p, store, user, pwd);
                        }
                        else
                        {
                            return false;
                        }
                    }
                    else
                    {
                        manager = new VirtuosoManager(server, VirtuosoManager.DefaultPort, store, user, pwd);
                    }

                    break;
#endif
            }

            obj = manager;
            return (manager != null);
        }
 public void ParsingWriteToStoreHandlerBNodesAcrossBatchesVirtuoso()
 {
     VirtuosoManager virtuoso = new VirtuosoManager("DB", "dba", "dba");
     this.TestWriteToStoreHandlerWithBNodes(virtuoso);
 }
 public void ParsingWriteToStoreHandlerDatasetsVirtuoso()
 {
     VirtuosoManager virtuoso = new VirtuosoManager("DB", "dba", "dba");
     this.TestWriteToStoreDatasetsHandler(virtuoso);
 }
示例#15
0
        /// <summary>
        /// starts connection with the server
        /// </summary>
        public static void startConnection()
        {
            //Read from the config file.
            StreamReader sr = new StreamReader("VirtuosoConnectionParameters.txt");

            //Initiating the manager(to be added to constructor?)
            if (!isConnectionStarted)
            {
                //manager = new VirtuosoManager("Server=localhost;Uid=dba;pwd=dba;Connection Timeout=500");
                //manager = new VirtuosoManager("localhost", 1111, "DB", "dba", "dba");
                manager = new VirtuosoManager(sr.ReadLine(), int.Parse(sr.ReadLine()), sr.ReadLine(), sr.ReadLine(), sr.ReadLine());
                isConnectionStarted = true;
            }
        }
示例#16
0
        public void StorageVirtuosoNativeUpdate()
        {
            try
            {
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                Object result = null;
                Console.WriteLine("Now we'll delete a Triple");

                //Try a DELETE DATA
                manager.Update("DELETE DATA FROM <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}");

                Console.WriteLine("Triple with subject <http://example.org/seven> should be missing - ASKing for it...");

                //Try a SELECT query
                result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}");
                CheckQueryResult(result, true);

                Console.WriteLine("Now we'll add the Triple back again");

                //Try a INSERT DATA
                manager.Update("INSERT DATA INTO <http://example.org/> { <http://example.org/seven> <http://example.org/property> \"extra triple\".}");

                Console.WriteLine("Triple with subject <http://example.org/seven> should be restored - ASKing for it again...");

                //Try a SELECT query
                result = manager.Query("ASK FROM <http://example.org/> WHERE {<http://example.org/seven> ?p ?o}");
                CheckQueryResult(result, true);
            }
            catch (RdfQueryException queryEx)
            {
                TestTools.ReportError("RDF Query Error", queryEx, true);
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
示例#17
0
        public void StorageVirtuosoEncoding()
        {
            //Get the Virtuoso Manager
            VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);

            //Make the Test Graph
            Graph g = new Graph();
            g.BaseUri = new Uri("http://example.org/VirtuosoEncodingTest");
            IUriNode encodedString = g.CreateUriNode(new Uri("http://example.org/encodedString"));
            ILiteralNode encodedText = g.CreateLiteralNode("William Jørgensen");
            g.Assert(new Triple(g.CreateUriNode(), encodedString, encodedText));

            Console.WriteLine("Test Graph created OK");
            TestTools.ShowGraph(g);

            //Save to Virtuoso
            Console.WriteLine();
            Console.WriteLine("Saving to Virtuoso");
            manager.SaveGraph(g);

            //Load back from Virtuoso
            Console.WriteLine();
            Console.WriteLine("Retrieving from Virtuoso");
            Graph h = new Graph();
            manager.LoadGraph(h, new Uri("http://example.org/VirtuosoEncodingTest"));
            TestTools.ShowGraph(h);

            Assert.AreEqual(g, h, "Graphs should be equal");
        }
示例#18
0
        public void StorageVirtuosoDataTypes()
        {
            VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
            Assert.IsNotNull(manager);

            NTriplesFormatter formatter = new NTriplesFormatter();

            //Try to retrieve
            Graph g = new Graph();
            manager.LoadGraph(g, "http://localhost/TurtleImportTest");

            Assert.IsFalse(g.IsEmpty, "Retrieved Graph should be non-empty");

            Console.WriteLine("Retrieved the Graph from Virtuoso OK");
            Console.WriteLine("Retrieved Graph contains:");
            foreach (Triple t in g.Triples)
            {
                Console.WriteLine(t.ToString(formatter));
            }
        }
示例#19
0
 /// <summary>
 /// Creates a new instance of the Virtuoso Reader which connects to a Virtuoso Native Quad Store using the given Manager
 /// </summary>
 /// <param name="manager">Manager for the connection to Virtuoso</param>
 public VirtuosoReader(VirtuosoManager manager)
 {
     this._manager = manager;
 }
示例#20
0
        public void StorageVirtuosoDeleteGraph()
        {
            try
            {
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                //Load in our Test Graph
                TurtleParser ttlparser = new TurtleParser();
                Graph g = new Graph();
                ttlparser.Load(g, "Turtle.ttl");
                g.BaseUri = new Uri("http://example.org/deleteMe");

                Console.WriteLine();
                Console.WriteLine("Loaded Test Graph OK");
                Console.WriteLine("Test Graph contains:");

                Assert.IsFalse(g.IsEmpty, "Test Graph should be non-empty");

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

                //Try to save to Virtuoso
                manager.SaveGraph(g);
                Console.WriteLine("Saved OK");
                Console.WriteLine();

                //Try to retrieve
                Graph h = new Graph();
                manager.LoadGraph(h, "http://example.org/deleteMe");

                Assert.IsFalse(h.IsEmpty, "Retrieved Graph should be non-empty");

                Console.WriteLine("Retrieved the Graph from Virtuoso OK");
                Console.WriteLine("Retrieved Graph contains:");
                foreach (Triple t in h.Triples)
                {
                    Console.WriteLine(t.ToString());
                }

                //Try to delete
                manager.DeleteGraph("http://example.org/deleteMe");
                Graph i = new Graph();
                manager.LoadGraph(i, "http://example.org/deleteMe");

                Assert.IsTrue(i.IsEmpty, "Retrieved Graph should be empty as it should have been deleted from the Store");
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }
示例#21
0
        /// <summary>
        /// starts connection with the server
        /// </summary>
        public static void startConnection()
        {
            //Initiating the manager(to be added to constructor?)
            if (!isConnectionStarted)
            {
                //manager = new VirtuosoManager("Server=localhost;Uid=dba;pwd=dba;Connection Timeout=500");

                manager = new VirtuosoManager("localhost", 1111, "DB", "dba", "dba");
                isConnectionStarted = true;
            }
        }
示例#22
0
        public void StorageVirtuosoLoadGraph()
        {
            NTriplesFormatter formatter = new NTriplesFormatter();
            try
            {
                VirtuosoManager manager = new VirtuosoManager("DB", VirtuosoTestUsername, VirtuosoTestPassword);
                Assert.IsNotNull(manager);

                Console.WriteLine("Got the Virtuoso Manager OK");

                //Add the Test Date to Virtuoso
                Graph testData = new Graph();
                FileLoader.Load(testData, "MergePart1.ttl");
                testData.BaseUri = new Uri("http://localhost/VirtuosoTest");
                manager.SaveGraph(testData);
                testData = new Graph();
                FileLoader.Load(testData, "Turtle.ttl");
                testData.BaseUri = new Uri("http://localhost/TurtleImportTest");
                manager.SaveGraph(testData);
                Console.WriteLine("Saved the Test Data to Virtuoso");

                //Try loading it back again
                Graph g = new Graph();
                manager.LoadGraph(g, "http://localhost/VirtuosoTest");

                Console.WriteLine("Load Operation completed without errors");

                Assert.AreNotEqual(0, g.Triples.Count);

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

                Console.WriteLine();
                Console.WriteLine("Loading a larger Graph");
                Graph h = new Graph();
                manager.LoadGraph(h, "http://localhost/TurtleImportTest");

                Console.WriteLine("Load operation completed without errors");

                Assert.AreNotEqual(0, h.Triples.Count);

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

                Console.WriteLine();
                Console.WriteLine("Loading same Graph again to ensure loading is repeatable");
                Graph i = new Graph();
                manager.LoadGraph(i, "http://localhost/TurtleImportTest");

                Console.WriteLine("Load operation completed without errors");

                Assert.AreEqual(h.Triples.Count, i.Triples.Count);
                Assert.AreEqual(h, i);
            }
            catch (VirtuosoException virtEx)
            {
                TestTools.ReportError("Virtuoso Error", virtEx, true);
            }
            catch (Exception ex)
            {
                TestTools.ReportError("Other Error", ex, true);
            }
        }