/// <summary>
        /// Saves the given Triple Store to an arbitrary store
        /// </summary>
        /// <param name="store">Store to Save</param>
        /// <param name="parameters">Parameters for the Store</param>
        /// <remarks>
        /// Parameters must be of type <see cref="GenericIOParams">GenericIOParams</see>
        /// </remarks>
        public void Save(ITripleStore store, IStoreParams parameters)
        {
            if (parameters is GenericIOParams)
            {
                //Create the Writer Context
                GenericStoreWriterContext context = new GenericStoreWriterContext(store, (GenericIOParams)parameters);

                //Queue Graphs for Writing
                foreach (IGraph g in store.Graphs)
                {
                    context.Add(g.BaseUri);
                }
                
                //Start making the async calls
                List<IAsyncResult> results = new List<IAsyncResult>();
                WriteGraphsDelegate d = new WriteGraphsDelegate(this.WriteGraphs);
                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());
                RdfThreadedOutputException outputEx = new RdfThreadedOutputException(WriterErrorMessages.ThreadedOutputFailure("TSV"));
                foreach (IAsyncResult result in results)
                {
                    try
                    {
                        d.EndInvoke(result);
                    }
                    catch (Exception ex)
                    {
                        outputEx.AddException(ex);
                    }
                }

                //If there were any errors we'll throw an RdfThreadedOutputException now
                if (outputEx.InnerExceptions.Any()) throw outputEx;
            }
            else
            {
                throw new RdfStorageException("Parameters for the GenericStoreWriter must be of type GenericIOParams");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Internal Worker method for Writer Threads
        /// </summary>
        /// <param name="context">Context for writing the Store</param>
        private void WriteGraphs(GenericStoreWriterContext context)
        {
            try
            {
                Uri u = context.GetNextURI();
                while (u != null)
                {
                    //Get the Graph from the Store
                    IGraph g = context.Store.Graph(u);

                    //Write the Graph to the Target Store
                    context.Manager.SaveGraph(g);

                    //Get Next Graph Uri
                    u = context.GetNextURI();
                }
            }
            catch (ThreadAbortException)
            {
                //We've been terminated, don't do anything
            #if !SILVERLIGHT
                Thread.ResetAbort();
            #endif
            }
            catch (Exception ex)
            {
                throw new RdfStorageException("Error in Threaded Writer in Thread ID " + Thread.CurrentThread.ManagedThreadId, ex);
            }
        }