Esempio n. 1
0
        /// <summary>
        /// Extracts an RDF Dataset which details the Constraints violated (if any) and whether Constraints are satisified
        /// </summary>
        /// <param name="callback">Callback to invoke when the operation completes</param>
        /// <param name="state">State to pass to the callback</param>
        public void Validate(TripleStoreCallback callback, Object state)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Endpoint.Uri);

            request.Method = this.Endpoint.HttpMethods.First();
            request.Accept = MimeTypesHelper.CustomHttpAcceptHeader(this.MimeTypes, MimeTypesHelper.SupportedRdfDatasetMimeTypes);

#if DEBUG
            if (Options.HttpDebugging)
            {
                Tools.HttpDebugRequest(request);
            }
#endif

            request.BeginGetResponse(result =>
            {
                using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result))
                {
#if DEBUG
                    if (Options.HttpDebugging)
                    {
                        Tools.HttpDebugResponse(response);
                    }
#endif
                    IStoreReader parser     = MimeTypesHelper.GetStoreParser(response.ContentType);
                    TripleStore store       = new TripleStore();
                    StreamParams parameters = new StreamParams(response.GetResponseStream());
                    parser.Load(store, parameters);

                    response.Close();
                    callback(store, state);
                }
            }, null);
        }
Esempio n. 2
0
        /// <summary>
        /// Extracts an RDF Dataset which details the Constraints violated (if any) and whether Constraints are satisified.
        /// </summary>
        /// <param name="callback">Callback to invoke when the operation completes.</param>
        /// <param name="state">State to pass to the callback.</param>
        /// <remarks>
        /// If the operation succeeds the callback will be invoked normally, if there is an error the callback will be invoked with a instance of <see cref="AsyncError"/> passed as the state which provides access to the error message and the original state passed in.
        /// </remarks>
        public void Validate(TripleStoreCallback callback, Object state)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Endpoint.Uri);

            request.Method = Endpoint.HttpMethods.First();
            request.Accept = MimeTypesHelper.CustomHttpAcceptHeader(MimeTypes, MimeTypesHelper.SupportedRdfDatasetMimeTypes);

            Tools.HttpDebugRequest(request);

            try
            {
                request.BeginGetResponse(result =>
                {
                    try
                    {
                        using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result))
                        {
                            Tools.HttpDebugResponse(response);
                            IStoreReader parser = MimeTypesHelper.GetStoreParser(response.ContentType);
                            TripleStore store   = new TripleStore();
                            parser.Load(store, new StreamReader(response.GetResponseStream()));

                            response.Close();
                            callback(store, state);
                        }
                    }
                    catch (WebException webEx)
                    {
                        if (webEx.Response != null)
                        {
                            Tools.HttpDebugResponse((HttpWebResponse)webEx.Response);
                        }
                        callback(null, new AsyncError(new RdfReasoningException("A HTTP error occurred while communicating with the Pellet Server, see inner exception for details", webEx), state));
                    }
                    catch (Exception ex)
                    {
                        callback(null, new AsyncError(new RdfReasoningException("An unexpected error occurred while communicating with the Pellet Server, see inner exception for details", ex), state));
                    }
                }, null);
            }
            catch (WebException webEx)
            {
                if (webEx.Response != null)
                {
                    Tools.HttpDebugResponse((HttpWebResponse)webEx.Response);
                }
                callback(null, new AsyncError(new RdfReasoningException("A HTTP error occurred while communicating with the Pellet Server, see inner exception for details", webEx), state));
            }
            catch (Exception ex)
            {
                callback(null, new AsyncError(new RdfReasoningException("An unexpected error occurred while communicating with the Pellet Server, see inner exception for details", ex), state));
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Attempts to load a RDF dataset asynchronously from the given URI into the given Triple Store.
 /// </summary>
 /// <param name="store">Triple Store to load into.</param>
 /// <param name="u">URI to attempt to get a RDF dataset from.</param>
 /// <param name="parser">Parser to use to parse the RDF dataset.</param>
 /// <param name="callback">Callback to invoke when the operation completes.</param>
 /// <param name="state">State to pass to the callback.</param>
 /// <remarks>
 /// <para>
 /// If the <paramref name="parser"/> parameter is set to null then this method attempts to select the relevant Store Parser based on the Content Type header returned in the HTTP Response.
 /// </para>
 /// <para>
 /// If you know ahead of time the Content Type you can explicitly pass in the parser to use.
 /// </para>
 /// <para>
 /// If the loading completes normally the callback will be invoked normally, if an error occurs it will be invoked and passed an instance of <see cref="AsyncError"/> as the state which contains details of the error and the original state.
 /// </para>
 /// </remarks>
 public static void Load(ITripleStore store, Uri u, IStoreReader parser, TripleStoreCallback callback, Object state)
 {
     if (store == null)
     {
         throw new RdfParseException("Cannot read a RDF dataset into a null Triple Store");
     }
     if (u == null)
     {
         throw new RdfParseException("Cannot read a RDF dataset from a null URI");
     }
     Load(new StoreHandler(store), u, parser, (_, s) => callback(store, s), state);
 }
Esempio n. 4
0
 /// <summary>
 /// Attempts to load a RDF dataset asynchronously from the given URI into the given Triple Store.
 /// </summary>
 /// <param name="store">Triple Store to load into.</param>
 /// <param name="u">URI to attempt to get a RDF dataset from.</param>
 /// <param name="callback">Callback to invoke when the operation completes.</param>
 /// <param name="state">State to pass to the callback.</param>
 /// <remarks>
 /// <para>
 /// Attempts to select the relevant Store Parser based on the Content Type header returned in the HTTP Response.
 /// </para>
 /// <para>
 /// If the loading completes normally the callback will be invoked normally, if an error occurs it will be invoked and passed an instance of <see cref="AsyncError"/> as the state which contains details of the error and the original state.
 /// </para>
 /// </remarks>
 public static void Load(ITripleStore store, Uri u, TripleStoreCallback callback, Object state)
 {
     Load(store, u, null, callback, state);
 }
Esempio n. 5
0
 /// <summary>
 /// Attempts to load a RDF dataset asynchronously from the given URI into the given Triple Store
 /// </summary>
 /// <param name="store">Triple Store to load into</param>
 /// <param name="u">URI to attempt to get a RDF dataset from</param>
 /// <param name="callback">Callback to invoke when the operation completes</param>
 /// <param name="state">State to pass to the callback</param>
 /// <remarks>
 /// <para>
 /// Attempts to select the relevant Store Parser based on the Content Type header returned in the HTTP Response.
 /// </para>
 /// </remarks>
 public static void Load(ITripleStore store, Uri u, TripleStoreCallback callback, Object state)
 {
     UriLoader.Load(store, u, null, callback, state);
 }
Esempio n. 6
0
 /// <summary>
 /// Attempts to load a RDF dataset asynchronously from the given URI into the given Triple Store
 /// </summary>
 /// <param name="store">Triple Store to load into</param>
 /// <param name="u">URI to attempt to get a RDF dataset from</param>
 /// <param name="parser">Parser to use to parse the RDF dataset</param>
 /// <param name="callback">Callback to invoke when the operation completes</param>
 /// <param name="state">State to pass to the callback</param>
 /// <remarks>
 /// <para>
 /// If the <paramref name="parser"/> parameter is set to null then this method attempts to select the relevant Store Parser based on the Content Type header returned in the HTTP Response.
 /// </para>
 /// <para>
 /// If you know ahead of time the Content Type you can explicitly pass in the parser to use.
 /// </para>
 /// </remarks>
 public static void Load(ITripleStore store, Uri u, IStoreReader parser, TripleStoreCallback callback, Object state)
 {
     if (store == null) throw new RdfParseException("Cannot read a RDF dataset into a null Triple Store");
     if (u == null) throw new RdfParseException("Cannot read a RDF dataset from a null URI");
     UriLoader.Load(new StoreHandler(store), u, parser, (_, s) => callback(store, s), state);
 }
        /// <summary>
        /// Extracts an RDF Dataset which details the Constraints violated (if any) and whether Constraints are satisified
        /// </summary>
        /// <param name="callback">Callback to invoke when the operation completes</param>
        /// <param name="state">State to pass to the callback</param>
        public void Validate(TripleStoreCallback callback, Object state)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Endpoint.Uri);
            request.Method = this.Endpoint.HttpMethods.First();
            request.Accept = MimeTypesHelper.CustomHttpAcceptHeader(this.MimeTypes, MimeTypesHelper.SupportedRdfDatasetMimeTypes);

            #if DEBUG
            if (Options.HttpDebugging)
            {
                Tools.HttpDebugRequest(request);
            }
            #endif

            request.BeginGetResponse(result =>
                {
                    using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result))
                    {
            #if DEBUG
                        if (Options.HttpDebugging)
                        {
                            Tools.HttpDebugResponse(response);
                        }
            #endif
                        IStoreReader parser = MimeTypesHelper.GetStoreParser(response.ContentType);
                        TripleStore store = new TripleStore();
                        StreamParams parameters = new StreamParams(response.GetResponseStream());
                        parser.Load(store, parameters);

                        response.Close();
                        callback(store, state);
                    }
                }, null);
        }