예제 #1
0
 internal SparqlResult(TextReader streamReader, ISerializationFormat resultFormat,
                       SparqlQueryContext sparqlQueryContext)
 {
     ResultFormat = resultFormat;
     ParseResult(streamReader);
     SourceSparqlQueryContext = sparqlQueryContext;
 }
예제 #2
0
        public void TestGetNamedGraph()
        {
            var brightstar        = new Mock <IBrightstarService>();
            var mockResultsStream = new MemoryStream(Encoding.UTF8.GetBytes("Mock Results"));
            ISerializationFormat expectedFormat = RdfFormat.RdfXml;

            brightstar.Setup(s => s.DoesStoreExist("foo")).Returns(true).Verifiable();
            brightstar.Setup(
                s =>
                s.ExecuteQuery("foo", "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH <http://example.org/g> { ?s ?p ?o } }",
                               It.IsAny <IEnumerable <string> >(), null, It.IsAny <SparqlResultsFormat>(), RdfFormat.RdfXml, out expectedFormat)).Returns(mockResultsStream).Verifiable();
            var app      = new Browser(new FakeNancyBootstrapper(brightstar.Object));
            var response = app.Get("/foo/graphs", with =>
            {
                with.Query("graph", "http://example.org/g");
                with.Accept(RdfXml);
            });

            Assert.That(response, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            var responseBody = response.Body.AsString();

            Assert.That(responseBody, Is.EqualTo("Mock Results"));
            brightstar.Verify();
        }
예제 #3
0
 internal SparqlResult(TextReader streamReader, ISerializationFormat resultFormat,
     SparqlQueryContext sparqlQueryContext)
 {
     ResultFormat = resultFormat;
     ParseResult(streamReader);
     SourceSparqlQueryContext = sparqlQueryContext;
 }
예제 #4
0
        public void TestPostQueryOnValidCommitPoint()
        {
            // Setup
            var brightstar = new Mock <IBrightstarService>();
            ISerializationFormat format = SparqlResultsFormat.Xml;

            brightstar.Setup(
                s =>
                s.ExecuteQuery(It.Is <ICommitPointInfo>(c => c.Id.Equals(123)), SparqlQueryString, (IEnumerable <string>)null,
                               SparqlResultsFormat.Xml, It.IsAny <RdfFormat>(), out format))
            .Returns(new MemoryStream(Encoding.UTF8.GetBytes("mock results")))
            .Verifiable();
            var commitPoint = new Mock <ICommitPointInfo>();

            commitPoint.Setup(c => c.Id).Returns(123);

            brightstar.Setup(s => s.GetCommitPoint("foo", 123L)).Returns(commitPoint.Object);
            var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));

            // Execute
            var response = app.Post("/foo/commits/123/sparql", with =>
            {
                with.FormValue("query", SparqlQueryString);
                with.Accept(SparqlXml);
            });

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(response.Body.AsString(), Is.EqualTo("mock results"));
            brightstar.Verify();
        }
예제 #5
0
        public void TestGetQueryValidation()
        {
            const string         mockResponse = "<results></results>";
            ISerializationFormat format       = SparqlResultsFormat.Xml;
            var brightstar = new Mock <IBrightstarService>();

            TestGetFails(HttpStatusCode.BadRequest, brightstar, "foo", "bad sparql query");
        }
예제 #6
0
 internal SparqlResult(Stream resultStream, ISerializationFormat resultFormat, SparqlQueryContext sparqlQueryContext)
 {
     if (resultStream == null) throw new ArgumentNullException(nameof(resultStream));
     ResultFormat = resultFormat;
     SourceSparqlQueryContext = sparqlQueryContext;
     using (var reader = new StreamReader(resultStream))
     {
         ParseResult(reader);
     }
 }
 public Stream GetResultsStream(SparqlResultsFormat format, RdfFormat graphFormat, DateTime? ifNotModifiedSince, out ISerializationFormat streamFormat)
 {
     if (_commitId > 0)
     {
         var commitPointInfo = _service.GetCommitPoint(_storeName, _commitId);
         if (commitPointInfo == null) throw new InvalidCommitPointException();
         return _service.ExecuteQuery(commitPointInfo, _sparqlRequest.Query, _sparqlRequest.DefaultGraphUri, format, graphFormat, out streamFormat);
     }
     return _service.ExecuteQuery(_storeName, _sparqlRequest.Query, _sparqlRequest.DefaultGraphUri, ifNotModifiedSince, format, graphFormat, out streamFormat);
 }
