/// <summary> /// Lists the graph sin the Store asynchronously /// </summary> /// <param name="callback">Callback</param> /// <param name="state">State to pass to the callback</param> public override void ListGraphs(AsyncStorageCallback callback, object state) { // Use ListUrisHandler and make an async query to list the graphs, when that returns we invoke the correct callback ListUrisHandler handler = new ListUrisHandler("g"); ((IAsyncQueryableStorage)this).Query(null, handler, "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } }", (sender, args, st) => { if (args.WasSuccessful) { callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, handler.Uris), state); } else { callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, args.Error), state); } }, state); }
/// <summary> /// Lists the Graphs from the Repository /// </summary> /// <param name="callback">Callback</param> /// <param name="state">State to pass to the callback</param> /// <returns></returns> public override void ListGraphs(AsyncStorageCallback callback, Object state) { try { //Use the /contexts method to get the Graph URIs //HACK: Have to use SPARQL JSON as currently Dydra's SPARQL XML Results are malformed HttpWebRequest request = this.CreateRequest("/contexts", MimeTypesHelper.CustomHttpAcceptHeader(MimeTypesHelper.SparqlResultsJson), "GET", new Dictionary <string, string>()); request.BeginGetResponse(r => { try { HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(r); ISparqlResultsReader parser = MimeTypesHelper.GetSparqlParser(response.ContentType); ListUrisHandler handler = new ListUrisHandler("contextID"); parser.Load(handler, new StreamReader(response.GetResponseStream())); response.Close(); callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, handler.Uris), state); } catch (WebException webEx) { callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, StorageHelper.HandleHttpError(webEx, "list Graphs asynchronously from")), state); } catch (Exception ex) { callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, StorageHelper.HandleError(ex, "list Graphs asynchronously from")), state); } }, state); } catch (WebException webEx) { callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, StorageHelper.HandleHttpError(webEx, "list Graphs asynchronously from")), state); } catch (Exception ex) { callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, StorageHelper.HandleError(ex, "list Graphs asynchronously from")), state); } }
/// <summary> /// Lists the Graphs in the Store asynchronously /// </summary> /// <param name="callback">Callback</param> /// <param name="state">State to pass to the callback</param> public virtual void ListGraphs(AsyncStorageCallback callback, object state) { if (this is IAsyncQueryableStorage) { //Use ListUrisHandler and make an async query to list the graphs, when that returns we invoke the correct callback ListUrisHandler handler = new ListUrisHandler("g"); ((IAsyncQueryableStorage)this).Query(null, handler, "SELECT DISTINCT ?g WHERE { GRAPH ?g { ?s ?p ?o } }", (sender, args, st) => { if (args.WasSuccessful) { callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, handler.Uris), state); } else { callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, args.Error), state); } }, state); } else { callback(this, new AsyncStorageCallbackArgs(AsyncStorageOperation.ListGraphs, new RdfStorageException("Underlying store does not supported listing graphs asynchronously or has failed to appropriately override this method")), state); } }