Esempio n. 1
0
        private void OnProgress(CodeLineCounterLibrary.LineCounterProgresArgs args)
        {
            if (this.InvokeRequired)
            {
                BeginInvoke((MethodInvoker) delegate
                {
                    OnProgress(args);
                });
            }
            else
            {
                if (_CurrentFolder != args.CurrentFolder)
                {
                    progressBar1.Maximum = args.TotalFolders;
                    progressBar1.Minimum = 0;
                    progressBar1.Value   = args.CurrentFolder;
                    _CurrentFolder       = args.CurrentFolder;
                }

                if (args.Status == ProgressStatus.Finished)
                {
                    progressBar1.Value = progressBar1.Maximum;
                }
                if (args.Status == ProgressStatus.Started)
                {
                    progressBar1.Value = progressBar1.Minimum;
                }

                lineCountControl1.LineCount = args.CurrentLineCount;
                lblProgressMessage.Text     = args.CurrentMessage;
                lblProgressMessage.Refresh();
            }
        }
        /// <summary>
        /// Method for retriveing the sub directories within this folder.
        /// Method is recursive and retrieves all sub folders.
        /// </summary>
        /// <param name="root">Full folder path</param>
        /// <param name="alFolders">Array list to store the folders in</param>
        /// <param name="OnProgress">Call back method to provide progress information</param>
        public void GetDirectories(string root, ArrayList alFolders, ProgressDelegate OnProgress)
        {
            if (OnProgress != null)
            {
                CodeLineCounterLibrary.LineCounterProgresArgs args = new LineCounterProgresArgs();
                args.CurrentMessage = "Querying Folder: " + root;
                OnProgress(args);
            }

            alFolders.Add(root);
            string[] folders = System.IO.Directory.GetDirectories(root);

            foreach (string folder in folders)
            {
                try
                {
                    GetDirectories(folder, alFolders, OnProgress);
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
            }
        }
        /// <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);
        }