예제 #8
0
        public BrightstarSparqlResultsType ExecuteSparqlQuery(SparqlQuery query, ISerializationFormat targetFormat, Stream resultsStream,
                                                              IEnumerable <string> defaultGraphUris)
        {
            var queryHandler = new SparqlQueryHandler(targetFormat, defaultGraphUris);
            // NOTE: streamWriter is not wrapped in a using because we don't want to close resultStream at this point

            var streamWriter = new StreamWriter(resultsStream, targetFormat.Encoding);
            var resultsType  = queryHandler.ExecuteSparql(query, this, streamWriter);

            return(resultsType);
        }
예제 #9
0
 public void TestGetQueryAsSparqlXmlWithoutAdditionalParameters()
 {
     const string mockResponse = "<results></results>";
     ISerializationFormat format = SparqlResultsFormat.Xml;
     var brightstar = new Mock<IBrightstarService>();
     brightstar.Setup(s => s.ExecuteQuery("foo", SparqlQueryString, null, null,
                                          SparqlResultsFormat.Xml, It.IsAny<RdfFormat>(), out format))
                            .Returns(new MemoryStream(Encoding.UTF8.GetBytes(mockResponse)));
     var response = TestGetSucceeds(brightstar, "foo", SparqlQueryString);
     Assert.That(response.Body.AsString(), Is.EqualTo(mockResponse));
 }
예제 #10
0
 static public IBindingBuilder <TModel, TView, TLoadedValue, TBindingCollection> Load <TModel, TView, TLoadedValue, TBindingCollection>(
     this IBindingBuilder <TModel, TView, FilePath, TBindingCollection> builder,
     Func <ISerializationFormat <TLoadedValue> > serializationFormatProvider)
     where TModel : IGlyphData
 {
     return(builder.Select((mv, m, v) => SafeLoad(mv, stream =>
     {
         ISerializationFormat <TLoadedValue> serializationFormat = serializationFormatProvider();
         serializationFormat.KnownTypes = m.SerializationKnownTypes;
         return serializationFormat.Load(stream);
     })));
 }
예제 #11
0
 public void TestGetQueryAsRdfXmlWithoutAdditionalParameters()
 {
     const string mockResponse = "<rdf:RDF/>";
     ISerializationFormat format = RdfFormat.RdfXml.WithEncoding(Encoding.UTF8);
     var brightstar = new Mock<IBrightstarService>();
     brightstar.Setup(s => s.ExecuteQuery("foo", DescribeQueryString, null, null,
                                          It.IsAny<SparqlResultsFormat>(), RdfFormat.RdfXml, out format))
               .Returns(new MemoryStream(Encoding.UTF8.GetBytes(mockResponse)));
     var response = TestGetSucceeds(brightstar, "foo", DescribeQueryString,
                                    accept: MediaRange.FromString("application/rdf+xml"));
     Assert.That(response.Body.AsString(), Is.EqualTo(mockResponse));
 }
예제 #12
0
 public void TestGetQueryAsSparqlTsvWithoutAdditionalParameters()
 {
     const string mockResponse = "x\ty";
     ISerializationFormat format = SparqlResultsFormat.Tsv;
     var brightstar = new Mock<IBrightstarService>();
     brightstar.Setup(s => s.ExecuteQuery("foo", SparqlQueryString, null, null,
                                          SparqlResultsFormat.Tsv, It.IsAny<RdfFormat>(), out format))
               .Returns(new MemoryStream(Encoding.UTF8.GetBytes(mockResponse)));
     var response = TestGetSucceeds(brightstar,
         "foo", SparqlQueryString, accept:MediaRange.FromString("text/tab-separated-values"));
     Assert.That(response.Body.AsString(), Is.EqualTo(mockResponse));
 }
