Beispiel #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);
            }
            url = urlRow.GetString(1);
            Console.WriteLine(url);

            try {
                /*Analyzer analyzer = new Analyzer(url);
                Report report = new Report(model, siteId);
                report = analyzer.Analyze(report.Id);*/
                Report report = new Report(model, siteId);
                report = Analyzer.Analyze(report.Id, url);
                report.PutIntoDB(model, siteId);
                Thread.Sleep(SLEEP_TIME);
            }
            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);
            }
        }
Beispiel #2
0
 public Report(Model model, int siteId)
     : this()
 {
     id = model.NewReport(siteId);
 }
Beispiel #3
0
 public void PutIntoDB(Model model, int siteId)
 {
     model.PutRules(id, FEATURES, commonFeatures);
     model.PutRules(id, mainUrl, mainPageResult);
     foreach(Page page in specificFeatures) {
         model.PutRules(id, page.Url, page.Features);
     }
     model.DataIsReady(siteId);
 }
Beispiel #4
0
        // Example: grab information for .pdf generation from database
        // and write it to stdout.
        //
        public static void WriteReadyData(Model model)
        {
            NpgsqlDataReader urlRow = model.GetUrlForReport();

            // Check if database have site ready for .pdf generation.
            //
            if (!urlRow.Read()) { return; }

            int siteId = urlRow.GetInt32(0);
            int reportId = model.GetReportId(siteId);
            NpgsqlDataReader subpages = model.GetSubpages(reportId);

            while (subpages.Read()) {
                string featuresAddress = subpages.GetString(0);
                Console.WriteLine(featuresAddress);

                Features rules = subpages.GetString(1).FromJson<Features>();
                foreach (var rule in rules) {
                    Console.WriteLine(rule.Key + " = " + rule.Value);
                    if (!rule.Value) {
                        Console.WriteLine(model.Explain(rule.Key));
                    }
                }
            }
        }