static void Main(string[] args) { DrawHeader(); //almost all important logic in this program is derivated from this line var paramsOptions = ParseParameters(args); if (args.Length == 0) { ConsoleExt.WriteTitle(" What you wanna do? "); Console.WriteLine(" Try --help for more information."); } else { Stopwatch sw = new Stopwatch(); LinkSpider ls = new LinkSpider(_url.AbsoluteUri); ls.URLExplorationFilter.AddRange(_urlNavFilter); Console.WriteLine("Starting to Weave Web"); Console.WriteLine("Exploring and Bulding..."); sw.Start(); if (_singleWebPage) { ls.WeaveSinglePage(); } else { ls.WeaveWeb(); } sw.Stop(); Console.WriteLine("An incredible Web has been Weaved"); Console.WriteLine("Total Links: {0}", ls.FullUrlList.Count()); Console.WriteLine("Total External Links: {0}", ls.ExternalUrlList.Count()); Console.WriteLine("Total Broken Links: {0}", ls.BrokenUrlList.Count()); Console.WriteLine("Time: {0}", sw.Elapsed); var sortedList = ls.FullUrlList.ToList(); ConsoleExt.WriteTitle("Generating files..."); BuildPlainFile(_plainFile, sortedList); Console.WriteLine("{0} OK", _plainFile); BuildPlainFile("brokenLinks.txt", ls.BrokenUrlList); Console.WriteLine("{0} OK", "brokenLinks.txt"); BuildPlainFile("externalLinks.txt", ls.ExternalUrlList); Console.WriteLine("{0} OK", "externalLinks.txt"); int counter; BuildSiteMap(_sitemapFile, _useUnicode, sortedList, _urlSitemapFilter, out counter); Console.WriteLine("{0} en formato Unicode: {1} OK", _sitemapFile, _useUnicode); Console.WriteLine("--> Total Sitema Links: {0}", counter); } #if DEBUG ConsoleExt.WriteTitle(" PRESIONE ENTER PARA SALIR ", true); Console.ReadLine(); #endif ConsoleExt.WriteTitle(" F I N ", true); }
private static void DrawHeader() { ConsoleExt.WriteTitle(" LinkSpider Console by @JuanKRuiz ", true); Console.WriteLine(" Licensed under MIT license"); ConsoleExt.WriteTitle(" Contact Info ", true); Console.WriteLine("Twitter: @JuanKRuiz"); Console.WriteLine("Facebook: JuanKDev"); Console.WriteLine("Blog: http://juank-io"); ConsoleExt.WriteTitle(" "); }
private static OptionSet ParseParameters(string[] args) { var paramsOptions = new OptionSet() { { "u|url=", "The site {URL} to start link exploration", u => { try { _url = new Uri(u); }catch (Exception ex) { throw new OptionException("Invalid Url", "url", ex); } } }, { "s|sitemap=", "Sitemap with this name must be generated {FileName}", s => _sitemapFile = s }, { "p|plain=", "Textfile including a link list must be generated {FileName}", p => _plainFile = p }, { "n|navfilter=", "Comma separated string with paths must be exclued in exploration\nexample: '/tag/,/pages'.Be carefull with case sensitive and white spaces", n => { AddCommaStringToList(_urlNavFilter, n); } }, { "m|smapfilter=", "Comma separated string with paths must be exclued in sitemap\nexample: '/tag/,/pages'.Be carefull with case sensitive and white spaces", sf => { AddCommaStringToList(_urlSitemapFilter, sf); } }, { "c|unicode", "Use unicode Encoding for sitemap", u => _useUnicode = (u != null) }, { "o|single", "Single web page scan", o => _singleWebPage = (o != null) }, { "h|?|help", "Show this message and exit", v => _show_help = (v != null) } }; try { paramsOptions.Parse(args); } catch (OptionException e) { ConsoleExt.WriteTitle("ERROR"); Console.WriteLine("Parameter: {0} - {1}", e.OptionName, e.Message); Console.WriteLine("Try --help for more information."); throw; } if (_show_help) { ShowHelp(paramsOptions); } return(paramsOptions); }
private static void ShowHelp(OptionSet paramsOptions) { ConsoleExt.WriteTitle(" H E L P "); paramsOptions.WriteOptionDescriptions(Console.Out); ConsoleExt.WriteTitle(" "); }