/// <summary>
        /// Method that parses several files
        /// </summary>
        /// <param name="files">Array of file names</param>
        /// <returns>Line count</returns>
        public ILineCount ParseFiles(string[] files)
        {
            LineCountImp lineCount = new LineCountImp();

            foreach (string file in files)
            {
                ILineCount temp = ParseFile(file);

                lineCount.Add(temp);
            }

            return(lineCount);
        }
示例#2
0
        /// <summary>
        /// Parses a file
        /// </summary>
        /// <param name="fileStream">file stream</param>
        /// <returns></returns>
        ILineCount IFileParser.Parse(FileStream fileStream)
        {
            LineCounter lineCounter = LineCounter.CreateLineCounter();

            ILineParser lineParser = lineCounter.GetLineParser();

            fileStream.Position = 0;
            LineCountImp lineCount = new LineCountImp();

            if (fileStream.CanRead)
            {
                StreamReader sr = new StreamReader(fileStream);

                bool inComment = false;

                while (sr.Peek() > -1)
                {
                    string   line     = sr.ReadLine();
                    LineType lineType = lineParser.Parse(line);

                    if (lineType == LineType.BeginComment)
                    {
                        inComment = true;
                    }

                    lineCount.SetLine((inComment ? LineType.LineComment : lineType));

                    if (lineType == LineType.EndComment)
                    {
                        inComment = false;
                    }
                }
            }

            return(lineCount);
        }
        /// <summary>
        /// Parses directory
        /// </summary>
        /// <param name="directory">Full folder path</param>
        /// <param name="includeSubFolders">True if subfolders should be included</param>
        /// <param name="OnProgress">Call back delegate for providing progress information</param>
        /// <returns>Line Count Interface</returns>
        public ILineCount ParseDir(string directory, bool includeSubFolders, ProgressDelegate OnProgress)
        {
            LineCountImp           lineCount = new LineCountImp();
            ArrayList              alFolders = new ArrayList();
            LineCounterProgresArgs args      = new LineCounterProgresArgs();
            int fileCount = 0;

            args.CurrentLineCount = lineCount;

            if (OnProgress != null)
            {
                args.Status         = ProgressStatus.Started;
                args.CurrentMessage = "Process started";
                OnProgress(args);
                args.Status = ProgressStatus.MidProcess;
            }

            if (includeSubFolders)
            {
                GetDirectories(directory, alFolders, OnProgress);
            }
            else
            {
                alFolders.Add(directory);
            }

            args.TotalFolders   = alFolders.Count;
            args.CurrentMessage = "Total Folders: " + alFolders.Count;

            if (OnProgress != null)
            {
                OnProgress(args);
            }

            foreach (string folder in alFolders)
            {
                args.CurrentFile = 0;
                args.CurrentFolder++;
                args.FolderName = folder;
                string[] files = null;


                string[] fileExtensions = new string[] { "*.java", "*.cs", "*.c", "*.cpp", "*.vb" };

                foreach (string fileExtension in fileExtensions)
                {
                    try
                    {
                        files = System.IO.Directory.GetFiles(folder, fileExtension);
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc.ToString());
                        continue;
                    }
                    args.TotalFilesInCurrentFolder = files.Length;

                    foreach (string file in files)
                    {
                        #region Call Back OnProgress
                        if (OnProgress != null)
                        {
                            args.CurrentFile++;
                            args.FileName       = file;
                            args.CurrentMessage = "Processing File: " + file;
                            OnProgress(args);
                        }
                        #endregion

                        ILineCount temp = ParseFile(file);
                        lineCount.Add(temp);
                        fileCount++;
                    }
                }
            }

            if (OnProgress != null)
            {
                args.Status         = ProgressStatus.Finished;
                args.CurrentMessage = string.Format("Process Finished! \r\nTotal Folders Processed: {0} \r\nTotal Files Processed: {1}", alFolders.Count, fileCount);
                OnProgress(args);
            }

            return(lineCount);
        }