예제 #13
0
 public void TestGetQueryAsSparqlJsonWithoutAdditionalParameters()
 {
     const string mockResponse = "{ \"head\": { }, \"results\": { } }";
     ISerializationFormat format = SparqlResultsFormat.Json;
     var brightstar = new Mock<IBrightstarService>();
     brightstar.Setup(
         s => s.ExecuteQuery("foo", SparqlQueryString, null, null,
                             SparqlResultsFormat.Json, It.IsAny<RdfFormat>(), out format))
             .Returns(new MemoryStream(Encoding.UTF8.GetBytes(mockResponse)));
     var response = TestGetSucceeds(brightstar, "foo", SparqlQueryString,
                                    accept: MediaRange.FromString("application/sparql-results+json"));
     Assert.That(response.Body.AsString(), Is.EqualTo(mockResponse));
 }
예제 #14
0
 internal SparqlResult(Stream resultStream, ISerializationFormat resultFormat, SparqlQueryContext sparqlQueryContext)
 {
     if (resultStream == null)
     {
         throw new ArgumentNullException(nameof(resultStream));
     }
     ResultFormat             = resultFormat;
     SourceSparqlQueryContext = sparqlQueryContext;
     using (var reader = new StreamReader(resultStream))
     {
         ParseResult(reader);
     }
 }
예제 #15
0
 public BrightstarSparqlResultsType Query(SparqlQuery query, ISerializationFormat targetFormat, Stream resultsStream, string[] defaultGraphUris)
 {
     Logging.LogDebug("Query {0}", query);
     try
     {
         return(ReadStore.ExecuteSparqlQuery(query, targetFormat, resultsStream, defaultGraphUris));
     }
     catch (ReadWriteStoreModifiedException)
     {
         Logging.LogDebug("Read/Write store was concurrently modified. Attempting a retry");
         InvalidateReadStore();
         return(Query(query, targetFormat, resultsStream, defaultGraphUris));
     }
 }
예제 #16
0
 public void TestGetQueryWithSingleDefaultGraphUri()
 {
     const string mockResponse = "yello";
     var brightstar = new Mock<IBrightstarService>();
     ISerializationFormat format = SparqlResultsFormat.Xml;
     brightstar.Setup(
         s =>
         s.ExecuteQuery("bar", SparqlQueryString, new[] {"http://some/graph/uri"}, null,
                        SparqlResultsFormat.Xml, It.IsAny<RdfFormat>(), out format))
               .Returns(new MemoryStream(Encoding.UTF8.GetBytes(mockResponse)));
     var response = TestGetSucceeds(brightstar, "bar", SparqlQueryString,
                                    defaultGraphUris: new[] {"http://some/graph/uri"},
                                    accept: MediaRange.FromString("application/sparql-results+xml"));
     Assert.That(response.Body.AsString(), Is.EqualTo(mockResponse));
 }
예제 #17
0
 public void TestGetQueryWithFormatOverride()
 {
     const string mockResponse ="OK";
     var brightstar = new Mock<IBrightstarService>();
     ISerializationFormat format = SparqlResultsFormat.Json;
     brightstar.Setup(
         s =>
         s.ExecuteQuery("foo", SparqlQueryString, null, null, It.IsAny<SparqlResultsFormat>(), It.IsAny<RdfFormat>(), out format))
               .Returns(new MemoryStream(Encoding.UTF8.GetBytes(mockResponse)));
     var response = TestGetSucceeds(brightstar, "foo", SparqlQueryString,
                                    formats: new string[] {format.MediaTypes[0]},
                                    accept: "application/xml");
     Assert.That(response.Body.AsString(), Is.EqualTo(mockResponse));
     Assert.That(MediaRange.FromString(format.MediaTypes[0]).Matches(MediaRange.FromString(response.ContentType)),
         "Expected content type: {0}. Got: {1}", format.MediaTypes[0], response.ContentType);
 }
예제 #18
0
 public SparqlQueryHandler(ISerializationFormat targetFormat,
                           IEnumerable <string> defaultGraphUris)
 {
     if (targetFormat is SparqlResultsFormat)
     {
         _sparqlResultsFormat = targetFormat as SparqlResultsFormat;
     }
     if (targetFormat is RdfFormat)
     {
         _rdfFormat = targetFormat as RdfFormat;
     }
     if (defaultGraphUris != null)
     {
         _defaultGraphUris = defaultGraphUris.Select(g => new Uri(g)).ToList();
     }
 }
