示例#1
0
 /// <summary>
 /// Updates the view by making the query over the Native Store (i.e. the query is handled by the stores SPARQL implementation).
 /// </summary>
 protected override void UpdateViewInternal()
 {
     try
     {
         Object results = ((INativelyQueryableStore)_store).ExecuteQuery(_q.ToString());
         if (results is IGraph)
         {
             DetachEventHandlers(_triples);
             IGraph g = (IGraph)results;
             foreach (Triple t in g.Triples)
             {
                 _triples.Add(t.CopyTriple(this));
             }
             AttachEventHandlers(_triples);
         }
         else
         {
             DetachEventHandlers(_triples);
             _triples = ((SparqlResultSet)results).ToTripleCollection(this);
             AttachEventHandlers(_triples);
         }
         LastError = null;
         RaiseGraphChanged();
     }
     catch (RdfQueryException queryEx)
     {
         LastError = new RdfQueryException("Unable to Update a SPARQL View as an error occurred in processing the Query - see Inner Exception for details", queryEx);
     }
 }
示例#2
0
 /// <summary>
 /// Updates the view by making the SPARQL Query in-memory over the relevant Triple Store.
 /// </summary>
 protected override void UpdateViewInternal()
 {
     try
     {
         var processor = new LeviathanQueryProcessor((IInMemoryQueryableStore)_store);
         var results   = processor.ProcessQuery(_q);
         if (results is IGraph g)
         {
             // Note that we replace the existing triple collection with an entirely new one as otherwise nasty race conditions can happen
             // This does mean that while the update is occurring the user may be viewing a stale graph
             DetachEventHandlers(_triples);
             TreeIndexedTripleCollection triples = new TreeIndexedTripleCollection();
             foreach (Triple t in g.Triples)
             {
                 triples.Add(t.CopyTriple(this));
             }
             _triples = triples;
             AttachEventHandlers(_triples);
         }
         else
         {
             // Note that we replace the existing triple collection with an entirely new one as otherwise nasty race conditions can happen
             // This does mean that while the update is occurring the user may be viewing a stale graph
             DetachEventHandlers(_triples);
             _triples = ((SparqlResultSet)results).ToTripleCollection(this);
             AttachEventHandlers(_triples);
         }
         LastError = null;
         RaiseGraphChanged();
     }
     catch (RdfQueryException queryEx)
     {
         LastError = new RdfQueryException("Unable to Update a SPARQL View as an error occurred in processing the Query - see Inner Exception for details", queryEx);
     }
 }
        /// <summary>
        /// Processes a SPARQL Query asynchronously invoking the relevant callback when the query completes
        /// </summary>
        /// <param name="query">SPARQL QUery</param>
        /// <param name="rdfCallback">Callback for queries that return a Graph</param>
        /// <param name="resultsCallback">Callback for queries that return a Result Set</param>
        /// <param name="state">State to pass to the callback</param>
        /// <remarks>
        /// In the event of a success the appropriate callback will be invoked, if there is an error both callbacks will be invoked and passed an instance of <see cref="AsyncError"/> which contains details of the error and the original state information passed in.
        /// </remarks>
        public void ProcessQuery(SparqlQuery query, GraphCallback rdfCallback, SparqlResultsCallback resultsCallback, Object state)
        {
            Graph             g    = new Graph();
            SparqlResultSet   rset = new SparqlResultSet();
            ProcessQueryAsync d    = new ProcessQueryAsync(this.ProcessQuery);

            d.BeginInvoke(new GraphHandler(g), new ResultSetHandler(rset), query, r =>
            {
                try
                {
                    d.EndInvoke(r);
                    if (rset.ResultsType != SparqlResultsType.Unknown)
                    {
                        resultsCallback(rset, state);
                    }
                    else
                    {
                        rdfCallback(g, state);
                    }
                }
                catch (RdfQueryException queryEx)
                {
                    if (rdfCallback != null)
                    {
                        rdfCallback(null, new AsyncError(queryEx, state));
                    }
                    if (resultsCallback != null)
                    {
                        resultsCallback(null, new AsyncError(queryEx, state));
                    }
                }
                catch (Exception ex)
                {
                    RdfQueryException queryEx = new RdfQueryException("Unexpected error while making an asynchronous query, see inner exception for details", ex);
                    if (rdfCallback != null)
                    {
                        rdfCallback(null, new AsyncError(queryEx, state));
                    }
                    if (resultsCallback != null)
                    {
                        resultsCallback(null, new AsyncError(queryEx, state));
                    }
                }
            }, state);
        }
示例#4
0
        /// <summary>
        /// Callback for when asychronous invalidation completes.
        /// </summary>
        /// <param name="result">Async call results.</param>
        private void InvalidateViewCompleted(IAsyncResult result)
        {
            try
            {
                _async.EndInvoke(result);

                // If we've been further invalidated then need to re-query
                if (_requiresInvalidate)
                {
                    InvalidateView();
                    _requiresInvalidate = false;
                }
            }
            catch (Exception ex)
            {
                // Ignore errors
                LastError = new RdfQueryException("Unable to complete update of SPARQL View, see inner exception for details", ex);
            }
        }
 /// <summary>
 /// Invalidates the View causing it to be updated.
 /// </summary>
 private void InvalidateView()
 {
     Task.Factory.StartNew(UpdateViewInternal).ContinueWith(antecedent =>
     {
         if (antecedent.IsFaulted)
         {
             LastError = new RdfQueryException(
                 "Unable to complete update of SPARQL View, see inner exception for details",
                 antecedent.Exception);
         }
         else
         {
             if (_requiresInvalidate)
             {
                 InvalidateView();
                 _requiresInvalidate = false;
             }
         }
     });
 }