public void Dispose() { _exporter?.Dispose(); _stream?.Close(); }
private static void SearchInExistingIndex(ICodeSearcherLogic logic) { string exportFileName = string.Empty; IResultExporter exporter = null; if (bool.TryParse(m_CmdHandler[m_CmdHandler.WildcardSearch], out bool wildcardSearch)) { m_Logger.Info("Using Wildcard Searcher"); wildcardSearch = true; } else { m_Logger.Info("Using Default Searcher"); wildcardSearch = false; } logic.SearchWithinExistingIndex( startCallback: () => { ShowSearchWithinIndexHeader(); }, getSearchWord: () => { string word; bool exit; if (m_CmdHandler[m_CmdHandler.SearchedWord] != null) { word = m_CmdHandler[m_CmdHandler.SearchedWord]; exit = true; } else { exit = ReadWordToSearch(out word); } word?.Trim(); return(word, exit); }, getMaximumNumberOfHits: () => { if (!int.TryParse(m_CmdHandler[m_CmdHandler.NumberOfHits], out int numberOfHits)) { m_Logger.Info("Maximum hits to show will be 1000"); numberOfHits = 1000; } return(numberOfHits); }, getHitsPerPage: () => { if (!int.TryParse(m_CmdHandler[m_CmdHandler.HitsPerPage], out int hitsPerPage)) { m_Logger.Info("Maximum hits per page will be shown"); hitsPerPage = -1; } return(hitsPerPage); }, getExporter: () => { if (!bool.TryParse(m_CmdHandler[m_CmdHandler.ExportToFile], out bool export)) { m_Logger.Info("Results will not be exported"); export = false; } if (export) { exportFileName = Path.GetTempFileName(); var exportStreamWriter = File.CreateText(exportFileName); exporter = wildcardSearch ? Factory.Get().GetWildcardResultExporter(exportStreamWriter) : Factory.Get().GetDefaultResultExporter(exportStreamWriter); } return(export, exporter); }, getSingleResultPrinter: () => { if (wildcardSearch) { return(new WildcardResultPrinter()); } return(new ConsoleResultPrinter()); }, finishedCallback: (timeSpan) => { Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine(">> searching completed!"); Console.WriteLine(">> action take : {0:00}:{1:00}:{2:00}.{3:000}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); }, endOfSearchCallback: () => { Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }, exportFinishedCallback: () => { exporter?.Dispose(); Console.WriteLine($"Export file written: {exportFileName}"); }, wildcardSearch); }