private void createAndStartThreads() { try { int threadCount = Convert.ToInt16(cmbThreadCount.Text); if (threadCount > users.Count) { threadCount = users.Count; } if (searchStrings.Count == 0) { MessageBox.Show("Enter search criterias."); return; } IList <IList <User> > listofUsers = new List <IList <User> >(); for (int i = 0; i < threadCount; i++) { listofUsers.Add(new List <User>()); } for (int i = 0; i < users.Count; i++) { listofUsers[i % threadCount].Add(users[i]); } IList <VideoExtractorAndCommenter> extractorAndCommenters = new List <VideoExtractorAndCommenter>(); for (int i = 0; i < threadCount; i++) { IAdapter adapter = new WebAdapter(searchStrings[i % searchStrings.Count], 1); IYouTubeAccountPool pool = new YouTubeAccountPool(listofUsers[i], (int)delayMinute.Value); ICommentRepository commentRepository = new CommentRepository(); IVideoCommenter videoCommenter = new VideoCommenter(pool, commentRepository); VideoExtractorAndCommenter videoExtractorAndCommenter = new VideoExtractorAndCommenter(adapter, videoCommenter, (int)minViewCount.Value); extractorAndCommenters.Add(videoExtractorAndCommenter); } for (int i = threadCount; i < searchStrings.Count; i++) { extractorAndCommenters[i % threadCount].addSearchStringPhrase(searchStrings[i]); } foreach (VideoExtractorAndCommenter commenter in extractorAndCommenters) { threads.Add(new System.Threading.Thread(new System.Threading.ThreadStart(commenter.extractVideosAndInsertAComment)) { IsBackground = true }); } for (int i = 0; i < threadCount; i++) { threads[i].Start(); } //new System.Threading.Thread(new System.Threading.ThreadStart(this.test)).Start(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public void getNextPageNumberzeroTest() { try { FileAdapter adapter = new FileAdapter("resources\\simple_page.htm"); VideoExtractorAndCommenter extractorAndCommenter = new VideoExtractorAndCommenter(adapter, 20); Assert.IsTrue(extractorAndCommenter.getNextPageNumber(adapter.readPageSource()) == 0); } catch (Exception e) { Assert.IsTrue(false, e.Message); } }
public void getRelatedVideoAddress3Test() { try { FileAdapter adapter = new FileAdapter("resources\\3_video.htm"); VideoExtractorAndCommenter extractorAndCommenter = new VideoExtractorAndCommenter(adapter, 20); Assert.IsTrue(extractorAndCommenter.getRelatedVideoAddress(adapter.getUrl()).Count == 19); } catch (Exception e) { Assert.IsTrue(false, e.Message); } }
public void VideoAddressExtractor5Test() { try { FileAdapter adapter = new FileAdapter("resources\\4_page.htm"); VideoExtractorAndCommenter extractorAndCommenter = new VideoExtractorAndCommenter(adapter, 20); IList <string> list = extractorAndCommenter.extractVideoAddresses(adapter.readPageSource()); Assert.IsTrue(list.Count == 16); } catch (Exception e) { Assert.IsTrue(false, e.Message); } }
public void extractVideosAndInsertACommentWithNoCommentTest() { try { IYouTubeAccountPool accountPool = new YouTubeAccountPool(YouTubeAccountPool.getUsersFromXml(), 5); ICommentRepository commentRepository = new CommentRepository(); IVideoCommenter videoCommenter = new VideoCommenter(accountPool, commentRepository); IAdapter adapter = new WebAdapter("test", 1); VideoExtractorAndCommenter extractorAndCommenter = new VideoExtractorAndCommenter(adapter, videoCommenter, 10); extractorAndCommenter.extractVideosAndInsertAComment(); } catch (Exception e) { Assert.IsTrue(false, e.Message); } }