Esempio n. 1
0
        public void Load(string[] urlStrings)
        {
            string ret;

            foreach (string url in urlStrings)
            {
                Task task = Task.Factory.StartNew(
                    () =>
                {
                    Sniffer sniff = SnifferFactory.Instance().Create(url);
                    Console.WriteLine("strated");
                    while (true)
                    {
                        try
                        {
                            ret = sniff.Sniff().Result;

                            var restResult = new SniffResult()
                            {
                                Url      = url,
                                DateTime = DateTime.Now,
                                Result   = ret
                            };
                            Console.WriteLine(restResult.Result);
                            _resultsSniff.Add(restResult);
                        }
                        catch (HttpRequestException ie)
                        {
                            Console.WriteLine("   {0}: {1}", ie.GetType().Name, ie.Message);
                        }
                        catch (AggregateException e)
                        {
                            Console.WriteLine("Exception messages:");
                            foreach (var ie in e.InnerExceptions)
                            {
                                Console.WriteLine("   {0}: {1}", ie.GetType().Name, ie.Message);
                            }
                        }
                    }
                }, _cancellationToken);
                this._sniffers.Add(task);
            }
            Task.WaitAll(this._sniffers.ToArray());
        }
Esempio n. 2
0
 private bool Equals(SniffResult other)
 {
     return(string.Equals(Url, other.Url));
 }