예제 #19
0
 public SparqlQueryHandler(ISerializationFormat targetFormat,
                           IEnumerable<string> defaultGraphUris)
 {
     if (targetFormat is SparqlResultsFormat)
     {
         _sparqlResultsFormat = targetFormat as SparqlResultsFormat;
     }
     if (targetFormat is RdfFormat)
     {
         _rdfFormat = targetFormat as RdfFormat;
     }
     if (defaultGraphUris != null)
     {
         _defaultGraphUris = defaultGraphUris.Select(g => new Uri(g)).ToList();
     }
 }
예제 #20
0
        private static void TestSparqlPostSucceeds(string storeName, string query, IEnumerable <string> defaultGraphUris, IEnumerable <string> namedGraphUris, MediaRange accept, SparqlResultsFormat expectedQueryFormat, Action <Mock <IBrightstarService> > brightstarSetup)
        {
            // Setup
            var brightstar = new Mock <IBrightstarService>();
            ISerializationFormat format = expectedQueryFormat;

            brightstar.Setup(s => s.ExecuteQuery(storeName, query, defaultGraphUris, null, expectedQueryFormat, It.IsAny <RdfFormat>(), out format))
            .Returns(new MemoryStream(Encoding.UTF8.GetBytes("Mock Results")))
            .Verifiable();
            if (brightstarSetup != null)
            {
                brightstarSetup(brightstar);
            }
            var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));

            // Execute
            var response = app.Post("/" + storeName + "/sparql", with =>
            {
                with.Body(query);
                with.Header("Content-Type", "application/sparql-query");
                if (defaultGraphUris != null)
                {
                    foreach (var defaultGraphUri in defaultGraphUris)
                    {
                        with.Query("default-graph-uri", defaultGraphUri);
                    }
                }
                if (namedGraphUris != null)
                {
                    foreach (var namedGraphUri in namedGraphUris)
                    {
                        with.Query("named-graph-uri", namedGraphUri);
                    }
                }
                with.Accept(accept);
            });

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(accept.Matches(MediaRange.FromString(response.ContentType)));
            Assert.That(response.Body.AsString(), Is.EqualTo("Mock Results"));
            brightstar.Verify();
        }
예제 #21
0
        public void TestPostQueryWithIfModifiedSince()
        {
            // Setup
            var brightstar = new Mock<IBrightstarService>();
            ISerializationFormat format = SparqlResultsFormat.Xml;
            brightstar.Setup(
                s => s.ExecuteQuery("foo", SparqlQueryString, (IEnumerable<string>)null, It.IsNotNull<DateTime?>(), SparqlResultsFormat.Xml,  It.IsAny<RdfFormat>(), out format))
                      .Throws<BrightstarStoreNotModifiedException>()
                      .Verifiable();
            var app = new Browser(new FakeNancyBootstrapper(brightstar.Object));

            // Execute
            var response = app.Post("/foo/sparql", with =>
            {
                with.FormValue("query", SparqlQueryString);
                with.Accept(SparqlXml);
                with.Header("If-Modified-Since", DateTime.Now.ToUniversalTime().ToString("r"));
            });

            // Assert
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotModified));
        }
예제 #22
0
        public void TestCorsHeaderOn404Response()
        {
            var brightstar           = new Mock <IBrightstarService>();
            ISerializationFormat fmt = SparqlResultsFormat.Xml;

            brightstar.Setup(
                x =>
                x.ExecuteQuery("foo", It.IsAny <string>(), null, null,
                               It.IsAny <SparqlResultsFormat>(),
                               It.IsAny <RdfFormat>(), out fmt)).Throws(
                new NoSuchStoreException("foo"));
            var app      = new Browser(new FakeNancyBootstrapper(brightstar.Object));
            var response = app.Get("/foo/sparql", with =>
            {
                with.Query("query", SparqlQueryString);
                with.Accept(SparqlXml);
                with.Header("Origin", "http://example.com/");
            });

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
            Assert.That(response.Headers["Access-Control-Allow-Origin"], Is.EqualTo("*"));
        }
