/// <summary>
        /// Adds a summary item to the projects list view.
        /// </summary>
        /// <param name="summary">The summary data object to reference.</param>
        /// <param name="group">The summary list view group this item
        /// should be listed under.</param>
        private void AddSummaryListItem(LineCountSummary summary, ListViewGroup group)
        {
            ListViewItem lvi = new ListViewItem();

            lvi.Text = summary.ProjectName;
            lvi.SubItems.Add("0");
            lvi.SubItems.Add("0");
            lvi.SubItems.Add("0");
            lvi.SubItems.Add("0");
            lvi.SubItems.Add("0");

            lvi.Tag        = summary;
            lvi.ImageIndex = summary.IconIndex;
            //lvi.StateImageIndex = summary.IconIndex;
            lvi.Group = group;

            summary.LinkedListViewItem = lvi;

            lvSummary.Items.Add(lvi);
        }
 /// <summary>
 /// Scans the project items (files, usually) of
 /// a project's ProjectItems collection.
 /// </summary>
 /// <param name="projectItems">The ProjectItems collection to scan.</param>
 /// <param name="summary">The root summary data object that these
 /// files belong to.</param>
 private void ScanProjectItems(IList <ProjectItem> projectItems, LineCountSummary summary)
 {
     tsprgTask.Maximum += projectItems.Count;
     foreach (ProjectItem projectItem in projectItems)
     {
         tsprgTask.PerformStep();
         if (!(projectItem is FileProjectItem))
         {
             // Skip references and other special MSBuild things
             continue;
         }
         string projectFile = projectItem.FileName;
         if (!Directory.Exists(projectFile))
         {
             int iconIndex = 0;
                                 #if IMPR1
             iconIndex = fileImageListHelper.GetIndex(IconService.GetImageForFile(projectFile));
                                 #else
             m_fileIconMappings.TryGetValue(Path.GetExtension(projectFile), out iconIndex);
                                 #endif
             summary.FileLineCountInfo.Add(new LineCountInfo(projectFile, iconIndex, summary));
         }
     }
 }
        /// <summary>
        /// Performs a complete counting and summation of all lines
        /// in all projects and files.
        /// </summary>
        private void SumSolution()
        {
            try
            {
                // Clean the list
                lvSummary.Items.Clear();
                lvFileList.Items.Clear();
                lvFileList.Groups.Clear();

                // Configure progress bars
                tsprgTotal.Minimum = 0;
                tsprgTotal.Step    = 1;
                tsprgTask.Minimum  = 0;
                tsprgTask.Step     = 1;

                // Skip if there are no projects
                if (m_summaryList == null || (m_summaryList != null && m_summaryList.Count == 1))
                {
                    MessageBox.Show("There are no projects loaded to summarize.", "Line Counter");
                    return;
                }

                // Get all projects summary
                LineCountSummary allProjects = m_summaryList[0];
                allProjects.LineCountSummaryDetails.Reset();
                AddSummaryListItem(allProjects, lvSummary.Groups["lvgAllProj"]);

                tsprgTotal.Maximum = m_summaryList.Count;
                tsprgTotal.Value   = 0;
                for (int s = 1; s < m_summaryList.Count; s++)
                {
                    tsprgTotal.PerformStep();

                    LineCountSummary summary = m_summaryList[s];
                    summary.LineCountSummaryDetails.Reset();
                    AddSummaryListItem(summary, lvSummary.Groups["lvgEachProj"]);

                    tsprgTask.Maximum = summary.FileLineCountInfo.Count;
                    tsprgTask.Value   = 0;
                    for (int i = 0; i < summary.FileLineCountInfo.Count; i++)
                    {
                        tsprgTask.PerformStep();

                        LineCountInfo info = summary.FileLineCountInfo[i];
                        if (m_countableTypes.Contains(info.FileType))
                        {
                            info.LineCountInfoDetails.Reset();
                                                        #if IMPR2
                            foreach (CountingAlgorithmDescriptor desc in countingAlgorithms)
                            {
                                if (desc.CanCountLines(info))
                                {
                                    desc.GetAlgorithm().CountLines(info);
                                    break;
                                }
                            }
                                                        #else
                            try
                            {
                                CountLines counter = m_countAlgorithms[info.FileType];
                                counter(info);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                                Console.WriteLine(ex.StackTrace);
                            }
                                                        #endif
                            info.LineCountInfoDetails.Summarize();

                            allProjects.LineCountSummaryDetails.Add(info.LineCountInfoDetails);
                            summary.LineCountSummaryDetails.Add(info.LineCountInfoDetails);

                            tstxtLinesCounted.Text = allProjects.LineCountSummaryDetails.TotalLines.ToString();

                            AddFileListItem(info);
                        }
                    }

                    summary.LineCountSummaryDetails.Summarize();
                    LineCountDetails details = summary.LineCountSummaryDetails;
                    summary.LinkedListViewItem.SubItems[1].Text = details.TotalLines.ToString();
                    summary.LinkedListViewItem.SubItems[2].Text = details.CodeLines.ToString();
                    summary.LinkedListViewItem.SubItems[3].Text = details.CommentLines.ToString();
                    summary.LinkedListViewItem.SubItems[4].Text = details.BlankLines.ToString();
                    summary.LinkedListViewItem.SubItems[5].Text = details.NetLines.ToString();
                    details = null;
                }

                allProjects.LineCountSummaryDetails.Summarize();
                LineCountDetails totals = allProjects.LineCountSummaryDetails;
                allProjects.LinkedListViewItem.SubItems[1].Text = totals.TotalLines.ToString();
                allProjects.LinkedListViewItem.SubItems[2].Text = totals.CodeLines.ToString();
                allProjects.LinkedListViewItem.SubItems[3].Text = totals.CommentLines.ToString();
                allProjects.LinkedListViewItem.SubItems[4].Text = totals.BlankLines.ToString();
                allProjects.LinkedListViewItem.SubItems[5].Text = totals.NetLines.ToString();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }

            tsprgTotal.Value = tsprgTotal.Maximum;
        }
        /// <summary>
        /// Scans the solution and creates a hierarchy of
        /// support objects for each project and file
        /// within each project.
        /// </summary>
        private void ScanSolution()
        {
            if (m_summaryList == null)
            {
                m_summaryList = new List <LineCountSummary>();
            }

            m_summaryList.Clear();

            Solution solution = ProjectService.OpenSolution;

            if (solution != null)             // OpenSolution is null when no solution is opened
            {
                FileInfo         fiSolution = new FileInfo(solution.FileName);
                LineCountSummary summary    = new LineCountSummary("All Projects", m_projIconMappings["{00000000-0000-0000-0000-000000000000}"]);
                m_summaryList.Add(summary);

                // Configure progress bars
                tsprgTotal.Minimum = 0;
                tsprgTotal.Step    = 1;
                tsprgTask.Minimum  = 0;
                tsprgTask.Step     = 1;

                List <IProject> projects = new List <IProject>(solution.Projects);
                tsprgTotal.Maximum = projects.Count;
                tsprgTask.Value    = 0;
                foreach (IProject fiProject in projects)
                {
                    tsprgTotal.PerformStep();
                    string projName, lang;
                    if (fiProject.FileName.IndexOf("://") != -1)
                    {
                        projName = fiProject.FileName;                         // this is a web project
                        lang     = "{00000001-0000-0000-0000-000000000000}";
                    }
                    else
                    {
                        projName = fiProject.Name;
                        lang     = fiProject.TypeGuid;
                    }

                    int iconIndex;
                                        #if IMPR1
                    iconIndex = projectImageListHelper.GetIndex(IconService.GetImageForProjectType(fiProject.Language ?? "defaultLanguageName"));
                                        #else
                    m_projIconMappings.TryGetValue(lang, out iconIndex);                     // default icon 0
                                        #endif
                    summary = new LineCountSummary(projName, iconIndex);
                    m_summaryList.Add(summary);

                    tsprgTask.Maximum = 0;
                    tsprgTotal.Value  = 0;
                    ScanProjectItems(fiProject.Items, summary);
                }

                tsprgTask.Value  = tsprgTask.Maximum;
                tsprgTotal.Value = tsprgTotal.Maximum;
            }
            else
            {
                MessageBox.Show("There is no solution open in SharpDevelop.", "Line Counter");
            }
        }
 public LineCountInfo(string fileName, int iconIndex, LineCountSummary projectSummary) : this(fileName, iconIndex)
 {
     m_projectSummary = projectSummary;
 }
		/// <summary>
		/// Adds a summary item to the projects list view.
		/// </summary>
		/// <param name="summary">The summary data object to reference.</param>
		/// <param name="group">The summary list view group this item
		/// should be listed under.</param>
		private void AddSummaryListItem(LineCountSummary summary, ListViewGroup group)
		{
			ListViewItem lvi = new ListViewItem();
			lvi.Text = summary.ProjectName;
			lvi.SubItems.Add("0");
			lvi.SubItems.Add("0");
			lvi.SubItems.Add("0");
			lvi.SubItems.Add("0");
			lvi.SubItems.Add("0");

			lvi.Tag = summary;
			lvi.ImageIndex = summary.IconIndex;
			//lvi.StateImageIndex = summary.IconIndex;
			lvi.Group = group;

			summary.LinkedListViewItem = lvi;

			lvSummary.Items.Add(lvi);
		}
		/// <summary>
		/// Scans the project items (files, usually) of
		/// a project's ProjectItems collection.
		/// </summary>
		/// <param name="projectItems">The ProjectItems collection to scan.</param>
		/// <param name="summary">The root summary data object that these
		/// files belong to.</param>
		private void ScanProjectItems(IMutableModelCollection<ProjectItem> projectItems, LineCountSummary summary)
		{
			tsprgTask.Maximum += projectItems.Count;
			foreach (ProjectItem projectItem in projectItems)
			{
				tsprgTask.PerformStep();
				if (!(projectItem is FileProjectItem)) {
					// Skip references and other special MSBuild things
					continue;
				}
				string projectFile = projectItem.FileName;
				if (!Directory.Exists(projectFile))
				{
					int iconIndex = 0;
					#if IMPR1
					iconIndex = fileImageListHelper.GetIndex(IconService.GetImageForFile(projectFile));
					#else
					m_fileIconMappings.TryGetValue(Path.GetExtension(projectFile), out iconIndex);
					#endif
					summary.FileLineCountInfo.Add(new LineCountInfo(projectFile, iconIndex, summary));
				}
			}
		}
		/// <summary>
		/// Scans the solution and creates a hierarchy of
		/// support objects for each project and file
		/// within each project.
		/// </summary>
		private void ScanSolution()
		{
			if (m_summaryList == null)
				m_summaryList = new List<LineCountSummary>();

			m_summaryList.Clear();
			
			ISolution solution = ProjectService.OpenSolution;
			if (solution != null) // OpenSolution is null when no solution is opened
			{
				FileInfo fiSolution = new FileInfo(solution.FileName);
				LineCountSummary summary = new LineCountSummary("All Projects", m_projIconMappings["{00000000-0000-0000-0000-000000000000}"]);
				m_summaryList.Add(summary);

				// Configure progress bars
				tsprgTotal.Minimum = 0;
				tsprgTotal.Step = 1;
				tsprgTask.Minimum = 0;
				tsprgTask.Step = 1;

				List<IProject> projects = new List<IProject>(solution.Projects);
				tsprgTotal.Maximum = projects.Count;
				tsprgTask.Value = 0;
				foreach (IProject fiProject in projects) {
					tsprgTotal.PerformStep();
					string projName;
					Guid lang;
					if (fiProject.FileName.ToString().IndexOf("://") != -1)
					{
						projName = fiProject.FileName; // this is a web project
						lang = Guid.Parse("{00000001-0000-0000-0000-000000000000}");
					} else {
						projName = fiProject.Name;
						lang = fiProject.TypeGuid;
					}

					int iconIndex;
					#if IMPR1
					iconIndex = projectImageListHelper.GetIndex(IconService.GetImageForProjectType(fiProject.Language ?? "defaultLanguageName"));
					#else
					m_projIconMappings.TryGetValue(lang, out iconIndex); // default icon 0
					#endif
					summary = new LineCountSummary(projName, iconIndex);
					m_summaryList.Add(summary);

					tsprgTask.Maximum = 0;
					tsprgTotal.Value = 0;
					ScanProjectItems(fiProject.Items, summary);
				}

				tsprgTask.Value = tsprgTask.Maximum;
				tsprgTotal.Value = tsprgTotal.Maximum;
			}
			else
			{
				MessageBox.Show("There is no solution open in SharpDevelop.", "Line Counter");
			}
		}
		public LineCountInfo(string fileName, int iconIndex, LineCountSummary projectSummary) : this(fileName, iconIndex)
		{
			m_projectSummary = projectSummary;
		}