예제 #1
0
 /// <summary>
 /// Handles Base URIs by passing them to the inner handler and cancelling handling if it has been requested.
 /// </summary>
 /// <param name="baseUri">Base URI.</param>
 /// <returns></returns>
 protected override bool HandleBaseUriInternal(Uri baseUri)
 {
     if (_cancelled)
     {
         return(false);
     }
     return(_handler.HandleBaseUri(baseUri));
 }
예제 #2
0
        /// <summary>
        /// Gets the Description Graph based on the Query Results from the given Evaluation Context passing the resulting Triples to the given RDF Handler
        /// </summary>
        /// <param name="handler">RDF Handler</param>
        /// <param name="context">SPARQL Evaluation Context</param>
        public void Describe(IRdfHandler handler, SparqlEvaluationContext context)
        {
            try
            {
                handler.StartRdf();

                //Apply Base URI and Namespaces to the Handler
                if (context.Query != null)
                {
                    if (context.Query.BaseUri != null)
                    {
                        if (!handler.HandleBaseUri(context.Query.BaseUri))
                        {
                            ParserHelper.Stop();
                        }
                    }
                    foreach (String prefix in context.Query.NamespaceMap.Prefixes)
                    {
                        if (!handler.HandleNamespace(prefix, context.Query.NamespaceMap.GetNamespaceUri(prefix)))
                        {
                            ParserHelper.Stop();
                        }
                    }
                }

                //Get the Nodes needing describing
                List <INode> nodes = this.GetNodes(handler, context);
                if (nodes.Count > 0)
                {
                    //If there is at least 1 Node then start describing
                    this.DescribeInternal(handler, context, nodes);
                }

                handler.EndRdf(true);
            }
            catch (RdfParsingTerminatedException)
            {
                handler.EndRdf(true);
            }
            catch
            {
                handler.EndRdf(false);
                throw;
            }
        }
예제 #3
0
        /// <summary>
        /// Applies the triples of a Graph to an RDF Handler.
        /// </summary>
        /// <param name="handler">RDF Handler.</param>
        /// <param name="g">Graph.</param>
        public static void Apply(this IRdfHandler handler, IGraph g)
        {
            try
            {
                handler.StartRdf();
                if (g != null)
                {
                    // Handle the Base URI if present
                    if (g.BaseUri != null)
                    {
                        if (!handler.HandleBaseUri(g.BaseUri))
                        {
                            ParserHelper.Stop();
                        }
                    }
                    // Handle any namespaces
                    foreach (String prefix in g.NamespaceMap.Prefixes)
                    {
                        if (!handler.HandleNamespace(prefix, g.NamespaceMap.GetNamespaceUri(prefix)))
                        {
                            ParserHelper.Stop();
                        }
                    }
                    // Finally handle triples
                    foreach (Triple t in g.Triples)
                    {
                        if (!handler.HandleTriple(t))
                        {
                            ParserHelper.Stop();
                        }
                    }
                }

                handler.EndRdf(true);
            }
            catch (RdfParsingTerminatedException)
            {
                handler.EndRdf(true);
            }
            catch
            {
                handler.EndRdf(false);
                throw;
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the Description Graph based on the Query Results from the given Evaluation Context passing the resulting Triples to the given RDF Handler
        /// </summary>
        /// <param name="handler">RDF Handler</param>
        /// <param name="context">SPARQL Evaluation Context</param>
        public void Describe(IRdfHandler handler, SparqlEvaluationContext context)
        {
            try
            {
                handler.StartRdf();

                //Apply Base URI and Namespaces to the Handler
                if (context.Query != null)
                {
                    if (context.Query.BaseUri != null)
                    {
                        if (!handler.HandleBaseUri(context.Query.BaseUri)) ParserHelper.Stop();
                    }
                    foreach (String prefix in context.Query.NamespaceMap.Prefixes)
                    {
                        if (!handler.HandleNamespace(prefix, context.Query.NamespaceMap.GetNamespaceUri(prefix))) ParserHelper.Stop();
                    }
                }

                //Get the Nodes needing describing
                List<INode> nodes = this.GetNodes(handler, context);
                if (nodes.Count > 0)
                {
                    //If there is at least 1 Node then start describing
                    this.DescribeInternal(handler, context, nodes);
                }

                handler.EndRdf(true);
            }
            catch (RdfParsingTerminatedException)
            {
                handler.EndRdf(true);
            }
            catch
            {
                handler.EndRdf(false);
                throw;
            }
        }
예제 #5
0
 /// <summary>
 /// Delegates base Uri handling to inner handler.
 /// </summary>
 protected override bool HandleBaseUriInternal(Uri baseUri) => _handler.HandleBaseUri(baseUri);
 /// <summary>
 /// Handles a Base URI declaration.
 /// </summary>
 /// <param name="baseUri">Base URI.</param>
 /// <returns></returns>
 protected override bool HandleBaseUriInternal(Uri baseUri)
 {
     return(_handler.HandleBaseUri(baseUri));
 }
        /// <summary>
        /// Loads a Graph from the Store asynchronously
        /// </summary>
        /// <param name="handler">Handler to load with</param>
        /// <param name="graphUri">URI of the Graph to load</param>
        /// <param name="callback">Callback</param>
        /// <param name="state">State to pass to the callback</param>
        public override void LoadGraph(IRdfHandler handler, string graphUri, AsyncStorageCallback callback, object state)
        {
            try
            {
                HttpWebRequest request;
                Dictionary<String, String> serviceParams = new Dictionary<string, string>();
                Uri baseUri = null;

                SparqlParameterizedString construct = new SparqlParameterizedString();
                if (!graphUri.Equals(string.Empty))
                {
                    construct.CommandText = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH @graph { ?s ?p ?o } }";
                    baseUri = UriFactory.Create(graphUri);
                    construct.SetUri("graph", baseUri);
                }
                else
                {
                    construct.CommandText = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }";
                }
                serviceParams.Add("query", construct.ToString());

                request = this.CreateRequest("/sparql", MimeTypesHelper.HttpAcceptHeader, "GET", serviceParams);

                Tools.HttpDebugRequest(request);

                request.BeginGetResponse(r =>
                {
                    try
                    {
                        using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(r))
                        {
                            Tools.HttpDebugResponse(response);

                            IRdfReader parser = MimeTypesHelper.GetParser(response.ContentType);
                            parser.Load(handler, new StreamReader(response.GetResponseStream()));
                            if (baseUri != null)
                            {
                                handler.StartRdf();
                                handler.HandleBaseUri(baseUri);
                                handler.EndRdf(true);
                            }
                            response.Close();
                        }

                        callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.LoadWithHandler, handler), state);
                    }
                    catch (WebException webEx)
                    {
                        callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.LoadWithHandler, StorageHelper.HandleHttpError(webEx, "loading a Graph from")), state);
                    }
                    catch (Exception ex)
                    {
                        callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.LoadWithHandler, StorageHelper.HandleError(ex, "loading a Graph from")), state);
                    }
                }, state);
            }
            catch (WebException webEx)
            {
                callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.LoadWithHandler, StorageHelper.HandleHttpError(webEx, "loading a Graph from")), state);
            }
            catch (Exception ex)
            {
                callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.LoadWithHandler, StorageHelper.HandleError(ex, "loading a Graph from")), state);
            }
        }