public void Execute()
        {
            Directory.CreateDirectory(_Output.GetReportDirectory());

            _Logger.LogInformation(200, $"Saving report to {_Output.GetReportFilePath()}");
            var client = new HttpClient();
            var body   = client.GetStringAsync(_Site.Site);

            _Logger.LogDebug(body.Result);

            var links = _LinkChecker.GetLinks(_Site.Site, body.Result);

            var checkedLinks = _LinkChecker.CheckLinks(links);

            using (var file = File.CreateText(_Output.GetReportFilePath()))
                using (var linksDb = new LinksDb())
                {
                    foreach (var link in checkedLinks.OrderBy(l => l.Exists))
                    {
                        var status = link.IsMissing ? "missing" : "OK";
                        file.WriteLine($"{status} - {link.Link}");
                        linksDb.Links.Add(link);
                    }
                    linksDb.SaveChanges();
                }
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            var site = "https://lketema.github.io/";
            // site = "https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/";
            var client = new HttpClient();
            // the below dumps content of site
            var bodyReturned = client.GetStringAsync(site);

            var links = LinkChecker.GetLinks(bodyReturned.Result);

            var result = LinkChecker.CheckLinks(links);

            LogToFile(result);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var config = new Config(args);

            Logs.Init(config.ConfigurationRoot);
            var logger = Logs.Factory.CreateLogger <Program>();

            Directory.CreateDirectory(config.Output.GetReportDirectory());
            logger.LogInformation(200, $"Saving report to {config.Output.GetReportDirectory()}");
            var client = new HttpClient();
            var body   = client.GetStringAsync(config.Site);

            logger.LogDebug(body.Result);

            logger.LogInformation("Links");
            var links = LinkChecker.GetLinks(config.Site, body.Result);

            links.ToList().ForEach(Console.WriteLine);
            var checkedLinks = LinkChecker.CheckLinks(links);

            using (var file = File.CreateText(config.Output.GetReportFilePath()))
                using (var linksDb = new LinksDb())
                {
                    foreach (var link in checkedLinks.OrderBy(l => l.Exists))
                    {
                        var status = link.IsMissing ? "Missing" : "OK";
                        file.WriteLine($"{status} - {link.Link}");
                        linksDb.Links.Add(link);
                        Console.WriteLine("{0} {1}", link.Id, link.Link);
                    }

                    /**
                     * docker run -d --name sqllinux-netcore -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=1Secure*Password1' -e 'MSSQL_PID=Enterprise' -p 1433:1433 -d microsoft/mssql-server-linux:2017-latest
                     * docker hub: https://hub.docker.com/r/microsoft/mssql-server-linux
                     * docker run -d --name mysql-netcore -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=Links -p 3306:3306 mysql
                     */
                    linksDb.SaveChanges();
                }
        }
Ejemplo n.º 4
0
        public void Execute()
        {
            Console.WriteLine("CheckLinksJob executed");
            Directory.CreateDirectory(_output.GetReportDirectoryPath());
            var client = new HttpClient();
            var body   = client.GetStringAsync(_siteSettings.Url);
            var links  = _linkChecker.GetLinks(_siteSettings.Url, body.Result);

            _logger.LogInformation(100, $"Saving report to {_output.GetReportFilePath()}");
            var checkedLinks = _linkChecker.CheckLinks(links);

            using (var file = File.CreateText(_output.GetReportFilePath()))
                using (var linksDb = new LinksDb())
                {
                    foreach (var link in checkedLinks.OrderBy(l => l.Exists))
                    {
                        var status = link.IsMissing ? "missing" : "OK";
                        file.WriteLine($"{status} - {link.Link}");
                        linksDb.Links.Add(link);
                    }

                    linksDb.SaveChanges();
                }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // it is a convention to pass the applications fully qualified class name
            // as an overload into the logger to aid in more descriptive logging since it includes
            // the namespace and everything
            var config = new Config(args);

            Logs.Init(config.ConfigurationRoot);
            var logger = Logs.Factory.CreateLogger <Program>();

            Directory.CreateDirectory(config.Output.GetReportDirectory()); // could also do configuration.GetSection("output").Get<OutputSettings>(); and this would also skipping creating the new outputsettings object

            logger.LogInformation($"Saving file to {config.Output.GetReportFilePath()}");
            var client = new HttpClient();
            var body   = client.GetStringAsync(config.Site);

            logger.LogDebug(body.Result);

            var links = LinkChecker.GetLinks(config.Site, body.Result);
            // write out links
            // File.WriteAllLines(outputPath, links);
            var checkedLinks = LinkChecker.CheckLinks(links);

            using (var file = File.CreateText(config.Output.GetReportFilePath()))
                using (var linksDb = new LinksDb())
                // using is like a try block, allows the system to drop the connection if something does wrong
                {
                    foreach (var link in checkedLinks.OrderBy(l => l.IsMissing))
                    {
                        var status = link.IsMissing ? "missing" : "ok";
                        file.WriteLine($"{status} - {link.Link}");
                        linksDb.Links.Add(link);
                    }
                    linksDb.SaveChanges();
                }
        }