예제 #1
0
        /// <summary>
        /// Loads RDF using the RDF Handler using the settings the Reader was instantiated with
        /// </summary>
        /// <param name="handler">RDF Handler to use</param>
        /// <param name="parameters">Parameters indicating where to read from</param>
        public void Load(IRdfHandler handler, IStoreParams parameters)
        {
            if (parameters is FolderStoreParams)
            {
                //Create the Parser Context
                FolderStoreParserContext context = new FolderStoreParserContext(handler, (FolderStoreParams)parameters);

                //Create the Folder
                if (!Directory.Exists(context.Folder))
                {
                    throw new RdfStorageException("Cannot read a Folder Store from a Folder that doesn't exist");
                }

                //Read list of Graphs and Queue Filenames of Graphs for reading by the Threads
                StreamReader graphlist = new StreamReader(Path.Combine(context.Folder, "graphs.fstore"));

                //First line contains format information
                String ext = graphlist.ReadLine();
                if (context.Format == FolderStoreFormat.AutoDetect)
                {
                    if (ext.Equals(".ttl"))
                    {
                        context.Format = FolderStoreFormat.Turtle;
                    }
                    else if (ext.Equals(".n3"))
                    {
                        context.Format = FolderStoreFormat.Notation3;
                    }
                    else if (ext.Equals(".rdf"))
                    {
                        context.Format = FolderStoreFormat.RdfXml;
                    }
                    else
                    {
                        throw new RdfStorageException("Folder Store Format auto-detection failed");
                    }
                }

                String file;
                while (!graphlist.EndOfStream)
                {
                    file = graphlist.ReadLine();
                    if (!file.Equals(String.Empty))
                    {
                        context.Add(file);
                    }
                }
                graphlist.Close();

                //Start making the async calls
                List <IAsyncResult> results = new List <IAsyncResult>();
                LoadGraphsDelegate  d       = new LoadGraphsDelegate(this.LoadGraphs);
                for (int i = 0; i < context.Threads; i++)
                {
                    results.Add(d.BeginInvoke(context, null, null));
                }

                //Wait for all the async calls to complete
                WaitHandle.WaitAll(results.Select(r => r.AsyncWaitHandle).ToArray());
                RdfThreadedParsingException parsingEx = new RdfThreadedParsingException("One/more errors occurred while parsing RDF from a Folder Store using a multi-threaded parsing process");
                foreach (IAsyncResult result in results)
                {
                    try
                    {
                        d.EndInvoke(result);
                    }
                    catch (Exception ex)
                    {
                        parsingEx.AddException(ex);
                    }
                }

                //If there were any errors we'll throw an RdfThreadedOutputException now
                if (parsingEx.InnerExceptions.Any())
                {
                    throw parsingEx;
                }
            }
            else
            {
                throw new RdfStorageException("Parameters for the FolderStoreReader must be of type FolderStoreParams");
            }
        }
예제 #2
0
        /// <summary>
        /// Loads RDF using the RDF Handler using the settings the Reader was instantiated with
        /// </summary>
        /// <param name="handler">RDF Handler to use</param>
        /// <param name="parameters">Parameters indicating where to read from</param>
        public void Load(IRdfHandler handler, IStoreParams parameters)
        {
            if (parameters is FolderStoreParams)
            {
                //Create the Parser Context
                FolderStoreParserContext context = new FolderStoreParserContext(handler, (FolderStoreParams)parameters);

                //Create the Folder
                if (!Directory.Exists(context.Folder))
                {
                    throw new RdfStorageException("Cannot read a Folder Store from a Folder that doesn't exist");
                }

                //Read list of Graphs and Queue Filenames of Graphs for reading by the Threads
                StreamReader graphlist = new StreamReader(Path.Combine(context.Folder, "graphs.fstore"));

                //First line contains format information
                String ext = graphlist.ReadLine();
                if (context.Format == FolderStoreFormat.AutoDetect)
                {
                    if (ext.Equals(".ttl"))
                    {
                        context.Format = FolderStoreFormat.Turtle;
                    }
                    else if (ext.Equals(".n3"))
                    {
                        context.Format = FolderStoreFormat.Notation3;
                    }
                    else if (ext.Equals(".rdf"))
                    {
                        context.Format = FolderStoreFormat.RdfXml;
                    }
                    else
                    {
                        throw new RdfStorageException("Folder Store Format auto-detection failed");
                    }
                }

                String file;
                while (!graphlist.EndOfStream)
                {
                    file = graphlist.ReadLine();
                    if (!file.Equals(String.Empty))
                    {
                        context.Add(file);
                    }
                }
                graphlist.Close();

                //Start making the async calls
                List<IAsyncResult> results = new List<IAsyncResult>();
                LoadGraphsDelegate d = new LoadGraphsDelegate(this.LoadGraphs);
                for (int i = 0; i < context.Threads; i++)
                {
                    results.Add(d.BeginInvoke(context, null, null));
                }

                //Wait for all the async calls to complete
                WaitHandle.WaitAll(results.Select(r => r.AsyncWaitHandle).ToArray());
                RdfThreadedParsingException parsingEx = new RdfThreadedParsingException("One/more errors occurred while parsing RDF from a Folder Store using a multi-threaded parsing process");
                foreach (IAsyncResult result in results)
                {
                    try
                    {
                        d.EndInvoke(result);
                    }
                    catch (Exception ex)
                    {
                        parsingEx.AddException(ex);
                    }
                }

                //If there were any errors we'll throw an RdfThreadedOutputException now
                if (parsingEx.InnerExceptions.Any()) throw parsingEx;
            }
            else
            {
                throw new RdfStorageException("Parameters for the FolderStoreReader must be of type FolderStoreParams");
            }
        }