Program.cs
上传用户:huiyue
上传日期:2022-04-08
资源大小:1429k
文件大小:6k
源码类别:

搜索引擎

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using Searcharoo.Common;
  6. using Mono.GetOptions;           //v4
  7. using PFitzsimons.ConsoleColour; //v6
  8. #region Mono.GetOptions attributes to drive command line argument parsing
  9. // Instructions to 'set up' Mono.GetOptions
  10. // http://www.talios.com/command_line_processing_with_monogetoptions.htm
  11. // Attributes visible in " -V"
  12. [assembly: Mono.About("Searcharoo Indexer (Spider)")]
  13. [assembly: Mono.Author("Craig.Dunn (at) ConceptDevelopment.net")]
  14. [assembly: Mono.AdditionalInfo("Searcharoo.Indexer.exe spiders and catalogs data for the Searcharoo.Engine")]
  15. // This is text that goes after " [options]" in help output - there is none for this program
  16. [assembly: Mono.UsageComplement("")]
  17. // Attributes visible in " --help"
  18. // are defined in AssemblyInfo.cs (not here)
  19. #endregion
  20. namespace Searcharoo.Indexer
  21. {
  22.     /// <summary>
  23.     /// Searcharoo INDEXER console application
  24.     /// </summary>
  25.     /// <remarks>
  26.     /// Colored-coded output courtesy of
  27.     /// http://www.codeproject.com/csharp/Console_Apps__Colour_Text/ConsoleColour_src.zip
  28.     /// (Philip Fitzsimons)
  29.     /// </remarks>
  30.     class Program
  31.     {
  32.         private static CommandLinePreferences clip;
  33.         static void Main(string[] args)
  34.         {
  35.             clip = new CommandLinePreferences();
  36.             clip.ProcessArgs(args);
  37.             if (clip.Verbosity > 0)
  38.             {
  39.                 ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Green, true);
  40.                 Console.Write("Searcharoo.Indexer");
  41.                 ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Red, true);
  42.                 Console.WriteLine(" v0.3");
  43.                 ConsoleColour.SetForeGroundColour();
  44.             }
  45.             ConsoleWriteLine(1, "=======================");
  46.             Spider spider = new Spider();
  47.             spider.SpiderProgressEvent += new SpiderProgressEventHandler(OnProgressEvent);
  48.             spider.SpiderProgressEvent += new SpiderProgressEventHandler(OnProgressLogEvent);
  49.             string[] startPages = Preferences.StartPage.Split(new char[] { ',',';'});
  50.            
  51.             Uri[] uris = new Uri[startPages.Length];
  52.             for (int i = 0; i < startPages.Length; i++)
  53.             {
  54.                 uris[i] = new Uri(startPages[i]);
  55.             }
  56.             Catalog catalog = null;
  57.             if (uris.Length == 1)
  58.             {   // legacy behaviour, just for testing/comparison
  59.                 catalog = spider.BuildCatalog(new Uri(Preferences.StartPage));
  60.             }
  61.             else
  62.             {   // multiple start Uris allowed
  63.                 catalog = spider.BuildCatalog(uris);
  64.             }
  65.            
  66.             ConsoleWriteLine(1, "=======================");
  67. #if DEBUG
  68.             //System.Threading.Thread.Sleep(30 * 1000);    // 30 seconds
  69.             ConsoleWriteLine(1, "Press <enter> to finish...");
  70.             if (clip.Verbosity > 0) Console.Read();
  71. #endif            
  72.         }
  73.         private static void ConsoleWriteLine(int level, string text)
  74.         {
  75.             switch (level)
  76.             {
  77.                 case 2:
  78.                     ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Grey);
  79.                     break;
  80.                 case 3:
  81.                     ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Yellow);
  82.                     break;
  83.                 case 4:
  84.                     ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Red);
  85.                     break;
  86.                 case 5:
  87.                     ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Magenta);
  88.                     break;
  89.                 default:
  90.                     ConsoleColour.SetForeGroundColour();
  91.                     break;
  92.             }
  93.             if (level <= clip.Verbosity)
  94.             {
  95.                 Console.WriteLine(text);
  96.             }
  97.         }
  98.         /// <summary>
  99.         /// Handle events generated by the Spider (mostly reporting on success/fail of page load/index)
  100.         /// </summary>
  101.         public static void OnProgressEvent(object source, ProgressEventArgs pea)
  102.         {
  103.             if (pea.Level <= clip.Verbosity)
  104.             {
  105.                 switch (pea.Level)
  106.                 {
  107.                     case 2:
  108.                         ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Grey);
  109.                         break;
  110.                     case 3:
  111.                         ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Yellow);
  112.                         break;
  113.                     case 4:
  114.                         ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Red);
  115.                         break;
  116.                     case 5:
  117.                         ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Magenta);
  118.                         break;
  119.                     default:
  120.                         ConsoleColour.SetForeGroundColour();
  121.                         break;
  122.                 }
  123.                 Console.WriteLine(">{0} :: {1}", pea.Level, pea.Message);
  124.             }
  125.             
  126.         }
  127.         /// <summary>
  128.         /// Log to disk events generated by the Spider (mostly reporting on success/fail of page load/index)
  129.         /// </summary>
  130.         public static void OnProgressLogEvent(object source, ProgressEventArgs pea)
  131.         {
  132.             //if (pea.Level < 3)
  133.             //{
  134.             //    Console.WriteLine(pea.Message + "<br>");
  135.             //}
  136.         }
  137.     }
  138. }