예제 #1
0
        public ViewResult Index(String searchingText)
        {
            try
            {
                Task[] tasks = new Task[preferences.parsers.Count];
                int    i     = 0;
                preferences.parsers.ForEach(p => { tasks[i] = p.LoadPage(searchingText); i++; });
                int index = Task.WaitAny(tasks);

                List <String> result = preferences.parsers[index].Parse();

                foreach (var r in result)
                {
                    FoundUrl url = new FoundUrl();
                    url.Url       = r;
                    url.Engine    = preferences.parsers[index].searchEngineUrl;
                    url.DateFound = DateTime.Now;
                    context.Add(url);
                }
                context.SaveChanges();

                return(View(result));
            }
            catch (AggregateException ex)
            {
                List <String> result = new List <String>();
                foreach (var e in ex.InnerExceptions)
                {
                    result.Add(e.Message);
                }
                return(View(result));
            }
        }