public void Run(string uri) { // Declaration of all the pipeline blocks GetTopStoriesBlock getTopStories = new GetTopStoriesBlock(); FilterTopStoriesBlock filterTopStories = new FilterTopStoriesBlock(); TraverseTopStoriesCommentsBlock traverseTopStoriesComments = new TraverseTopStoriesCommentsBlock(); ComputeTopCommentsPerStoryBlock computeTopCommentsPerStory = new ComputeTopCommentsPerStoryBlock(); // Links and interactions betwen each block getTopStories.block.LinkTo(filterTopStories.block, this.linkOptions); filterTopStories.bufferBlock.LinkTo(traverseTopStoriesComments.block, linkOptions); traverseTopStoriesComments.bufferBlock.LinkTo(computeTopCommentsPerStory.block, linkOptions); // Triggering the start of the pipeline getTopStories.block.Post(uri); getTopStories.block.Complete(); // Buffer at the end of the pipeline var receiveAllStories = Task.Run(() => { for (int i = 0; i <= Constants.NBSTORIES; i++) { this.topStories.Add(computeTopCommentsPerStory.bufferBlock.Receive()); // Wait for all the Top Story objects to arrive } }); Task.WaitAll(receiveAllStories); computeTopCommentsPerStory.bufferBlock.Complete(); //End of the pipeline commentsRegistry = traverseTopStoriesComments.commentsRegistry; printResults(); }
public void TraverseTopStoriesCommentsBlock() { Item story = new Item(); story.Id = 21021709; story.Kids = new List <int>(21021916); story.Dead = false; story.Deleted = false; TraverseTopStoriesCommentsBlock traverseTopStoriesComments = new TraverseTopStoriesCommentsBlock(); traverseTopStoriesComments.block.Post(story); var result = traverseTopStoriesComments.bufferBlock.ReceiveAsync().Result; Assert.IsNotNull(result.Comments); }