예제 #23
0
        public void TestIfModifiedSinceHeaderRespected()
        {
            ISerializationFormat expectedFormat = RdfFormat.RdfXml;
            var brightstar = new Mock <IBrightstarService>();

            brightstar.Setup(s => s.DoesStoreExist("foo")).Returns(true).Verifiable();
            brightstar.Setup(
                s =>
                s.ExecuteQuery("foo", "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }",
                               It.Is <IEnumerable <string> >(x => x.First().Equals(Constants.DefaultGraphUri)),
                               It.IsNotNull <DateTime?>(), It.IsAny <SparqlResultsFormat>(), RdfFormat.RdfXml, out expectedFormat))
            .Throws <BrightstarStoreNotModifiedException>()
            .Verifiable();
            var app      = new Browser(new FakeNancyBootstrapper(brightstar.Object));
            var response = app.Get("/foo/graphs", with =>
            {
                with.Query("default", "");
                with.Accept(RdfXml);
                with.Header("If-Modified-Since", DateTime.UtcNow.ToString("r"));
            });

            Assert.That(response, Is.Not.Null);
            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotModified));
        }
예제 #24
0
 public SerializationBuilder Add(ContentType contentType, ISerializationFormat format) => Add(new FlexibleContentType(contentType), format);
예제 #25
0
        private string MakeQueryCacheKey(string storeName, long commitTime, SparqlQuery query, string[] defaultGraphUris, ISerializationFormat targetFormat)
        {
            var graphHashCode = defaultGraphUris == null ? 0 : String.Join(",", defaultGraphUris.OrderBy(s => s)).GetHashCode();

            return(storeName + "_" + commitTime + "_" + query.GetHashCode() + "_" + graphHashCode + "_" + targetFormat);
        }
예제 #26
0
 private string MakeQueryCacheKey(string storeName, long commitTime, SparqlQuery query, string[] defaultGraphUris, ISerializationFormat targetFormat)
 {
     var graphHashCode = defaultGraphUris == null ? 0 : String.Join(",", defaultGraphUris.OrderBy(s=>s)).GetHashCode();
     return storeName + "_" + commitTime + "_" + query.GetHashCode() + "_" + graphHashCode + "_" + targetFormat;
 }
