/// <summary> /// Thread Worker method which writes Graphs to the output /// </summary> /// <param name="globalContext">Context for writing the Store</param> private void SaveGraphs(ThreadedStoreWriterContext globalContext) { try { Uri u = globalContext.GetNextUri(); while (u != null) { //Get the Graph from the Store if (WriterHelper.IsDefaultGraph(u) && !globalContext.Store.HasGraph(u)) u = null; IGraph g = globalContext.Store.Graphs[u]; //Generate the Graph Output and add to Stream NTriplesWriterContext context = new NTriplesWriterContext(g, new System.IO.StringWriter(), globalContext.PrettyPrint, globalContext.HighSpeedModePermitted); String graphContent = this.GraphToNQuads(globalContext, context); if (!graphContent.Equals(String.Empty)) { try { Monitor.Enter(globalContext.Output); globalContext.Output.WriteLine(graphContent); globalContext.Output.Flush(); } catch { throw; } finally { Monitor.Exit(globalContext.Output); } } //Get the Next Uri u = globalContext.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); } }
/// <summary> /// Thread Worker method which writes Graphs to the output /// </summary> /// <param name="globalContext">Context for writing the Store</param> private void SaveGraphs(ThreadedStoreWriterContext globalContext) { try { Uri u = globalContext.GetNextUri(); while (u != null) { //Get the Graph from the Store IGraph g = globalContext.Store.Graphs[u]; //Generate the Graph Output and add to Stream BaseWriterContext context = new BaseWriterContext(g, new System.IO.StringWriter()); String graphContent = this.GenerateGraphOutput(globalContext, context); try { Monitor.Enter(globalContext.Output); globalContext.Output.WriteLine(graphContent); globalContext.Output.Flush(); } catch { throw; } finally { Monitor.Exit(globalContext.Output); } //Get the Next Uri u = globalContext.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); } }