Ejemplo n.º 1
0
        static void Validate(Spinner spinner, HttpClient httpClient, Options options)
        {
            var progressUpdater = new SpinnerProgressUpdater(spinner);

            var sitemap = new SitemapRetriever(httpClient).Retrieve(options.Url);

            var validationResults = new Validator(httpClient, progressUpdater).Validate(sitemap, options);

            spinner.Stop();

            var groupedByStatusCode = validationResults
                                      .OrderBy(x => x.ActualHttpStatusCode)
                                      .GroupBy(x => x.ActualHttpStatusCode);

            Console.WriteLine("\nFound Status Codes: ");

            foreach (var statusCodeGroup in groupedByStatusCode)
            {
                Console.WriteLine($"\t{statusCodeGroup.Key}: {statusCodeGroup.Count()}");
            }

            if (string.IsNullOrEmpty(options.ExportFilename))
            {
                return;
            }

            //using (var textWriter = File.CreateText(options.ExportFilename))
            //{
            //    new SitemapExporter(textWriter).Export(validationResults);
            //}
        }
        public void Test()
        {
            var httpClient = GetMockHttpClient("http://scottbm.me/sitemap.xml",
                                               @"<?xml version=""1.0"" encoding=""UTF-8""?>
<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">
<url>
<loc>http://scottbm.me/</loc>
<lastmod>2017-09-01</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url></urlset>");

            var retriever = new SitemapRetriever(httpClient);

            var sitemap = retriever.Retrieve("http://scottbm.me/sitemap.xml");

            Assert.Single(sitemap.Urls);
        }
Ejemplo n.º 3
0
        public void Process(int sitemapSubmissionId)
        {
            var sitemapSubmission = _db.SitemapSubmissions.Single(x => x.Id == sitemapSubmissionId);

            // _hubContext.Clients.Groups(sitemapSubmissionId.ToString()).SendAsync("SubmissionUpdate", "from hangfire");

            var progressUpdater = new SignalRProgressUpdater(_hubContext, sitemapSubmissionId.ToString());

            using (var client = new HttpClient())
            {
                var validator = new SitemapValidator.Core.SitemapValidator(client, progressUpdater);

                var retriever = new SitemapRetriever(client);
                var sitemap   = retriever.Retrieve(sitemapSubmission.Url);

                validator.Validate(sitemap, new Options
                {
                    ExpectedStatusCode = 200,
                    Delay = 1000
                });
            }
        }