コード例 #1
0
        /// <summary>
        /// Gets the list of available stores.
        /// </summary>
        /// <returns></returns>
        public virtual IEnumerable <String> ListStores()
        {
            try
            {
                HttpWebRequest request = CreateRequest("repositories", MimeTypesHelper.SparqlResultsXml[0], "GET", new Dictionary <string, string>());
                Tools.HttpDebugRequest(request);

                ListStringsHandler handler = new ListStringsHandler("id");
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    SparqlXmlParser parser = new SparqlXmlParser();
                    parser.Load(handler, new StreamReader(response.GetResponseStream()));
                    response.Close();
                }
                return(handler.Strings);
            }
            catch (WebException webEx)
            {
                throw StorageHelper.HandleHttpError(webEx, "listing Stores from");
            }
        }
コード例 #2
0
        /// <summary>
        /// Lists the available stores asynchronously.
        /// </summary>
        /// <param name="callback">Callback.</param>
        /// <param name="state">State to pass to the callback.</param>
        public virtual void ListStores(AsyncStorageCallback callback, Object state)
        {
            HttpWebRequest     request = CreateRequest("repositories", MimeTypesHelper.SparqlResultsXml[0], "GET", new Dictionary <string, string>());
            ListStringsHandler handler = new ListStringsHandler("id");

            try
            {
                request.BeginGetResponse(r =>
                {
                    try
                    {
                        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(r);
                        SparqlXmlParser parser   = new SparqlXmlParser();
                        parser.Load(handler, new StreamReader(response.GetResponseStream()));
                        response.Close();
                        callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListStores, handler.Strings), state);
                    }
                    catch (WebException webEx)
                    {
                        callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListStores, StorageHelper.HandleHttpError(webEx, "listing Stores from")), state);
                    }
                    catch (Exception ex)
                    {
                        callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListStores, StorageHelper.HandleError(ex, "listing Stores from")), state);
                    }
                }, state);
            }
            catch (WebException webEx)
            {
                callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListStores, StorageHelper.HandleHttpError(webEx, "listing Stores from")), state);
            }
            catch (Exception ex)
            {
                callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListStores, StorageHelper.HandleError(ex, "listing Stores from")), state);
            }
        }