private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     Dispatch(new Action(() => viewModel.IsSearching = false));
     Dispatch(new Action(() => SearchCompleted?.Invoke(this, new QueryProcessManagerArgs {
         Error = LastError
     })));
 }
Ejemplo n.º 2
0
        private async void LoadCompleted(object sender, NavigationEventArgs e)
        {
            Debug.WriteLine("[SearchEngine] LoadCompleted to " + e.Uri.AbsoluteUri);
            List <string> imageUrls;
            await Task.Delay(600);

            try
            {
                StorageFile scriptFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Utils/Scripts/parseHtml.js"));

                string script = await FileIO.ReadTextAsync(scriptFile);

                Debug.WriteLine("[SearchEngine] Invoke parse html script...");
                string urls = await webView.InvokeScriptAsync("eval", new string[] { script });

                Debug.WriteLine("[SearchEngine] End invoke.");
                imageUrls = urls.Split(' ').ToList();
                for (int i = 0; i < imageUrls.Count; i++)
                {
                    imageUrls[i] = Uri.UnescapeDataString(imageUrls[i].Split('&')[0]);
                }

                Debug.WriteLine("[SearchEngine] " + imageUrls.Count + " result(s)");
                SearchCompleted?.Invoke(imageUrls);
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog("SearchEngine error : " + Environment.NewLine + ex.ToString());
                await dialog.ShowAsync();
            }
        }
        public async Task <Beer[]> DoSearchAsync(string searchString)
        {
            beers = await _httpClient.GetFromJsonAsync <Beer[]>($"beers?beer_name={searchString}");

            SearchCompleted?.Invoke(beers);
            return(beers);
        }
Ejemplo n.º 4
0
 public void Search(IEnumerable <Type> types)
 {
     foreach (Type type in types)
     {
         CheckStaticFields(type);
     }
     SearchCompleted?.Invoke();
 }
Ejemplo n.º 5
0
        private async static Task CrawlImages()
        {
            var images = browser.Document.GetElementsByTagName("img").ToList()
                         .Where(el => el.GetAttribute("className").StartsWith("rg_i"))
                         .Take(50)
                         .ToList();

            var covers = new List <Cover>();

            for (int i = 0; i < images.Count; i++)
            {
                try
                {
                    HtmlElement image = images[i];

                    // We want square images
                    if (image.ClientRectangle.Width != image.ClientRectangle.Height || image.ClientRectangle.Width < 100)
                    {
                        continue;
                    }


                    // Open right pane viewer
                    image.InvokeMember("click");
                    await Task.Delay(350);

                    // Retreive new added attribute value and extract image url
                    string href    = image.Parent?.Parent?.GetAttribute("href");
                    string encoded = href?.Replace("/imgres?imgurl=", "")?.Split('&')?[0];

                    if (href == null)
                    {
                        continue;
                    }

                    var cover = new Cover(
                        rank: i + 1,
                        url: encoded.DecodeUrl()
                        );

                    covers.Add(cover);

                    if (covers.Count == 20)
                    {
                        break;
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show(error.ToString(), "Bof..");
                }
            }

            SearchCompleted?.Invoke(covers);
        }
        private void CheckRequestsStatus()
        {
            if (receivedPortRequests >= sentPortRequests)
            {
                long m = 0;

                if (stopwatch != null)
                {
                    stopwatch.Stop();
                    m = stopwatch.ElapsedMilliseconds;
                }

                if (ScanInterval == 0 && stop != null)
                {
                    stop.Set();
                }
                SearchCompleted?.Invoke(this, m);
            }
        }
Ejemplo n.º 7
0
        /// <summary>Webページ読み込み完了時の処理</summary>
        private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            try
            {
                // タイトル取得
                if (_title == string.Empty)
                {
                    _title = _search.GetTitleFromHtml(_browser.Document);
                    //SetTitleFromHtml(_browser.Document);
                }

                if (_browser.ReadyState == WebBrowserReadyState.Complete)
                {
                    // 検索文字を含む文字列を取得
                    _searchResultList.AddRange(_search.GetSearchResult(_browser.Document, _seachStrList, _pageNo, _url));
                    //SetSearchResult(_browser.Document);

                    // 次ページのURLを取得
                    _nextPageUrl = GetNextPageURL(_browser.Document);
                    if (_nextPageUrl == string.Empty)
                    {
                        SearchCompleted?.Invoke(this, EventArgs.Empty);
                        return;
                    }

                    _nextPageUrl = _url + _nextPageUrl;

                    _pageNo++;

                    // 次ページにアクセス
                    _browser.Navigate(_nextPageUrl);

                    // 一ページ検索終了
                    SearchOnlyPageCompleted?.Invoke(this, EventArgs.Empty);
                }
            }
            catch (Exception ex)
            {
                //Init();
                // errorイベント
                MessageBox.Show("検索に失敗しました。\n" + ex.ToString());
            }
        }
