Ejemplo n.º 1
0
        /// <summary>
        /// Adds a Visual Studio CSharp project file and
        /// adds its source files to the list of files to be
        /// checked by StyleCop.
        /// </summary>
        /// <param name="projectFilePath">
        /// The fully-qualified path to the project file.
        /// </param>
        /// <param name="solutionsRow">
        /// The solutions row this project belongs to. Specify
        /// null if this project is not a member of a solution.
        /// </param>
        private void AddProjectFile(
            string projectFilePath,
            StyleCopReport.SolutionsRow solutionsRow)
        {
            // Get the project's name.
            var pname = Path.GetFileNameWithoutExtension(projectFilePath);

            if (solutionsRow == null)
            {
                solutionsRow = this.Report.Solutions.AddSolutionsRow(
                    projectFilePath,
                    "Project - " + pname);
            }

            // Add a new project row.
            var pr = this.Report.Projects.AddProjectsRow(
                projectFilePath,
                pname,
                solutionsRow);

            var pf = XDocument.Load(projectFilePath);

            // ReSharper disable PossibleNullReferenceException

            // Get the source files that are not auto-generated.
            var cnodes =
                pf.Root.Descendants().Where(
                    d => d.Name.LocalName == "Compile" &&
                    d.Attribute(XName.Get("Include")).Value.EndsWith(
                        "cs",
                        StringComparison.CurrentCultureIgnoreCase) &&
                    d.Elements().SingleOrDefault(
                        c =>
                        c.Name.LocalName == "AutoGen" &&
                        c.Value == "True") ==
                    null);

            // Add the source files.
            foreach (var n in cnodes)
            {
                var fpath =
                    Path.GetFullPath(Path.GetDirectoryName(projectFilePath))
                    + Path.DirectorySeparatorChar.ToString() + n.Attribute(XName.Get("Include")).Value;

                this.AddFile(
                    fpath,
                    solutionsRow,
                    pr);
            }

            // ReSharper restore PossibleNullReferenceException
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add the given file to the list of files to
        /// be checked by StyleCop.
        /// </summary>
        /// <param name="filePath">
        /// The fully-qualified path of the file to add.
        /// </param>
        /// <param name="solutionsRow">
        /// The solutions row for this file.
        /// </param>
        /// <param name="projectsRow">
        /// The projects row for this file.
        /// </param>
        private void AddFile(
            string filePath,
            StyleCopReport.SolutionsRow solutionsRow,
            StyleCopReport.ProjectsRow projectsRow)
        {
            if (this.IgnorePatterns != null)
            {
                // Check to see if this file should be ignored.
                if (this.IgnorePatterns.FirstOrDefault(
                        fp => Regex.IsMatch(
                            Path.GetFileName(filePath),
                            fp)) != null)
                {
                    return;
                }
            }

            var sr = solutionsRow ??
                     this.Report.Solutions.SingleOrDefault(
                r => r.Name == "Files") ??
                     this.Report.Solutions.AddSolutionsRow(
                "Files",
                "Files");

            var pr = projectsRow ??
                     this.Report.Projects.SingleOrDefault(
                r => r.Name == "Files") ??
                     this.Report.Projects.AddProjectsRow(
                "Files",
                "Files",
                sr);

            var ext = Path.GetExtension(
                filePath).Replace(
                ".",
                string.Empty)
                      .ToUpper(CultureInfo.CurrentCulture);

            this.Report.SourceCodeFiles.AddSourceCodeFilesRow(
                filePath,
                File.GetLastWriteTimeUtc(filePath),
                ext,
                Path.GetFileName(filePath),
                pr);
        }