/// <summary> /// Initializes the control with a crawler object. /// </summary> /// <param name="crawler">The crawler object.</param> public void Initialize(Crawler crawler) { // Save the parameters. this.crawler = crawler; this.request = new YouTubeRequestFeed<Video>(this.crawler.YouTube.Settings); // Enable the control this.Enabled = true; }
// Public methods. /// <summary> /// Initializes the control with a crawler object. /// </summary> /// <param name="crawler">The crawler object.</param> public void Initialize(Crawler crawler) { // Save the parameters. this.crawler = crawler; this.request = new YouTubeRequestFeed<Video>(this.crawler.YouTube.Settings); // Enable the control. this.Enabled = true; // Update the categories. this.OnUpdateCategories(this, EventArgs.Empty); }
/// <summary> /// Initializes the control with a crawler object. /// </summary> /// <param name="crawler">The crawler object.</param> /// <param name="delegateFeed">The feed event handler.</param> /// <param name="idName">The ID name.</param> /// <param name="feedName">The feed name.</param> /// <param name="objectName">The object name.</param> /// <param name="logSource">The log source.</param> public void Initialize(Crawler crawler, VideosFeedEventHandler delegateFeed, string idName, string feedName, string objectName, string logSource) { // Save the parameters. this.crawler = crawler; this.delegateFeed = delegateFeed; this.labelId.Text = idName; this.feedName = feedName; this.objectName = objectName; this.logSource = logSource; this.request = new YouTubeRequestFeed<Video>(this.crawler.YouTube.Settings); // Enable the control this.Enabled = true; }
// Private methods. /// <summary> /// Crawls the feed at the specified parameters. /// </summary> /// <param name="asyncResult">The asynchronous result.</param> /// <param name="feedId">The feed.</param> /// <param name="timeId">The time.</param> /// <param name="category">The category.</param> /// <param name="regionId">The region.</param> /// <param name="obj">The standard feed object.</param> /// <returns>The crawl result.</returns> private CrawlResult CrawlFeed( SpiderAsyncResult asyncResult, YouTubeStandardFeed feedId, YouTubeTimeId timeId, string category, string regionId, ref DbObjectStandardFeed obj) { // If the asynchronousn operation has been canceled, do nothing. if (asyncResult.IsCanceled) return CrawlResult.Canceled; // Compute the feed key. string key = this.EncodeFeedKey(feedId, timeId, category, regionId); // Compute the feed URI starting at index 1 and ask for 1 result. Uri uri = YouTubeUri.GetStandardFeed(feedId, regionId, category, timeId, 1, 1); // Create a new video request. YouTubeRequestFeed<Video> request = new YouTubeRequestFeed<Video>(this.crawler.YouTube.Settings); // Set the feed URL. obj.Url = uri.AbsoluteUri; try { // Begin an asynchronous request for the standard feed. AsyncWebResult result = request.Begin(uri, (AsyncWebResult webResult) => { }) as AsyncWebResult; // Add the result of the web operation to the collection of web requests. AsyncWebOperation operation = asyncResult.AddAsyncWeb(request, result); // Wait for the asynchronous operation to complete. result.AsyncWaitHandle.WaitOne(); // Remove the result of the web operation from the collection of web requests. asyncResult.RemoveAsyncWeb(operation); // Complete the request and get the video feed. Feed<Video> feed = request.End(result); // If the operation completed successfully, set the browsable to true. obj.Browsable = true; // Set the response HTTP code. obj.HttpCode = (int)(result as AsyncWebResult).Response.StatusCode; // Return the result. return (feed.FailuresAtom.Count == 0) && (feed.FailuresEntry.Count == 0) ? CrawlResult.Success : CrawlResult.Warning; } catch (WebException exception) { if (exception.Status == WebExceptionStatus.RequestCanceled) { return CrawlResult.Canceled; } else { // If the operation failed with a web exception, set the browsable to false. obj.Browsable = false; // Set the response HTTP code. obj.HttpCode = (int)(exception.Response as HttpWebResponse).StatusCode; // Return the result. return CrawlResult.Fail; } } catch (Exception) { // If the operation failed with a web exception, set the browsable to false. obj.Browsable = false; // Set the response HTTP code to null. obj.HttpCode = null; // Return the result. return CrawlResult.Fail; } }