Ejemplo n.º 8
0
        public async Task <MoveViewer> CpuMove(int maxDepth)
        {
            SearchStarted?.Invoke(this, new EventArgs());

            var searchResults = await Task.Run(() => search.Go(board, CpuColour, maxDepth));

            SearchCompleted?.Invoke(this, new SearchCompleteEventArgs(searchResults));

            var chosenMove = searchResults.MoveEvaluations
                             .OrderByDescending(x => x.Score)
                             .FirstOrDefault();

            if (chosenMove == null)
            {
                return(new MoveViewer(0));
            }

            ApplyMove(board, CpuColour, chosenMove.Move);

            return(chosenMove.Move);
        }
Ejemplo n.º 9
0
 private void Sniffer_RequestsCompleted(long milliseconds)
 {
     SearchCompleted.Invoke(milliseconds);
 }
Ejemplo n.º 10
0
        private async Task SearchAsync()
        {
            if (string.IsNullOrEmpty(mSearchString))
            {
                return;
            }

            if (mSearchTask?.IsCanceled == false && mSearchTask?.IsCompleted == false)
            {
                //Cancel if previous search is running
                await CancelSearchAsync();
            }

            xSearchBtn.Visibility      = Visibility.Collapsed;
            xSearchClearBtn.Visibility = Visibility.Visible;
            mCancellationTokenSource   = new CancellationTokenSource();
            mSearchTask = new Task(() =>
            {
                this.Dispatcher.Invoke(() =>
                {
                    try
                    {
                        mCancellationTokenSource.Token.ThrowIfCancellationRequested();

                        if (SearchStarted == null)
                        {
                            //If event is not hooked we say searching status on main window
                            Reporter.ToStatus(eStatusMsgKey.Search, null, ": " + mSearchString);
                        }
                        else
                        {
                            //If event is hookded then no point in showing status on main window.
                            //child window need to handle it in the window. E.g. Windows Explorer
                            SearchStarted.Invoke(Tree, new EventArgs());
                        }
                        Mouse.OverrideCursor = Cursors.Wait;
                        xTreeViewTree.FilterItemsByText(xTreeViewTree.TreeItemsCollection, mSearchString, mCancellationTokenSource.Token);
                    }
                    catch (Exception ex)
                    {
                        Reporter.ToLog(eLogLevel.ERROR, "Failed to search : ", ex);
                    }
                    finally
                    {
                        if (SearchStarted == null)
                        {
                            Reporter.HideStatusMessage();
                        }
                        else
                        {
                            SearchCompleted.Invoke(Tree, new EventArgs());
                        }

                        Mouse.OverrideCursor = null;
                        mCancellationTokenSource.Dispose();
                    }
                });
            }, mCancellationTokenSource.Token, TaskCreationOptions.LongRunning);

            mSearchTask.Start();
        }
Ejemplo n.º 11
0
 protected void OnSearchCompleted(RunWorkerCompletedEventArgs e)
 {
     SearchCompleted?.Invoke(this, e);
 }