/// <summary> /// Processes the file. /// </summary> /// <param name="pathInfo">The path info.</param> /// <param name="filePath">The file path.</param> void IFileCrawlerObserver.ProcessFile(FileFolderPath pathInfo, string filePath) { try { // Notify processing file: this.NotifyFileProcessing(filePath); // Read file: //string input = File.ReadAllText(filePath); string input; Encoding detectedEncoding; using (StreamReader reader = new StreamReader(filePath, Encoding.Default)) { input = reader.ReadToEnd(); detectedEncoding = reader.CurrentEncoding; } // Reset file tags: AllAvailableSmartTags.ResetFileTags(); // Apply replacing: string output = input; int count = this.wrappedPatterns.Count; for (int i = 0; i < count; i++) { output = this.wrappedPatterns[i].ProcessPattern(output); } // Notify file processed: bool shouldSave = this.NotifyFileProcessed(filePath, input, output); // Save file: if (shouldSave) { //File.WriteAllText(filePath, output, Encoding.ASCII); File.WriteAllText(filePath, output, detectedEncoding); } } catch (Exception e) { this.NotifyMessage(filePath, String.Format("Exception in file {0} : {1}", filePath, e)); } }
/// <summary> /// Notifies that exception has occurred. /// </summary> /// <param name="pathInfo">The path info.</param> /// <param name="exc">The exc.</param> void IFileCrawlerObserver.ErrorOccurred(FileFolderPath pathInfo, Exception exc) { this.NotifyMessage(pathInfo.RootPath, exc); }
/// <summary> /// Files the crawling finished. /// </summary> /// <param name="pathInfo">The path info.</param> void IFileCrawlerObserver.FileCrawlingFinished(FileFolderPath pathInfo) { this.NotifyMessage(pathInfo.RootPath, "Crawling finished."); }