/// <summary>
        /// Dont have Parents :'( (Y/N)
        /// </summary>
        /// <returns></returns>
        private List <Entity> SelectMaster(SparqlUtilities.QStrings qString, bool haveParents = true, bool haveChilds = true)
        {
            List <Entity>             list        = new List <Entity>();
            SparqlParameterizedString sparqlprmtS = new SparqlParameterizedString();

            sparqlUtilities.AddQueryCommand(sparqlprmtS, qString);

            Object results = store.ExecuteQuery(sparqlprmtS.ToString());

            if (results is SparqlResultSet)
            {
                SparqlResultSet rset = (SparqlResultSet)results;

                foreach (SparqlResult result in rset.Results)
                {
                    Entity entity = new Entity();
                    Entity child  = new Entity();

                    if (result.HasBoundValue("uri"))
                    {
                        entity.Uri = result.Value("uri").ToString();
                    }
                    if (result.HasBoundValue("name"))
                    {
                        entity.Name = result.Value("name").ToString();
                    }

                    if (haveParents)
                    {
                        entity.ParentUri = result.Value("parent").ToString();
                        if (result.HasBoundValue("parentname"))
                        {
                            entity.ParentName = result.Value("parentname").ToString();
                        }
                    }

                    if (haveChilds)
                    {
                        if (result.HasBoundValue("childname"))
                        {
                            child.Uri = result.Value("child").ToString();
                        }
                        if (result.HasBoundValue("childname"))
                        {
                            child.Name = result.Value("childname").ToString();
                        }

                        entity.Children.Add(child);
                    }

                    list.Add(entity);
                }
            }
            return(list);
        }
示例#2
0
        public LastBlockInfo GetLastBlockInfo()
        {
            _logger.LogDebug("Getting last block info...");
            string queryName = "get_last_block_info";

            _logger.LogTrace("Invoking the '{0}' SPARQL query...", queryName);
            string query     = String.Format(_queryTemplatesService.GetQueryTemplate(queryName), _chainGraphIri);
            var    resultSet = _repository.ExecuteQuery(query) as SparqlResultSet;

            if (resultSet.IsEmpty)
            {
                return(null);
            }
            var    bindingSet     = resultSet.Results[0];
            string lastBlockIri   = bindingSet.Value("lastBlockIRI").ToString();
            string lastBlockHash  = (bindingSet.Value("lastBlockHash") as ILiteralNode).Value;
            string lastBlockIndex = (bindingSet.Value("lastBlockIndex") as ILiteralNode).Value;

            return(new LastBlockInfo(lastBlockIri, lastBlockHash, lastBlockIndex));
        }
        private void TestQueryUnsynced(IStorageProvider manager)
        {
            this.EnsureTestDataset(manager);

            PersistentTripleStore store = new PersistentTripleStore(manager);

            try
            {
                store.Remove(new Uri(TestGraphUri1));

                store.ExecuteQuery("SELECT * WHERE { ?s ?p ?o }");
            }
            finally
            {
                store.Discard();
                store.Dispose();
            }
        }
        private void TestQueryDescribe(IStorageProvider manager, String query)
        {
            this.EnsureTestDataset(manager);

            PersistentTripleStore store = new PersistentTripleStore(manager);

            try
            {
                IGraph g = store.ExecuteQuery(query) as IGraph;
                if (g == null)
                {
                    Assert.True(false, "Did not get a Graph as expected");
                }

                TestTools.ShowResults(g);
            }
            finally
            {
                store.Dispose();
            }
        }
        private void TestQuerySelect(IStorageProvider manager, String query)
        {
            this.EnsureTestDataset(manager);

            PersistentTripleStore store = new PersistentTripleStore(manager);

            try
            {
                SparqlResultSet results = store.ExecuteQuery(query) as SparqlResultSet;
                if (results == null)
                {
                    Assert.True(false, "Did not get a SPARQL Result Set as expected");
                }

                TestTools.ShowResults(results);
            }
            finally
            {
                store.Dispose();
            }
        }
示例#6
0
        private void TestQueryAsk(IStorageProvider manager, String query, bool expected)
        {
            this.EnsureTestDataset(manager);

            PersistentTripleStore store = new PersistentTripleStore(manager);

            try
            {
                SparqlResultSet results = store.ExecuteQuery(query) as SparqlResultSet;
                if (results == null)
                {
                    Assert.Fail("Did not get a SPARQL Result Set as expected");
                }

                TestTools.ShowResults(results);

                Assert.AreEqual(SparqlResultsType.Boolean, results.ResultsType, "Did not get Boolean result as expected");
                Assert.AreEqual(expected, results.Result, "Boolean Result failed to match");
            }
            finally
            {
                store.Dispose();
            }
        }