Exemplo n.º 1
0
        protected override TaskValueResult <int> RunTaskInternal()
        {
            if (this._graphUri != null && !this._graphUri.Equals(String.Empty))
            {
                this.Information = "Counting Triples for Graph " + this._graphUri.ToString() + "...";
            }
            else
            {
                this.Information = "Counting Triples for Default Graph...";
            }

            this._counter   = new CountHandler();
            this._canceller = new CancellableHandler(this._counter);
            this._manager.LoadGraph(this._canceller, this._graphUri);
            this.Information = "Graph contains " + this._counter.Count + " Triple(s)";
            return(new TaskValueResult <int>(this._counter.Count));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs the task
        /// </summary>
        /// <returns></returns>
        protected override IGraph RunTaskInternal()
        {
            if (this._graphUri != null && !this._graphUri.Equals(String.Empty))
            {
                this.Information = "Previewing Graph " + this._graphUri + "...";
            }
            else
            {
                this.Information = "Previewing Default Graph...";
            }

            Graph g = new Graph();

            this._canceller = new CancellableHandler(new PagingHandler(new GraphHandler(g), this._previewSize));
            this._manager.LoadGraph(this._canceller, this._graphUri);
            this.Information = "Previewed Graph previews first " + g.Triples.Count + " Triple(s)";
            return(g);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Implementation of the task
        /// </summary>
        /// <returns></returns>
        protected sealed override TaskResult RunTaskInternal()
        {
            if (this._manager.UpdateSupported)
            {
                //Use a WriteToStoreHandler for direct writing
                this._canceller = new CancellableHandler(new WriteToStoreHandler(this._manager, this.GetTargetUri(), this._batchSize));
                if (this.HasBeenCancelled)
                {
                    this._canceller.Cancel();
                }

                //Wrap in a ChainedHandler to ensure we permit cancellation but also count imported triples
                ChainedHandler m = new ChainedHandler(new IRdfHandler[] { this._canceller, this._progress });
                this.ImportUsingHandler(m);
            }
            else
            {
                //Use a StoreHandler to load into memory and will do a SaveGraph() at the end
                TripleStore store = new TripleStore();
                this._canceller = new CancellableHandler(new StoreHandler(store));
                if (this.HasBeenCancelled)
                {
                    this._canceller.Cancel();
                }

                //Wrap in a ChainedHandler to ensure we permit cancellation but also count imported triples
                ChainedHandler m = new ChainedHandler(new IRdfHandler[] { this._canceller, this._progress });
                this.ImportUsingHandler(m);

                //Finally Save to the underlying Store
                foreach (IGraph g in store.Graphs)
                {
                    if (g.BaseUri == null)
                    {
                        g.BaseUri = this.GetTargetUri();
                    }
                    this._manager.SaveGraph(g);
                }
            }
            this.Information = this._counter.TripleCount + " Triple(s) in " + this._counter.GraphCount + " Graph(s) Imported";

            return(new TaskResult(true));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Runs the task
        /// </summary>
        /// <returns></returns>
        protected override TaskResult RunTaskInternal()
        {
            if (this.Target.IsReadOnly)
            {
                throw new RdfStorageException("Cannot Copy/Move a Graph when the Target is a read-only Store!");
            }

            switch (this.Name)
            {
            case "Rename":
            case "Move":
                //Move/Rename a Graph
                if (ReferenceEquals(this.Source, this.Target) && this.Source.StorageProvider is IUpdateableStorage)
                {
                    //If the Source and Target are identical and it supports SPARQL Update natively then we'll just issue a MOVE command
                    this.Information = "Issuing a MOVE command to rename Graph '" + this._sourceUri.ToSafeString() + "' to '" + this._targetUri.ToSafeString() + "'";
                    SparqlParameterizedString update = new SparqlParameterizedString {
                        CommandText = "MOVE"
                    };
                    if (this._sourceUri == null)
                    {
                        update.CommandText += " DEFAULT TO";
                    }
                    else
                    {
                        update.CommandText += " GRAPH @source TO";
                        update.SetUri("source", this._sourceUri);
                    }
                    if (this._targetUri == null)
                    {
                        update.CommandText += " DEFAULT";
                    }
                    else
                    {
                        update.CommandText += " GRAPH @target";
                        update.SetUri("target", this._targetUri);
                    }
                    ((IUpdateableStorage)this.Source.StorageProvider).Update(update.ToString());
                    this.Information = "MOVE command completed OK, Graph renamed to '" + this._targetUri.ToSafeString() + "'";
                }
                else
                {
                    //Otherwise do a load of the source graph writing through to the target graph
                    IRdfHandler handler;
                    IGraph      g = null;
                    if (this.Target.StorageProvider.UpdateSupported)
                    {
                        //If Target supports update then we'll use a WriteToStoreHandler combined with a GraphUriRewriteHandler
                        handler = new WriteToStoreHandler(this.Target.StorageProvider, this._targetUri);
                        handler = new GraphUriRewriteHandler(handler, this._targetUri);
                    }
                    else
                    {
                        //Otherwise we'll use a GraphHandler and do a save at the end
                        g       = new Graph();
                        handler = new GraphHandler(g);
                    }
                    handler         = new CopyMoveProgressHandler(handler, this, "Moving", this.Target.StorageProvider.UpdateSupported);
                    this._canceller = new CancellableHandler(handler);
                    if (this.HasBeenCancelled)
                    {
                        this._canceller.Cancel();
                    }

                    //Now start reading out the data
                    this.Information = "Copying data from Graph '" + this._sourceUri.ToSafeString() + "' to '" + this._targetUri.ToSafeString() + "'";
                    this.Source.StorageProvider.LoadGraph(this._canceller, this._sourceUri);

                    //If we weren't moving the data directly need to save the resulting graph now
                    if (g != null)
                    {
                        this.Information = "Saving copied data to Target Store...";
                        this.Target.StorageProvider.SaveGraph(g);
                    }

                    //And finally since we've done a copy (not a move) so far we need to delete the original graph
                    //to effect a rename
                    if (this.Source.StorageProvider.DeleteSupported)
                    {
                        this.Information = "Removing source graph to complete the move operation";
                        this.Source.StorageProvider.DeleteGraph(this._sourceUri);

                        this.Information = "Move completed OK, Graph moved to '" + this._targetUri.ToSafeString() + "'" + (ReferenceEquals(this.Source, this.Target) ? String.Empty : " on " + this.Target);
                    }
                    else
                    {
                        this.Information = "Copy completed OK, Graph copied to '" + this._targetUri.ToSafeString() + "'" + (ReferenceEquals(this.Source, this.Target) ? String.Empty : " on " + this.Target) + ".  Please note that as the Source Triple Store does not support deleting Graphs so the Graph remains present in the Source Store";
                    }
                }

                break;

            case "Copy":
                if (ReferenceEquals(this.Source, this.Target) && this.Source.StorageProvider is IUpdateableStorage)
                {
                    //If the Source and Target are identical and it supports SPARQL Update natively then we'll just issue a COPY command
                    this.Information = "Issuing a COPY command to copy Graph '" + this._sourceUri.ToSafeString() + "' to '" + this._targetUri.ToSafeString() + "'";
                    SparqlParameterizedString update = new SparqlParameterizedString();
                    update.CommandText = "COPY";
                    if (this._sourceUri == null)
                    {
                        update.CommandText += " DEFAULT TO";
                    }
                    else
                    {
                        update.CommandText += " GRAPH @source TO";
                        update.SetUri("source", this._sourceUri);
                    }
                    if (this._targetUri == null)
                    {
                        update.CommandText += " DEFAULT";
                    }
                    else
                    {
                        update.CommandText += " GRAPH @target";
                        update.SetUri("target", this._targetUri);
                    }
                    ((IUpdateableStorage)this.Source.StorageProvider).Update(update.ToString());
                    this.Information = "COPY command completed OK, Graph copied to '" + this._targetUri.ToSafeString() + "'";
                }
                else
                {
                    //Otherwise do a load of the source graph writing through to the target graph
                    IRdfHandler handler;
                    IGraph      g = null;
                    if (this.Target.StorageProvider.UpdateSupported)
                    {
                        //If Target supports update then we'll use a WriteToStoreHandler combined with a GraphUriRewriteHandler
                        handler = new WriteToStoreHandler(this.Target.StorageProvider, this._targetUri);
                        handler = new GraphUriRewriteHandler(handler, this._targetUri);
                    }
                    else
                    {
                        //Otherwise we'll use a GraphHandler and do a save at the end
                        g       = new Graph();
                        handler = new GraphHandler(g);
                    }
                    handler         = new CopyMoveProgressHandler(handler, this, "Copying", this.Target.StorageProvider.UpdateSupported);
                    this._canceller = new CancellableHandler(handler);
                    if (this.HasBeenCancelled)
                    {
                        this._canceller.Cancel();
                    }

                    //Now start reading out the data
                    this.Information = "Copying data from Graph '" + this._sourceUri.ToSafeString() + "' to '" + this._targetUri.ToSafeString() + "'";
                    this.Source.StorageProvider.LoadGraph(this._canceller, this._sourceUri);

                    //If we weren't moving the data directly need to save the resulting graph now
                    if (g != null)
                    {
                        this.Information = "Saving copied data to Store...";
                        this.Target.StorageProvider.SaveGraph(g);
                    }

                    this.Information = "Copy completed OK, Graph copied to '" + this._targetUri.ToSafeString() + "'" + (ReferenceEquals(this.Source, this.Target) ? String.Empty : " on " + this.Target.ToString());
                }

                break;
            }

            return(new TaskResult(true));
        }