public FeedAsync ( string feeduri, int itemCount ) : void | ||
feeduri | string | |
itemCount | int | |
리턴 | void |
public void FeedAsync(string feeduri, int itemCount)
{
AsyncManager.OutstandingOperations.Increment();
if(HttpRuntime.Cache.IsEmpty(feeduri))
{
_feedfactory.BeginCreateFeed(new Uri(feeduri),
async =>
AsyncManager.Sync(() =>
{
var feed = _feedfactory.EndCreateFeed(async);
AsyncManager.Parameters["feed"] = feed;
AsyncManager.Parameters["itemCount"] = itemCount;
HttpRuntime.Cache.Insert(feeduri, feed, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 20, 0));
AsyncManager.OutstandingOperations.Decrement();
}));
}
else
{
AsyncManager.Sync(() =>
{
AsyncManager.Parameters["feed"] = HttpRuntime.Cache[feeduri];
AsyncManager.Parameters["itemCount"] = itemCount;
AsyncManager.OutstandingOperations.Decrement();
});
}
}
public void CanQueryFeedsInBulk() { var controller = new FeedController(_factory); var waitHandle = new AutoResetEvent(false); IFeedLocationService locationService = new FakeFeedLocationService(); // Create and attach event handler for the "Finished" event EventHandler eventHandler = (sender, e) => waitHandle.Set(); controller.AsyncManager.Finished += eventHandler; foreach(var item in locationService.GetFeeds()) { if (_factory.PingFeed(item)) { controller.FeedAsync(item.AbsoluteUri, ItemCount); const int msTimeout = 5000; if (!waitHandle.WaitOne(msTimeout, false)) { Assert.Fail("Test timed out."); } var response = controller.AsyncManager.Parameters["feed"] as IFeed; Assert.IsNotNull(response); Assert.AreEqual(item.AbsoluteUri, response.FeedUri.AbsoluteUri); var summary = FeedSummarizer.SummarizeFeed(response, ItemCount); Assert.AreEqual(summary.Items.Count, ItemCount); } else { Assert.Inconclusive(string.Format("Unable to ping feed at uri {0}", item)); } } }