public List <String> doSearch(String folder, String serchedText)
        {
            DirectoryStructure dirStructure = new DirectoryStructure(folder);
            List <String>      result       = new List <string>();

            String[] textFilesRes = new String[] { ".asp", ".aspx", ".css", ".js", ".cs" };
            var      fileList     = dirStructure.ItemsList.Where(file => (!file.IsFolder && textFilesRes.Contains(file.Extension)));

            int counter = 0;

            foreach (DirectoryItem file in fileList)
            {
                FileContentModel fileContent = SearchFactory.FileReader.readFile(file);
                //if (file.FullPath.Contains("common.css"))
                //{
                //    Console.WriteLine("/n/n ");
                //}
                //try
                //{   // Open the text file using a stream reader.
                //    using (StreamReader sr = new StreamReader(file.FullPath))
                //    {
                //        String line;
                //        // Read the stream to a string, and write the string to the console.
                //        while ((line = sr.ReadLine()) != null) {
                //            if (line.ToLower().Contains(serchedText.ToLower()))
                //            {

                //                Console.WriteLine("{0} - {1}", file, line.Trim());
                //                ++counter;
                //            }
                //        }
                //    }
                //}
                //catch (Exception e)
                //{
                //    Console.WriteLine("The file could not be read:");
                //    Console.WriteLine(e.Message);
                //}
                ++counter;
                if (counter >= 10)
                {
                    break;
                }
            }


            return(result);
        }
예제 #2
0
        public FileContentModel readFile(DirectoryItem fileItem)
        {
            if (fileItem == null || fileItem.IsFolder)
            {
                throw new ArgumentException("fileItem");
            }

            FileContentModel fileModel = new FileContentModel(fileItem);

            using (StreamReader sr = new StreamReader(fileItem.FullPath))
            {
                String line;
                while ((line = sr.ReadLine()) != null)
                {
                    fileModel.addLine(line);
                }
            }
            return(fileModel);
        }