//Here we Itterate accross the SFL files in the Directory and send them to be parsed and saved as CSV files private void Frm_Btn_Convert_files_Click(object sender, EventArgs e) { sfl_list = Directory.GetFiles(sfl_loc_fldr_path_str, "*.sfl"); raw_file_string = new List <string>(); foreach (string name in sfl_list) { string tmp_str; //string return_str; try { //the file string will begin with name, then the contents of the file tmp_str = @name + @"," + @File.ReadAllText(name); raw_file_string.Add(tmp_str); parser.Parse_SFL(tmp_str); } catch (Exception ex) { ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Red); Console.WriteLine("The file could not be read: {0}", name); Console.WriteLine(ex.Message); ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.White); } } }
private static void ConsoleWriteLine(int level, string text) { switch (level) { case 2: ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Grey); break; case 3: ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Yellow); break; case 4: ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Red); break; case 5: ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Magenta); break; default: ConsoleColour.SetForeGroundColour(); break; } if (level <= clip.Verbosity) { Console.WriteLine(text); } }
/// <summary> /// Handle events generated by the Spider (mostly reporting on success/fail of page load/index) /// </summary> public static void OnProgressEvent(object source, ProgressEventArgs pea) { if (pea.Level <= clip.Verbosity) { switch (pea.Level) { case 2: ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Grey); break; case 3: ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Yellow); break; case 4: ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Red); break; case 5: ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Magenta); break; default: ConsoleColour.SetForeGroundColour(); break; } Console.WriteLine(">{0} :: {1}", pea.Level, pea.Message); } }
static void Main(string[] args) { clip = new CommandLinePreferences(); clip.ProcessArgs(args); if (clip.Verbosity > 0) { ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Green, true); Console.Write("Searcharoo.Indexer"); ConsoleColour.SetForeGroundColour(ConsoleColour.ForeGroundColour.Red, true); Console.WriteLine(" v0.3"); ConsoleColour.SetForeGroundColour(); } ConsoleWriteLine(1, "======================="); Spider spider = new Spider(); spider.SpiderProgressEvent += new SpiderProgressEventHandler(OnProgressEvent); spider.SpiderProgressEvent += new SpiderProgressEventHandler(OnProgressLogEvent); string[] startPages = Preferences.StartPage.Split(new char[] { ',', ';' }); Uri[] uris = new Uri[startPages.Length]; for (int i = 0; i < startPages.Length; i++) { uris[i] = new Uri(startPages[i]); } Catalog catalog = null; if (uris.Length == 1) { // legacy behaviour, just for testing/comparison catalog = spider.BuildCatalog(new Uri(Preferences.StartPage)); } else { // multiple start Uris allowed catalog = spider.BuildCatalog(uris); } ConsoleWriteLine(1, "======================="); #if DEBUG //System.Threading.Thread.Sleep(30 * 1000); // 30 seconds ConsoleWriteLine(1, "Press <enter> to finish..."); if (clip.Verbosity > 0) { Console.Read(); } #endif }