Exemplo n.º 1
0
        public void ParsingRdfXmlStreamingDoesNotExhaustMemory()
        {
            IGraph         g            = new Graph();
            GraphHandler   graphHandler = new GraphHandler(g);
            PagingHandler  paging       = new PagingHandler(graphHandler, 1000);
            CountHandler   counter      = new CountHandler();
            ChainedHandler handler      = new ChainedHandler(new IRdfHandler[] { paging, counter });

            GZippedRdfXmlParser parser = new GZippedRdfXmlParser(RdfXmlParserMode.Streaming);

            parser.Load(handler, @"resources\oom.rdf.gz");

            Assert.False(g.IsEmpty);
            Assert.Equal(1000, counter.Count);
            // Note that the source produces some duplicate triples so triples in the graph will be at most 1000
            Assert.True(g.Triples.Count <= 1000);
        }
Exemplo n.º 2
0
 public override void ElementEnd(string element)
 {
     // chained handler gets first crack at this element
     if (ChainedHandler != null)
     {
         ChainedHandler.ElementEnd(element);
         // clean up if completed
         if (ChainedHandler.Completed())
         {
             CleanupChainedHandler();
         }
     }
     else
     {
         ElementEndLocal(element);
     }
 }
Exemplo n.º 3
0
 public override void ElementStart(string element, XMLAttributes attributes)
 {
     // chained handler gets first crack at this element
     if (ChainedHandler != null)
     {
         ChainedHandler.ElementStart(element, attributes);
         // clean up if completed
         if (ChainedHandler.Completed())
         {
             CleanupChainedHandler();
         }
     }
     else
     {
         ElementStartLocal(element, attributes);
     }
 }
Exemplo n.º 4
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));
        }