private string ProcessUrls(IEnumerable<string> links, string content)
{
string result = content;
// REVIEW: is this safe to do? We're holding on to this instance
// when this should really be a fire and forget.
var contentTasks = links.Select(_resourceProcessor.ExtractResource).ToArray();
var end = Task.Factory.ContinueWhenAll(contentTasks, tasks =>
{
foreach (var task in tasks)
{
if (task.IsFaulted)
{
Trace.TraceError(task.Exception.GetBaseException().Message);
continue;
}
if (task.Result == null || String.IsNullOrEmpty(task.Result.Content))
{
continue;
}
// Try to get content from each url we're resolved in the query
string extractedContent = "<p>" + task.Result.Content + "</p>";
// If we did get something, update the message and notify all clients
result += extractedContent;
}
});
end.Wait();
return result;
}