Пример #1
0
        private static bool StartSearches(string imgUrl, SearchEngines engines, SearchResults res)
        {
            ISearchEngine[] available = GetAvailableEngines()
                                        .Where(e => engines.HasFlag(e.Engine))
                                        .ToArray();

            int i = 0;

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

            i++;

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

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


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

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


                    if (url != null)
                    {
                        CliOutput.OnCurrentLine(ConsoleColor.Green, "{0}: Done\n", result.Name);

                        if (RuntimeInfo.Config.PriorityEngines.HasFlag(idx.Engine))
                        {
                            WebAgent.OpenUrl(result.Url);
                        }
                    }
                    else
                    {
                        CliOutput.OnCurrentLine(ConsoleColor.Yellow, "{0}: Done (url is null!)\n", result.Name);
                    }

                    res.Results[i] = result;
                }

                // todo

                i++;
            }


            return(true);
        }
Пример #2
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);
        }