示例#1
0
        private static bool StartSearches(string imgUrl, SearchEngines engines, ref SearchResult[] res)
        {
            // todo: improve
            // todo: use tasks

            var availableEngines = GetAvailableEngines()
                                   .Where(e => engines.HasFlag(e.Engine))
                                   .ToArray();

            int i = 0;

            res    = new SearchResult[availableEngines.Length + 1];
            res[i] = new SearchResult(imgUrl, "(Original image)");

            i++;


            foreach (var currentEngine in availableEngines)
            {
                string wait = String.Format("{0}: ...", currentEngine.Engine);

                CliOutput.WithColor(ConsoleColor.Blue, () =>
                {
                    //
                    Console.Write(wait);
                });

                var sw = Stopwatch.StartNew();

                // Run search
                var result = currentEngine.GetResult(imgUrl);

                sw.Stop();

                if (result != null)
                {
                    string url = result.Url;

                    var    sb = new StringBuilder();
                    double t  = sw.Elapsed.TotalSeconds;
                    double t2 = Math.Round(t, 3);
                    sb.AppendFormat("{0}: Done ({1:F3} sec)\n", result.Name, t2);


                    //todo

                    bool ok = url != null;

                    string sz = sb.ToString();


                    if (ok)
                    {
                        CliOutput.OnCurrentLine(ConsoleColor.Green, sz);

                        if (SearchConfig.Config.PriorityEngines.HasFlag(currentEngine.Engine))
                        {
                            WebAgent.OpenUrl(result.Url);
                        }
                    }
                    else
                    {
                        CliOutput.OnCurrentLine(ConsoleColor.Yellow, sz);
                    }

                    res[i] = result;
                }

                // todo

                i++;
            }


            return(true);
        }