Exemplo n.º 1
0
 public Result(ResultSearch search)
 {
     ResultSearch = search;
     Type         = ResultTypes.Search;
 }
        /// <summary>
        /// バックグラウンドワーカーの作業
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bgw1_DoWork(object sender, DoWorkEventArgs e)
        {
            List <Result> results = new List <Result>();

            if (e.Argument is List <String> args)
            {
                foreach (var arg in args)
                {
                    try
                    {
                        if (Util.IsUrl(arg) == false)
                        {
                            var urls = Search.GetSearchResult(arg).Result;
                            Thread.Sleep(1000);

                            ResultSearch search = new ResultSearch();

                            foreach (var url in urls.URLs)
                            {
                                try
                                {
                                    var s = ResultSpec.GetTextAsync(Util.SpecUrl(url), arg).Result;

                                    search.Specs.Add(s);

                                    Thread.Sleep(1000);
                                }
                                catch
                                {
                                }
                            }

                            Result result = new Result(search);
                            result.Time = DateTime.Now;
                            result.Word = arg;

                            results.Add(result);
                        }
                        else
                        {
                            var t = arg.TrimEnd('/');
                            var s = ResultSpec.GetTextAsync(Util.SpecUrl(t)).Result;
                            Thread.Sleep(1000);

                            Result result = new Result(s);
                            result.Time = DateTime.Now;
                            result.Word = arg;

                            results.Add(result);
                        }
                    }
                    catch
                    {
                    }
                }

                Console.WriteLine(String.Join(",", args));
            }

            e.Result = results;
        }