예제 #27
0
 public BrightstarSparqlResultsType Query(ulong commitPointId, SparqlQuery query, ISerializationFormat targetFormat, Stream resultsStream, string[] defaultGraphUris)
 {
     // Not supported by read/write store so no handling for ReadWriteStoreModifiedException required
     Logging.LogDebug("CommitPointId={0}, Query={1}", commitPointId, query);
     using (var readStore = _storeManager.OpenStore(_storeLocation, commitPointId))
     {
         return(readStore.ExecuteSparqlQuery(query, targetFormat, resultsStream, defaultGraphUris));
     }
 }
        /// <summary>
        /// Query a specific commit point of a store
        /// </summary>
        /// <param name="commitPoint">The commit point be queried</param>
        /// <param name="queryExpression">The SPARQL query string</param>
        /// <param name="defaultGraphUris">An enumeration over the URIs of the graphs that will be taken together as the default graph for the query. May be NULL to use the built-in default graph</param>
        /// <param name="resultsFormat">Specifies the serialization format for the SPARQL result set returned by the query. May be NULL to indicate that an RDF graph is the expected result.</param>
        /// <param name="graphFormat">Specifies the serialization format for the RDF graph returned by the query. May be NULL to indicate that a SPARQL results set is the expected result.</param>
        /// <param name="streamFormat">Specifies the serialization format used in the returned <see cref="Stream"/>.</param>
        /// <returns>A stream containing the results of executing the query</returns>
        public Stream ExecuteQuery(ICommitPointInfo commitPoint, string queryExpression, IEnumerable<string> defaultGraphUris, 
            SparqlResultsFormat resultsFormat, RdfFormat graphFormat, out ISerializationFormat streamFormat)
        {
            if (queryExpression == null) throw new ArgumentNullException("queryExpression");
            if (resultsFormat == null) resultsFormat = SparqlResultsFormat.Xml;
            if (graphFormat == null) graphFormat = RdfFormat.RdfXml;

            try
            {
                var pStream = new MemoryStream();
                streamFormat = _serverCore.Query(commitPoint.StoreName, commitPoint.Id, queryExpression, defaultGraphUris, resultsFormat, graphFormat, pStream);
                return new MemoryStream(pStream.ToArray());
            }
#if !PORTABLE && !WINDOWS_PHONE
            catch (AggregateException aggregateException)
            {
                Logging.LogError(BrightstarEventId.ServerCoreException,
                                 "Error querying store {0}@{1} with expression {2}", commitPoint.StoreName,
                                 commitPoint.Id, queryExpression);
                if (aggregateException.InnerExceptions.Count == 1)
                {
                    throw new BrightstarClientException(
                        String.Format("Error querying store {0}@{1} with expression {2}. {3}",
                                      commitPoint.StoreName, commitPoint.Id, queryExpression,
                                      aggregateException.InnerExceptions[0].Message));
                }
                var messages = String.Join("; ", aggregateException.InnerExceptions.Select(ex => ex.Message));
                throw new BrightstarClientException(
                    String.Format(
                        "Error querying store {0}@{1} with expression {2}. Multiple errors occurred: {3}",
                        commitPoint.StoreName, commitPoint.Id, queryExpression, messages));
            }
#endif
            catch (Exception ex)
            {
                Logging.LogError(BrightstarEventId.ServerCoreException,
                                 "Error querying store {0}@{1} with expression {2}", commitPoint.StoreName,
                                 commitPoint.Id, queryExpression);
                throw new BrightstarClientException(
                    String.Format("Error querying store {0}@{1} with expression {2}. {3}", commitPoint.StoreName,
                                  commitPoint.Id, queryExpression, ex.Message), ex);
            }
        }
예제 #29
0
 public BrightstarSparqlResultsType ExecuteSparqlQuery(SparqlQuery query, ISerializationFormat targetFormat, Stream resultsStream,
     IEnumerable<string> defaultGraphUris )
 {
     var queryHandler = new SparqlQueryHandler(targetFormat, defaultGraphUris);
     // NOTE: streamWriter is not wrapped in a using because we don't want to close resultStream at this point
     
     var streamWriter = new StreamWriter(resultsStream, targetFormat.Encoding);
     var resultsType = queryHandler.ExecuteSparql(query, this, streamWriter);
     return resultsType;
 }
