Пример #1
0
        // Example: analyze one url from database.
        //
        public static void Analyze(Model model)
        {
            string url = "";
            int siteId = -1;
            NpgsqlDataReader urlRow;

            // This part must be locked, otherwise threads will read
            // the same site.
            //
            lock (urlLocker) {
                urlRow = model.GetUrl();

                // If database haven't site to analyze.
                if (!urlRow.Read()) {
                    Console.WriteLine("All sites are processed or "
                        + "processing now.");
                    Thread.Sleep(SLEEP_TIME);
                    return;
                }
                siteId = urlRow.GetInt32(0);
                model.MarkSiteProcessed(siteId);
            }
             try {
                url = urlRow.GetString(1);
                Console.WriteLine(url);

                Analyzer analyzer = new Analyzer(url);
                int reportId = model.NewReport(siteId);
                Report report = analyzer.Analyze(reportId);
                report.PutIntoDB(model, siteId);
            }
            catch (InvalidOperationException ex) {
                Console.WriteLine("Analyze Error: {0}", ex.Message);
                model.MarkSiteFailed(siteId);
            }
            catch (Exception ex) {
                Console.WriteLine("Unknown error: " + ex.Message);
                model.MarkSiteFailed(siteId);
            }
        }
Пример #2
0
 public Report(Model model, int siteId)
     : this()
 {
     id = model.NewReport(siteId);
 }