Skip to content

Commit

Permalink
Several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Oct 5, 2019
1 parent bae30e6 commit 3da540b
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 106 deletions.
12 changes: 3 additions & 9 deletions src/BuildVision.Contracts/Models/BuildProjectContextEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,17 @@ namespace BuildVision.UI.Contracts
{
public class BuildProjectContextEntry
{
public int InstanceId { get; set; }

public int ContextId { get; set; }

public string FileName { get; set; }
public string ProjectFile { get; set; }

public IDictionary<string, string> Properties { get; }

public IProjectItem ProjectItem { get; set; }

public bool IsInvalid { get; set; }

public BuildProjectContextEntry(int instanceId, int contextId, string fileName, IDictionary<string, string> properties)
public BuildProjectContextEntry(string fileName, IDictionary<string, string> properties)
{
InstanceId = instanceId;
ContextId = contextId;
FileName = fileName;
ProjectFile = fileName;
Properties = properties;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/BuildVision.Contracts/Models/IBuildInformationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public interface IBuildInformationModel : INotifyPropertyChanged
string StateIconKey { get; }
IProjectItem CurrentProject { get; set; }

int GetFinishedProjectsCount();
void ResetState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public interface IBuildInformationProvider
void ResetCurrentProjects();
void BuildFinished(bool success, bool canceled);
void BuildStarted(BuildAction currentBuildAction, BuildScope scope);
void BuildUpdate();
void ResetBuildInformationModel();

event Action BuildStateChanged;
}
}
2 changes: 1 addition & 1 deletion src/BuildVision.UI/Helpers/BuildMessagesFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static string GetActionName(BuildAction buildAction)
case BuildAction.Clean:
return Resources.BuildActionClean;
default:
throw new ArgumentOutOfRangeException(nameof(buildAction));
throw new ArgumentOutOfRangeException(nameof(buildAction), $"Actual: {buildAction}");
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/BuildVision.UI/Models/BuildInformationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ private BuildResultState GetBuildResultState()
}
}

public int GetFinishedProjectsCount() => SucceededProjectsCount + UpToDateProjectsCount + WarnedProjectsCount + FailedProjectsCount;

