示例#1
0
        private async void search_Click(object sender, RoutedEventArgs e)
        {
            List <Website> allSites = TheInternet.ReadFile();

            var searchInput = Observable.FromEventPattern(this.textBox, "TextChanged")
                              .Select(w => this.textBox.Text)
                              .Where(n => n.Count() > 3)
                              .Throttle(TimeSpan.FromSeconds(0.5))
                              .DistinctUntilChanged();


            Tools.DebugTrace("ctor", Thread.CurrentThread.ManagedThreadId);
            Tools.DebugTrace(searchInput.ToString(), Thread.CurrentThread.ManagedThreadId);

            //var res = await Task.Run( () => SearchEngine.SearchWebSites(allSites, searchInput.ToString()) );
            foreach (var site in allSites)
            {
                var res = await Task.Run(() => SearchEngine.Search(site, searchInput.ToString()));

                res.ToObservable()
                .ObserveOn(Dispatcher)
                .Select(x => x)
                .Subscribe(y => PopulateView(site, y));
            }
        }
示例#2
0
        public async void DisplayBulkHeadLines(WebsiteType type, int headlines)
        {
            int            countSites = 0;
            List <Website> allSites   = TheInternet.ReadFile(type);
            int            totalSites = (allSites.Count() == 0) ? 1:allSites.Count();

            if (this.listView.Items.Count > 0)
            {
                this.listView.Items.Clear();
            }
            if (this.sitelistBox.Items.Count > 0)
            {
                this.sitelistBox.Items.Clear();
            }

            PopulateSiteListbox();



            foreach (var site in allSites)
            {
                Tools.DebugTrace("siteloop", Thread.CurrentThread.ManagedThreadId);

                countSites++;
                var data = await Task.Run(() => Downloader.DownloadHtml(site));

                var listView = data.ToObservable()
                               .ObserveOn(Dispatcher)
                               .Where(x => x.Length > 5)
                               .Select(x => x.Trim())
                               .Take(headlines)
                               .Subscribe(x => PopulateView(site, x));

                statusLabel = data.ToObservable()
                              .ObserveOn(Dispatcher)
                              .Subscribe(x => PopulateLabel($"From {site.SiteName}  |  Feteched {countSites} of {totalSites}"));
            }
            statusLabel.Dispose();
        }
示例#3
0
 public void PopulateSiteListbox()
 {
     TheInternet.ReadFile().ForEach(site => this.sitelistBox.Items.Add(site.SiteName));
 }