예제 #30
0
 internal SparqlResult(string resultString, ISerializationFormat resultFormat, SparqlQueryContext sparqlQueryContext) :
     this(new StringReader(resultString), resultFormat, sparqlQueryContext )
 {
     
 }
        /// <summary>
        /// Query a specific commit point of a store
        /// </summary>
        /// <param name="storeName">The name of the store to query</param>
        /// <param name="queryExpression">The SPARQL query string</param>
        /// <param name="ifNotModifiedSince">OPTIONAL : If this parameter has a value and the store has not been changed since the time specified,
        /// a <see cref="BrightstarStoreNotModifiedException"/> will be raised with the message "Store not modified".</param>
        /// <param name="defaultGraphUris">An enumeration over the URIs of the graphs that will be taken together as the default graph for the query. May be NULL to use the built-in default graph</param>
        /// <param name="resultsFormat">Specifies the serialization format for the SPARQL result set returned by the query. May be NULL to indicate that an RDF graph is the expected result.</param>
        /// <param name="graphFormat">Specifies the serialization format for the RDF graph returned by the query. May be NULL to indicate that a SPARQL results set is the expected result.</param>
        /// <param name="streamFormat">Specifies the serialization format used in the returned <see cref="Stream"/>.</param>
        /// <returns>A stream containing the results of executing the query</returns>
        public Stream ExecuteQuery(string storeName, string queryExpression, IEnumerable<string> defaultGraphUris, DateTime? ifNotModifiedSince, 
            SparqlResultsFormat resultsFormat, RdfFormat graphFormat, out ISerializationFormat streamFormat)
        {
            if (storeName == null) throw new ArgumentNullException("storeName");
            if (queryExpression == null) throw new ArgumentNullException("queryExpression");
            if (resultsFormat == null && graphFormat == null) throw new ArgumentException("Either resultsFormat or graphFormat must be non-NULL");

            if (!_serverCore.DoesStoreExist(storeName)) throw new NoSuchStoreException(storeName);
            try
            {
                var pStream = new MemoryStream();
                streamFormat = _serverCore.Query(storeName, queryExpression,
                    defaultGraphUris == null ? null : defaultGraphUris.Where(x => !string.IsNullOrEmpty(x)), 
                    ifNotModifiedSince, resultsFormat,
                    graphFormat, pStream);
                return new MemoryStream(pStream.ToArray());
            }
            catch (BrightstarStoreNotModifiedException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logging.LogError(BrightstarEventId.ServerCoreException, "Error Executing Query {0} {1}", storeName, queryExpression);
                throw new BrightstarClientException("Error querying store " + storeName + " with expression " + queryExpression + ". " + ex.Message, ex);
            }
        }
 public Stream GetResultsStream(SparqlResultsFormat format, RdfFormat graphFormat, DateTime?ifNotModifiedSince, out ISerializationFormat streamFormat)
 {
     if (_commitId > 0)
     {
         var commitPointInfo = _service.GetCommitPoint(_storeName, _commitId);
         if (commitPointInfo == null)
         {
             throw new InvalidCommitPointException();
         }
         return(_service.ExecuteQuery(commitPointInfo, _sparqlRequest.Query, _sparqlRequest.DefaultGraphUri, format, graphFormat, out streamFormat));
     }
     return(_service.ExecuteQuery(_storeName, _sparqlRequest.Query, _sparqlRequest.DefaultGraphUri, ifNotModifiedSince, format, graphFormat, out streamFormat));
 }
예제 #33
0
 public ConversionHandler(ISerializationFormat format, IHandler parent)
 {
     Parent = parent;
     Format = format;
 }
예제 #34
0
 public GenericSerializationFormat(ISerializationFormat serializationFormat)
 {
     _serializationFormat = serializationFormat;
 }
예제 #35
0
 internal SparqlResult(string resultString, ISerializationFormat resultFormat, SparqlQueryContext sparqlQueryContext) :
     this(new StringReader(resultString), resultFormat, sparqlQueryContext)
 {
 }
예제 #36
0
 static public ISerializationFormat <T> AsGeneric <T>(this ISerializationFormat serializationFormat) => new GenericSerializationFormat <T>(serializationFormat);
예제 #37
0
 public ConversionHandlerBuilder(ISerializationFormat format)
 {
     _Format = format;
 }
예제 #38
0
 public BrightstarSparqlResultsType Query(SparqlQuery query, ISerializationFormat targetFormat, Stream resultsStream, string[] defaultGraphUris )
 {
     Logging.LogDebug("Query {0}", query);
     try
     {
         return ReadStore.ExecuteSparqlQuery(query, targetFormat, resultsStream, defaultGraphUris);
     }
     catch (ReadWriteStoreModifiedException)
     {
         Logging.LogDebug("Read/Write store was concurrently modified. Attempting a retry");
         InvalidateReadStore();
         return Query(query, targetFormat, resultsStream, defaultGraphUris);
     }
 }
예제 #39
0
 public SerializationBuilder Add(FlexibleContentType contentType, ISerializationFormat format)
 {
     _Registry[contentType] = format;
     return(this);
 }
예제 #40
0
 public BrightstarSparqlResultsType Query(ulong commitPointId, SparqlQuery query, ISerializationFormat targetFormat, Stream resultsStream, string[] defaultGraphUris)
 {
     // Not supported by read/write store so no handling for ReadWriteStoreModifiedException required
     Logging.LogDebug("CommitPointId={0}, Query={1}", commitPointId, query);
     using (var readStore = _storeManager.OpenStore(_storeLocation, commitPointId))
     {
         return readStore.ExecuteSparqlQuery(query, targetFormat, resultsStream, defaultGraphUris);
     }
 }