-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support parsing and retrieving SolutionGuid (#26)
* Support parsing and retrieving SolutionGuid Closes #23 * Fixed coding style Moved sln contents to external files Simplified and refactored code
- Loading branch information
Showing
13 changed files
with
174 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Global | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {7F92F20E-4C3D-4316-BF60-105559EFEAFF} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace SlnParser.Contracts.Helper | ||
{ | ||
internal interface ISectionParser | ||
{ | ||
IEnumerable<string> GetFileContentsInGlobalSection( | ||
IEnumerable<string> fileContents, | ||
string sectionName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using SlnParser.Contracts; | ||
using SlnParser.Contracts.Helper; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace SlnParser.Helper | ||
{ | ||
internal sealed class EnrichSolutionWithSolutionGuid : IEnrichSolution | ||
{ | ||
private readonly ISectionParser _sectionParser = new SectionParser(); | ||
|
||
public void Enrich(Solution solution, IEnumerable<string> fileContents) | ||
{ | ||
var extensibilityGlobals = _sectionParser.GetFileContentsInGlobalSection( | ||
fileContents, | ||
"ExtensibilityGlobals"); | ||
|
||
solution.Guid = extensibilityGlobals | ||
.Select(ExtractSolutionGuid) | ||
.FirstOrDefault(x => x.HasValue); | ||
} | ||
|
||
private Guid? ExtractSolutionGuid(string line) | ||
{ | ||
const string pattern = @"\s*SolutionGuid\s*=\s*{([A-Fa-f0-9\-]+)}"; | ||
var match = Regex.Match(line, pattern); | ||
if (!match.Success) | ||
{ | ||
return null; | ||
} | ||
|
||
var guidString = match.Groups[1].Value; | ||
return new Guid(guidString); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using SlnParser.Contracts.Helper; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace SlnParser.Helper | ||
{ | ||
internal class SectionParser : ISectionParser | ||
{ | ||
public IEnumerable<string> GetFileContentsInGlobalSection( | ||
IEnumerable<string> fileContents, | ||
string sectionName) | ||
{ | ||
var startSection = $"GlobalSection({sectionName}"; | ||
const string endSection = "EndGlobalSection"; | ||
|
||
return GetFileContentsInSection(fileContents, startSection, endSection); | ||
} | ||
|
||
private static IEnumerable<string> GetFileContentsInSection( | ||
IEnumerable<string> fileContents, | ||
string startSection, | ||
string endSection) | ||
{ | ||
var section = fileContents | ||
.SkipWhile(line => !line.StartsWith(startSection)) | ||
.TakeWhile(line => !line.StartsWith(endSection)) | ||
.Where(line => !line.StartsWith(startSection)) | ||
.Where(line => !line.StartsWith(endSection)) | ||
.Where(line => !string.IsNullOrWhiteSpace(line)); | ||
|
||
return section.ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters