• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HicServices / RDMP / 9118172652

16 May 2024 07:38PM UTC coverage: 56.911% (+0.009%) from 56.902%
9118172652

push

github

jas88
Fix multiple enumerations

A

10817 of 20482 branches covered (52.81%)

Branch coverage included in aggregate %.

6 of 13 new or added lines in 5 files covered. (46.15%)

39 existing lines in 6 files now uncovered.

30824 of 52687 relevant lines covered (58.5%)

7403.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.65
/Rdmp.Core/ReusableLibraryCode/VisualStudioSolutionFileProcessing/VisualStudioSolutionFile.cs
1
// Copyright (c) The University of Dundee 2018-2019
2
// This file is part of the Research Data Management Platform (RDMP).
3
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
6

7
using System;
8
using System.Collections.Generic;
9
using System.IO;
10
using System.Linq;
11
using System.Text.RegularExpressions;
12

13
namespace Rdmp.Core.ReusableLibraryCode.VisualStudioSolutionFileProcessing;
14

15
/// <summary>
16
/// Reference to a .sln file in which we can extract all the solution folders and project references.
17
/// </summary>
18
public class VisualStudioSolutionFile
19
{
20
    public DirectoryInfo SolutionDirectory { get; private set; }
2✔
21
    public VisualStudioSolutionFolder[] RootFolders { get; set; }
4✔
22
    public VisualStudioProjectReference[] RootProjects { get; set; }
4✔
23

24
    public List<VisualStudioProjectReference> Projects { get; private set; }
24✔
25
    public List<VisualStudioSolutionFolder> Folders { get; private set; }
50✔
26

27
    public VisualStudioSolutionFile(DirectoryInfo solutionDirectory, FileInfo slnFile)
2✔
28
    {
29
        SolutionDirectory = solutionDirectory;
2✔
30

31
        var slnFileContents = File.ReadAllText(slnFile.FullName);
2✔
32

33
        //                                                           Group 1             Group 2                       Group4
34
        var projReg =
2✔
35
            new Regex(
2✔
36
                @"Project\(\""\{[\w-]*\}\""\) = \""([\w _]*.*)\"", \""(.*\.(cs|vcx|vb)proj)\"", \""({[\w-]*\})\""",
2✔
37
                RegexOptions.Compiled);
2✔
38
        //                                                           Group 1                Group 2            Group3
39
        var folderReg =
2✔
40
            new Regex(@"Project\(\""\{[\w-]*\}\""\) = \""([\w _]*.*)\"", \""([\w\.]*)\"", \""({[\w-]*\})\""",
2✔
41
                RegexOptions.Compiled);
2✔
42

43
        Projects = new List<VisualStudioProjectReference>();
2✔
44
        Folders = new List<VisualStudioSolutionFolder>();
2✔
45

46
        //VisualStudioProjectReference("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CachingUI", "Caching\CachingUI\CachingUI.csproj", "{D91F4688-A8BD-4B60-97B6-DFA64A875CFF}"
47
        foreach (Match m in projReg.Matches(slnFileContents))
32✔
48
            Projects.Add(new VisualStudioProjectReference(m.Groups[1].Value, m.Groups[2].Value, m.Groups[4].Value));
14✔
49

50
        foreach (Match m in folderReg.Matches(slnFileContents))
20✔
51
        {
52
            if (!m.Groups[1].Value.Equals(m.Groups[2].Value))
8!
53
                throw new Exception(
×
54
                    $"Expected folder name to be the same as folder text when evaluating the projects in solution {slnFile.FullName} (Regex matches were'{m.Groups[1].Value}' and '{m.Groups[2].Value}')");
×
55

56
            Folders.Add(new VisualStudioSolutionFolder(m.Groups[2].Value, m.Groups[3].Value));
8✔
57
        }
58

59
        var slnFileLines = File.ReadAllLines(slnFile.FullName);
2✔
60

61
        /*
62
GlobalSection(NestedProjects) = preSolution
63
    {FDF08240-2AFC-48A4-8F48-37CC7EA3000B} = {264C99E2-E3F5-4001-87EA-9CB1B06204AA}
64
    {16187832-4783-4FD5-A4C7-76E5E3254749} = {264C99E2-E3F5-4001-87EA-9CB1B06204AA}
65
         EndGlobalSection*/
66

67
        var enteredRelationshipsBit = false;
2✔
68
        foreach (var line in slnFileLines)
1,246✔
69
        {
70
            var trim = line.Trim();
622✔
71
            if (trim.Equals(@"GlobalSection(NestedProjects) = preSolution"))
622✔
72
            {
73
                enteredRelationshipsBit = true;
2✔
74
                continue;
2✔
75
            }
76

77
            if (trim.Equals("EndGlobalSection") && enteredRelationshipsBit)
620✔
78
                break;
79

80
            if (string.IsNullOrWhiteSpace(line))
618✔
81
                continue;
82

83
            if (!enteredRelationshipsBit) continue;
618✔
84

85
            var split = line.Split('=');
6✔
86

87
            var thingInside = split[0].Trim();
6✔
88
            var thingHoldingIt = split[1].Trim();
6✔
89

90
            var folderInside = Folders.SingleOrDefault(f => f.Guid.Equals(thingInside));
30✔
91
            var folderHoldingIt = Folders.SingleOrDefault(f => f.Guid.Equals(thingHoldingIt));
30✔
92

93
            if (folderHoldingIt == null)
6✔
94
                continue;
95

96
            if (folderInside != null)
4!
97
            {
UNCOV
98
                folderHoldingIt.ChildrenFolders.Add(folderInside);
×
99
            }
100
            else
101
            {
102
                var visualStudioProjectReferenceInside = Projects.Single(p => p.Guid.Equals(thingInside));
32✔
103
                Folders.Single(f => f.Guid.Equals(thingHoldingIt)).ChildrenProjects
20✔
104
                    .Add(visualStudioProjectReferenceInside);
4✔
105
            }
106
        }
107

108
        RootFolders = Folders.Where(f => !Folders.Any(f2 => f2.ChildrenFolders.Contains(f))).ToArray();
42✔
109
        RootProjects = Projects.Where(p => !Folders.Any(f => f.ChildrenProjects.Contains(p))).ToArray();
62✔
110
    }
2✔
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc