Exemplo n.º 1
0
        private bool OnSearchResults(Searcher.Searcher sender, List <Result> results)
        {
            bool retval = false;

            if (!(sender is HistorySearcher) && Utils.RecordHistory)
            {
                Utils.HistoryRecorder.Insert(results);
            }

            this.Invoke(new MethodInvoker(() =>
            {
                int gen = (int)sender.Tag;
                if (gen != searchGeneration)
                {
                    retval = false;
                }
                else
                {
                    listViewResults.BeginUpdate();
                    foreach (Result r in results)
                    {
                        listViewResults.UniqueItemAdd(new List.ListViewItem(r));
                    }
                    listViewResults.EndUpdate();

                    this.Text = "MagnetX (" + listViewResults.Items.Count + "个结果)";

                    retval = true;
                }
            }));
            return(retval);
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            foreach (ListViewItem lvi in listView1.Items)
            {
                lvi.SubItems[1].Text = "测试中";
            }

            int count = listView1.Items.Count;

            foreach (ListViewItem lvi in listView1.Items)
            {
                Searcher.Searcher s = lvi.Tag as Searcher.Searcher;
                if (s != null)
                {
                    Task.Run(async() =>
                    {
                        var result = await s.TestAsync();
                        this.Invoke(new MethodInvoker(() => {
                            switch (result)
                            {
                            case Searcher.TestResults.OK:
                                lvi.SubItems[1].Text = "可用";
                                break;

                            case Searcher.TestResults.Timeout:
                                lvi.SubItems[1].Text = "超时";
                                break;

                            case Searcher.TestResults.FormatError:
                                lvi.SubItems[1].Text = "解析错误";
                                break;

                            case Searcher.TestResults.ServerError:
                                lvi.SubItems[1].Text = "请求错误";
                                break;

                            case Searcher.TestResults.UnknownError:
                                lvi.SubItems[1].Text = "未知错误";
                                break;
                            }

                            if (--count == 0)
                            {
                                button1.Enabled = true;
                            }
                        }));
                    });
                }
            }
        }
Exemplo n.º 3
0
 public static bool GetSearcherEnabled(Searcher.Searcher s)
 {
     if (s == null)
     {
         return(false);
     }
     string[] ignoredSearcher = Settings.IgnoredSearcher;
     foreach (string b in ignoredSearcher)
     {
         if (s.Name == b)
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 4
0
 public static void SetSearcherEnabled(Searcher.Searcher s, bool b)
 {
     if (s != null)
     {
         HashSet <string> hashSet = new HashSet <string>(Settings.IgnoredSearcher);
         try
         {
             if (b)
             {
                 hashSet.Remove(s.Name);
             }
             else
             {
                 hashSet.Add(s.Name);
             }
         }
         catch
         {
         }
         Settings.IgnoredSearcher = hashSet.ToArray();
         Settings.Save(Settings);
     }
 }