private void Expand(ExpansionContext context) { while (context.Uris.Count > 0) { //Get the next URI to expand upon and check it's not above the max expansion depth //Or that it's already a Graph in the Store UriToExpand u = context.GetNextUri();//context.Uris.Dequeue(); if (u == null) { return; } Debug.WriteLine("Expanding URI <" + u.Uri.ToString() + "> at Depth " + u.Depth); Debug.WriteLine(context.Uris.Count + " remaining to expand"); Debug.WriteLine("Got " + context.Store.Graphs.Count + " Graphs so far"); if (u.Depth > context.Profile.MaxExpansionDepth) { continue; } if (context.Store.HasGraph(u.Uri)) { continue; } //Try and retrieve RDF from the next URI Graph g = new Graph(); try { UriLoader.Load(g, u.Uri); } catch (RdfException rdfEx) { //Ignore this.DebugErrors("Error: Tried to expand URI <" + u.Uri.ToString() + "> but an RDF Error occurred", rdfEx); } catch (WebException webEx) { //Ignore this.DebugErrors("Error: Tried to expand URI <" + u.Uri.ToString() + "> but a HTTP Error occurred", webEx); } ExpandGraph(u, g, context); //If we've got any URIs to expand and we're not already multi-threading then spawn some //threads to share out the work if (!context.MultiThreading && context.Uris.Count > 0) { //REQ: Convert to an IAsyncResult pattern context.MultiThreading = true; List <Thread> threads = new List <Thread>(); for (int i = 0; i < Math.Min(context.Uris.Count, this._threadsToUse); i++) { threads.Add(new Thread(new ThreadStart(delegate { this.Expand(context); }))); } threads.ForEach(t => t.Start()); while (threads.Any(t => t.ThreadState == System.Threading.ThreadState.Running)) { Thread.Sleep(ThreadPollingInterval); } context.MultiThreading = false; } } }
private void Expand(ExpansionContext context) { while (context.Uris.Count > 0) { //Get the next URI to expand upon and check it's not above the max expansion depth //Or that it's already a Graph in the Store UriToExpand u = context.GetNextUri();//context.Uris.Dequeue(); if (u == null) return; Debug.WriteLine("Expanding URI <" + u.Uri.ToString() + "> at Depth " + u.Depth); Debug.WriteLine(context.Uris.Count + " remaining to expand"); Debug.WriteLine("Got " + context.Store.Graphs.Count + " Graphs so far"); if (u.Depth > context.Profile.MaxExpansionDepth) continue; if (context.Store.HasGraph(u.Uri)) continue; //Try and retrieve RDF from the next URI Graph g = new Graph(); try { UriLoader.Load(g, u.Uri); } catch (RdfException rdfEx) { //Ignore this.DebugErrors("Error: Tried to expand URI <" + u.Uri.ToString() + "> but an RDF Error occurred", rdfEx); } catch (WebException webEx) { //Ignore this.DebugErrors("Error: Tried to expand URI <" + u.Uri.ToString() + "> but a HTTP Error occurred", webEx); } ExpandGraph(u, g, context); //If we've got any URIs to expand and we're not already multi-threading then spawn some //threads to share out the work if (!context.MultiThreading && context.Uris.Count > 0) { //REQ: Convert to an IAsyncResult pattern context.MultiThreading = true; List<Thread> threads = new List<Thread>(); for (int i = 0; i < Math.Min(context.Uris.Count, this._threadsToUse); i++) { threads.Add(new Thread(new ThreadStart(delegate { this.Expand(context); }))); } threads.ForEach(t => t.Start()); while (threads.Any(t => t.ThreadState == System.Threading.ThreadState.Running)) { Thread.Sleep(ThreadPollingInterval); } context.MultiThreading = false; } } }