Beispiel #1
0
        static void Main(string[] args)
        {
            string fullFilePath = "empty";
            string searchString = "empty";

            if (args.Length > 1)
            {
                fullFilePath = args[0];
                searchString = args[1];
            }

            Console.WriteLine("File: {0}", fullFilePath);
            Console.WriteLine("Search String: {0}", searchString);
            Console.WriteLine();

            IList <int> results = null;

            try
            {
                FileSearchBase fs = FileSearchFactory.GetSearchAgent(FileType.TXT);
                fs.Search(fullFilePath, searchString, out results);

                foreach (var item in results)
                {
                    Console.WriteLine("Row: {0}", item);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.ReadLine();
        }
        public static FileSearchBase GetSearchAgent(FileType fileType)
        {
            FileSearchBase FileSearchAgent = null;

            switch (fileType)
            {
            case FileType.TXT:
                FileSearchAgent = new FileSearchTXT();
                break;

            case FileType.PDF:
                FileSearchAgent = new FileSearchPDF();
                break;

            default:
                FileSearchAgent = null;
                throw new Exception("File type '" + fileType.ToString() + "' is not supported");
            }

            return(FileSearchAgent);
        }