public void ResetState()
{
ErrorCount = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/BuildVision.UI/ViewModels/BuildVisionPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ public BuildVisionPaneViewModel(
SolutionModel = solutionProvider.GetSolutionModel();
ControlSettings = settingsProvider.Settings;
Projects = _buildInformationProvider.Projects;


_buildInformationProvider.BuildStateChanged += () => OnPropertyChanged(nameof(GroupedProjectsList));

_settingsProvider = settingsProvider;
_settingsProvider.SettingsChanged += () =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/BuildVision/Core/BuildVisionPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void SolutionEvents_Opened()
_buildInformationProvider.ResetCurrentProjects();
_buildInformationProvider.ResetBuildInformationModel();

_solutionBuildEvents = new SolutionBuildEvents(_solutionProvider, _buildInformationProvider, _serviceProvider);
_solutionBuildEvents = new SolutionBuildEvents(_solutionProvider, _buildInformationProvider, _serviceProvider, LogManager.ForContext<SolutionBuildEvents>());
_solutionBuildManager.AdviseUpdateSolutionEvents(_solutionBuildEvents, out _updateSolutionEventsCookie);
_solutionBuildManager4.AdviseUpdateSolutionEvents4(_solutionBuildEvents, out _updateSolutionEvents4Cookie);
}
Expand Down
78 changes: 61 additions & 17 deletions src/BuildVision/Core/SolutionBuildEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,105 @@
using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using Serilog;

namespace BuildVision.Core
{
public class SolutionBuildEvents : IVsUpdateSolutionEvents2, IVsUpdateSolutionEvents4
{
private readonly ISolutionProvider _solutionProvider;
private readonly IBuildInformationProvider _buildInformationProvider;
private readonly ILogger _logger;
private readonly BuildEvents _buildEvents;
private BuildAction _currentBuildAction;

public SolutionBuildEvents(
ISolutionProvider solutionProvider,
IBuildInformationProvider buildInformationProvider,
IServiceProvider serviceProvider)
IServiceProvider serviceProvider,
ILogger logger)
{
_solutionProvider = solutionProvider;
_buildInformationProvider = buildInformationProvider;
_logger = logger;
_buildEvents = (serviceProvider.GetService(typeof(DTE)) as DTE).Events.BuildEvents;
_buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
}

public void UpdateSolution_BeginUpdateAction(uint dwAction)
{
_solutionProvider.ReloadSolution();
_currentBuildAction = StateConverterHelper.ConvertSolutionBuildFlagsToBuildAction(dwAction, (VSSOLNBUILDUPDATEFLAGS)dwAction);
_buildInformationProvider.ReloadCurrentProjects();
try
{
_solutionProvider.ReloadSolution();
_currentBuildAction = StateConverterHelper.ConvertSolutionBuildFlagsToBuildAction(dwAction, (VSSOLNBUILDUPDATEFLAGS)dwAction);
_buildInformationProvider.ReloadCurrentProjects();
}
catch (Exception ex)
{
_logger.Error(ex, "");
throw;
}
}

private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action)
{
// We use the action from UpdateSolution_BeginUpdateAction here because it givs closer details on the current action
_buildInformationProvider.BuildStarted(_currentBuildAction, (BuildScope)scope);
try
{
// We use the action from UpdateSolution_BeginUpdateAction here because it givs closer details on the current action
_buildInformationProvider.BuildStarted(_currentBuildAction, (BuildScope)scope);
}
catch (Exception ex)
{
_logger.Error(ex, "");
throw;
}
}

public int UpdateProjectCfg_Begin(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, ref int pfCancel)
{
var projectItem = new UI.Models.ProjectItem();
var configPair = pCfgProj.ToConfigurationTuple();
SolutionProjectsExtensions.UpdateProperties(pHierProj.ToProject(), projectItem, configPair.Item1, configPair.Item2);
var buildAction = StateConverterHelper.ConvertSolutionBuildFlagsToBuildAction(dwAction, (VSSOLNBUILDUPDATEFLAGS)dwAction);
_buildInformationProvider.ProjectBuildStarted(projectItem, buildAction);
return VSConstants.S_OK;
try
{
var projectItem = new UI.Models.ProjectItem();
var configPair = pCfgProj.ToConfigurationTuple();
SolutionProjectsExtensions.UpdateProperties(pHierProj.ToProject(), projectItem, configPair.Item1, configPair.Item2);
var buildAction = StateConverterHelper.ConvertSolutionBuildFlagsToBuildAction(dwAction, (VSSOLNBUILDUPDATEFLAGS)dwAction);
_buildInformationProvider.ProjectBuildStarted(projectItem, buildAction);
return VSConstants.S_OK;
}
catch (Exception ex)
{
_logger.Error(ex, "");
throw;
}
}

public int UpdateProjectCfg_Done(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, int fSuccess, int fCancel)
{
var buildAction = StateConverterHelper.ConvertSolutionBuildFlagsToBuildAction(dwAction, (VSSOLNBUILDUPDATEFLAGS)dwAction);
_buildInformationProvider.ProjectBuildFinished(buildAction, ProjectIdentifierGenerator.GetIdentifierForInteropTypes(pHierProj, pCfgProj), fSuccess == 1, fCancel == 1);
return VSConstants.S_OK;
try
{
var buildAction = StateConverterHelper.ConvertSolutionBuildFlagsToBuildAction(dwAction, (VSSOLNBUILDUPDATEFLAGS)dwAction);
_buildInformationProvider.ProjectBuildFinished(buildAction, ProjectIdentifierGenerator.GetIdentifierForInteropTypes(pHierProj, pCfgProj), fSuccess == 1, fCancel == 1);
return VSConstants.S_OK;
}
catch (Exception ex)
{
_logger.Error(ex, "");
throw;
}
}

public int UpdateSolution_Done(int fSucceeded, int fModified, int fCancelCommand)
{
_buildInformationProvider.BuildFinished(fSucceeded == 1, fCancelCommand == 1);
return VSConstants.S_OK;
try
{
_buildInformationProvider.BuildFinished(fSucceeded == 1, fCancelCommand == 1);
return VSConstants.S_OK;
}
catch (Exception ex)
{
_logger.Error(ex, "");
throw;
}
}

#region Interface Implementation
Expand Down
9 changes: 5 additions & 4 deletions src/BuildVision/Helpers/ProjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public static class ProjectExtensions

private static readonly Dictionary<string, string> _knownProjectTypes = new Dictionary<string, string>
{
{"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "Windows"}, // C#
{"{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "Windows"}, // VB.NET
{"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", "Windows"}, // C++
{"{F2A71F9B-5D33-465A-A702-920D77279786}", "Windows"}, // F#
{"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}", "Windows C#"}, // C#
{"{F184B08F-C81C-45F6-A57F-5ABD9991F28F}", "Windows VB.NET"}, // VB.NET
{"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}", "Windows C++"}, // C++
{"{F2A71F9B-5D33-465A-A702-920D77279786}", "Windows F#"}, // F#
{"{D954291E-2A0B-460D-934E-DC6B0785DB48}", "Shared Project" },
{"{349C5851-65DF-11DA-9384-00065B846F21}", "Web Application"},
{"{E24C65DC-7377-472B-9ABA-BC803B73C61A}", "Web Site"},
{"{603c0e0b-db56-11dc-be95-000d561079b0}", "ASP.NET MVC1"},
Expand Down
18 changes: 14 additions & 4 deletions src/BuildVision/Helpers/SolutionProjectsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public static IList<Project> GetProjects(this Solution solution)
continue;
}

if (project.FileName.EndsWith(".shproj")) // Shared Projects shouldn´t be displayed in BuildVision
{
continue;
}

if (project.Kind == EnvDTEProjectKinds.ProjectKindSolutionFolder)
{
list.AddRange(project.GetSubProjects());
Expand Down Expand Up @@ -163,7 +168,7 @@ public static void UpdateProperties(Project project, ProjectItem projectItem, st
Configuration config;
try
{
config = project.ConfigurationManager.ActiveConfiguration;
config = project.ConfigurationManager?.ActiveConfiguration;
}
catch (Exception ex)
{
Expand All @@ -178,6 +183,14 @@ public static void UpdateProperties(Project project, ProjectItem projectItem, st
}
else
{
if (project.ConfigurationManager == null)
{
LogManager.ForContext<Solution>().Warning("ConfigurationManager for project {UniqueName} was null.", project?.UniqueName);
}
else if (project.ConfigurationManager.ActiveConfiguration == null)
{
LogManager.ForContext<Solution>().Warning("ActiveConfiguration for project {UniqueName} was null.", project?.UniqueName);
}
projectItem.Configuration = @"N\A";
projectItem.Platform = @"N\A";
}
Expand All @@ -188,14 +201,11 @@ public static void UpdateProperties(Project project, ProjectItem projectItem, st
try
{
projectItem.Framework = project.GetFrameworkString();

var flavourTypes = project.GetFlavourTypes().ToList();
projectItem.FlavourType = string.Join("; ", flavourTypes);
projectItem.MainFlavourType = flavourTypes.FirstOrDefault();

projectItem.OutputType = project.GetOutputType();
projectItem.ExtenderNames = project.GetExtenderNames();

projectItem.RootNamespace = project.GetRootNamespace();
}
catch (Exception ex)
Expand Down
Loading

0 comments on commit 3da540b

Please sign in to comment.