/misc/Com.Hertkorn.Framework.SourceCodeManagement/Com.Hertkorn.Framework.SourceCodeManagement/VisualStudio/Solution.cs

https://github.com/dun3/dun3 · C# · 119 lines · 102 code · 16 blank · 1 comment · 6 complexity · 7f0c7004592ca497664c4961837e5733 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Text.RegularExpressions;
  6. namespace Com.Hertkorn.Framework.SourceCodeManagement.VisualStudio
  7. {
  8. [DebuggerDisplay("{this.GetType().Name}: Path={RawSolutionPath}, Version={Version.ToString()}, Subprojects: {ProjectListe.Count}")]
  9. public class Solution : ISolutionInfo
  10. {
  11. private string m_rawContent = string.Empty;
  12. public string RawContent
  13. {
  14. get { return m_rawContent; }
  15. }
  16. private FileInfo m_solutionFile;
  17. public FileInfo SolutionFile
  18. {
  19. get { return m_solutionFile; }
  20. }
  21. public string RawSolutionPath
  22. {
  23. get { return m_solutionFile.FullName; }
  24. }
  25. public Solution(FileInfo solutionFile)
  26. {
  27. m_solutionFile = solutionFile;
  28. StreamReader sr = solutionFile.OpenText();
  29. m_rawContent = sr.ReadToEnd();
  30. parseRawContent(m_rawContent);
  31. }
  32. protected virtual void parseRawContent(string rawContent)
  33. {
  34. parseVersion(rawContent);
  35. parseProjectListe(rawContent);
  36. }
  37. public static readonly string GROUPNAME_VERSION = "version";
  38. public static readonly Regex PARSE_VERSION_REGEX = new Regex(@"Microsoft Visual Studio Solution File, Format Version (?<" + GROUPNAME_VERSION + ">[0-9\\.]+)", RegexOptions.Compiled | RegexOptions.Multiline);
  39. protected virtual void parseVersion(string rawContent)
  40. {
  41. MatchCollection mc = PARSE_VERSION_REGEX.Matches(rawContent);
  42. if (mc.Count == 1)
  43. {
  44. if (mc[0].Groups[GROUPNAME_VERSION].Value == "10.00")
  45. {
  46. m_version = VisualStudioVersion.VS2008;
  47. }
  48. }
  49. }
  50. public static readonly string GROUPNAME_PROJECT_TYPE = "type";
  51. public static readonly string GROUPNAME_PROJECT_GUID = "guid";
  52. public static readonly string GROUPNAME_PROJECT_NAME = "name";
  53. public static readonly string GROUPNAME_PROJECT_PATH = "path";
  54. public static readonly string REGEX_MATCH_GUID = "\\{[a-zA-Z0-9\\-]{36}\\}";
  55. //Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "De.Hbv.Framework.Helper", "..\De.Hbv.Framework\Helper\Helper\De.Hbv.Framework.Helper.csproj", "{70EE87C0-4295-4681-97FB-1E9549549B8B}"
  56. public static readonly Regex PARSE_SOLUTION_REGEX
  57. = new Regex(
  58. "Project\\(\"(?<" + GROUPNAME_PROJECT_TYPE + ">" + REGEX_MATCH_GUID + ")\"\\) = "
  59. + "\"(?<" + GROUPNAME_PROJECT_NAME + ">[^\\\"]+)\", "
  60. + "\"(?<" + GROUPNAME_PROJECT_PATH + ">[^\\\"]+)\", "
  61. + "\"(?<" + GROUPNAME_PROJECT_GUID + ">" + REGEX_MATCH_GUID + ")\"",
  62. RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.Multiline);
  63. protected virtual void parseProjectListe(string rawContent)
  64. {
  65. List<ISolutionProjectInfo> projectInfoListe = new List<ISolutionProjectInfo>();
  66. MatchCollection mc = PARSE_SOLUTION_REGEX.Matches(rawContent);
  67. foreach (Match match in mc)
  68. {
  69. #warning TODO: Warum hier 5!?
  70. if (match.Groups.Count == 5)
  71. {
  72. projectInfoListe.Add(new ProjectSubItem
  73. {
  74. ProjectTypeGuid = new Guid(match.Groups[GROUPNAME_PROJECT_TYPE].Value),
  75. ProjectName = match.Groups[GROUPNAME_PROJECT_NAME].Value,
  76. RawProjectPath = match.Groups[GROUPNAME_PROJECT_PATH].Value,
  77. ProjectGuid = new Guid(match.Groups[GROUPNAME_PROJECT_GUID].Value)
  78. });
  79. }
  80. }
  81. m_projectListe = projectInfoListe;
  82. }
  83. private VisualStudioVersion m_version = VisualStudioVersion.Unknown;
  84. public VisualStudioVersion Version
  85. {
  86. get { return m_version; }
  87. }
  88. private List<ISolutionProjectInfo> m_projectListe = new List<ISolutionProjectInfo>();
  89. public IList<ISolutionProjectInfo> ProjectListe
  90. {
  91. get { return m_projectListe; }
  92. }
  93. private class ProjectSubItem : ISolutionProjectInfo
  94. {
  95. #region ISolutionProjectInfo Members
  96. public Guid ProjectTypeGuid { get; set; }
  97. public Guid ProjectGuid { get; set; }
  98. public string ProjectName { get; set; }
  99. public string RawProjectPath { get; set; }
  100. #endregion
  101. }
  102. }
  103. }