From 3da540bb625b511e373c8244bb27f30251fc28c2 Mon Sep 17 00:00:00 2001 From: Stefan Kert Date: Sat, 5 Oct 2019 14:05:03 +0200 Subject: [PATCH] Several fixes --- .../Models/BuildProjectContextEntry.cs | 12 +-- .../Models/IBuildInformationModel.cs | 1 + .../Providers/IBuildInformationProvider.cs | 3 +- .../Helpers/BuildMessagesFactory.cs | 2 +- .../Models/BuildInformationModel.cs | 2 + .../ViewModels/BuildVisionPaneViewModel.cs | 4 +- src/BuildVision/Core/BuildVisionPackage.cs | 2 +- src/BuildVision/Core/SolutionBuildEvents.cs | 78 +++++++++++---- src/BuildVision/Helpers/ProjectExtensions.cs | 9 +- .../Helpers/SolutionProjectsExtensions.cs | 18 +++- .../Services/BuildInformationProvider.cs | 99 ++++++++++--------- src/BuildVision/Services/BuildOutputLogger.cs | 48 ++++----- 12 files changed, 172 insertions(+), 106 deletions(-) diff --git a/src/BuildVision.Contracts/Models/BuildProjectContextEntry.cs b/src/BuildVision.Contracts/Models/BuildProjectContextEntry.cs index 41b5a3c6..64f8528a 100644 --- a/src/BuildVision.Contracts/Models/BuildProjectContextEntry.cs +++ b/src/BuildVision.Contracts/Models/BuildProjectContextEntry.cs @@ -5,11 +5,7 @@ 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 Properties { get; } @@ -17,11 +13,9 @@ public class BuildProjectContextEntry public bool IsInvalid { get; set; } - public BuildProjectContextEntry(int instanceId, int contextId, string fileName, IDictionary properties) + public BuildProjectContextEntry(string fileName, IDictionary properties) { - InstanceId = instanceId; - ContextId = contextId; - FileName = fileName; + ProjectFile = fileName; Properties = properties; } } diff --git a/src/BuildVision.Contracts/Models/IBuildInformationModel.cs b/src/BuildVision.Contracts/Models/IBuildInformationModel.cs index f524b06d..4e35f442 100644 --- a/src/BuildVision.Contracts/Models/IBuildInformationModel.cs +++ b/src/BuildVision.Contracts/Models/IBuildInformationModel.cs @@ -26,6 +26,7 @@ public interface IBuildInformationModel : INotifyPropertyChanged string StateIconKey { get; } IProjectItem CurrentProject { get; set; } + int GetFinishedProjectsCount(); void ResetState(); } } diff --git a/src/BuildVision.Exports/Providers/IBuildInformationProvider.cs b/src/BuildVision.Exports/Providers/IBuildInformationProvider.cs index f010b82a..ed69e19c 100644 --- a/src/BuildVision.Exports/Providers/IBuildInformationProvider.cs +++ b/src/BuildVision.Exports/Providers/IBuildInformationProvider.cs @@ -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; } } diff --git a/src/BuildVision.UI/Helpers/BuildMessagesFactory.cs b/src/BuildVision.UI/Helpers/BuildMessagesFactory.cs index 36af09c4..f7b3da21 100644 --- a/src/BuildVision.UI/Helpers/BuildMessagesFactory.cs +++ b/src/BuildVision.UI/Helpers/BuildMessagesFactory.cs @@ -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}"); } } diff --git a/src/BuildVision.UI/Models/BuildInformationModel.cs b/src/BuildVision.UI/Models/BuildInformationModel.cs index c0039dca..a6620f2b 100644 --- a/src/BuildVision.UI/Models/BuildInformationModel.cs +++ b/src/BuildVision.UI/Models/BuildInformationModel.cs @@ -258,6 +258,8 @@ private BuildResultState GetBuildResultState() } } + public int GetFinishedProjectsCount() => SucceededProjectsCount + UpToDateProjectsCount + WarnedProjectsCount + FailedProjectsCount; + public void ResetState() { ErrorCount = 0; diff --git a/src/BuildVision.UI/ViewModels/BuildVisionPaneViewModel.cs b/src/BuildVision.UI/ViewModels/BuildVisionPaneViewModel.cs index 61c0f4ec..fa237bfb 100644 --- a/src/BuildVision.UI/ViewModels/BuildVisionPaneViewModel.cs +++ b/src/BuildVision.UI/ViewModels/BuildVisionPaneViewModel.cs @@ -214,7 +214,9 @@ public BuildVisionPaneViewModel( SolutionModel = solutionProvider.GetSolutionModel(); ControlSettings = settingsProvider.Settings; Projects = _buildInformationProvider.Projects; - + + _buildInformationProvider.BuildStateChanged += () => OnPropertyChanged(nameof(GroupedProjectsList)); + _settingsProvider = settingsProvider; _settingsProvider.SettingsChanged += () => { diff --git a/src/BuildVision/Core/BuildVisionPackage.cs b/src/BuildVision/Core/BuildVisionPackage.cs index 8fe625e8..966c43c3 100644 --- a/src/BuildVision/Core/BuildVisionPackage.cs +++ b/src/BuildVision/Core/BuildVisionPackage.cs @@ -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()); _solutionBuildManager.AdviseUpdateSolutionEvents(_solutionBuildEvents, out _updateSolutionEventsCookie); _solutionBuildManager4.AdviseUpdateSolutionEvents4(_solutionBuildEvents, out _updateSolutionEvents4Cookie); } diff --git a/src/BuildVision/Core/SolutionBuildEvents.cs b/src/BuildVision/Core/SolutionBuildEvents.cs index 4963338a..386c13b7 100644 --- a/src/BuildVision/Core/SolutionBuildEvents.cs +++ b/src/BuildVision/Core/SolutionBuildEvents.cs @@ -6,6 +6,7 @@ using EnvDTE; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell.Interop; +using Serilog; namespace BuildVision.Core { @@ -13,54 +14,97 @@ public class SolutionBuildEvents : IVsUpdateSolutionEvents2, IVsUpdateSolutionEv { 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 diff --git a/src/BuildVision/Helpers/ProjectExtensions.cs b/src/BuildVision/Helpers/ProjectExtensions.cs index a3d73037..f01b4816 100644 --- a/src/BuildVision/Helpers/ProjectExtensions.cs +++ b/src/BuildVision/Helpers/ProjectExtensions.cs @@ -27,10 +27,11 @@ public static class ProjectExtensions private static readonly Dictionary _knownProjectTypes = new Dictionary { - {"{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"}, diff --git a/src/BuildVision/Helpers/SolutionProjectsExtensions.cs b/src/BuildVision/Helpers/SolutionProjectsExtensions.cs index f7ddcd5c..61f8c328 100644 --- a/src/BuildVision/Helpers/SolutionProjectsExtensions.cs +++ b/src/BuildVision/Helpers/SolutionProjectsExtensions.cs @@ -106,6 +106,11 @@ public static IList 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()); @@ -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) { @@ -178,6 +183,14 @@ public static void UpdateProperties(Project project, ProjectItem projectItem, st } else { + if (project.ConfigurationManager == null) + { + LogManager.ForContext().Warning("ConfigurationManager for project {UniqueName} was null.", project?.UniqueName); + } + else if (project.ConfigurationManager.ActiveConfiguration == null) + { + LogManager.ForContext().Warning("ActiveConfiguration for project {UniqueName} was null.", project?.UniqueName); + } projectItem.Configuration = @"N\A"; projectItem.Platform = @"N\A"; } @@ -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) diff --git a/src/BuildVision/Services/BuildInformationProvider.cs b/src/BuildVision/Services/BuildInformationProvider.cs index c52d9ccb..f1fe75b6 100644 --- a/src/BuildVision/Services/BuildInformationProvider.cs +++ b/src/BuildVision/Services/BuildInformationProvider.cs @@ -2,10 +2,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel.Composition; -using System.Diagnostics; using System.Linq; using System.Threading; -using System.Threading.Tasks; using BuildVision.Common; using BuildVision.Common.Diagnostics; using BuildVision.Common.Logging; @@ -88,10 +86,14 @@ private void BuildOutputLogger_OnErrorRaised(BuildProjectContextEntry projectEnt { try { - if (!TryGetProjectItem(projectEntry, out var projectItem)) + var projectItem = projectEntry.ProjectItem; + if (projectItem == null) { - projectEntry.IsInvalid = true; - return; + if (!TryGetProjectItem(projectEntry, out projectItem)) + { + projectEntry.IsInvalid = true; + return; + } } var errorItem = new ErrorItem(errorLevel); @@ -135,29 +137,36 @@ private void BuildOutputLogger_OnErrorRaised(BuildProjectContextEntry projectEnt private bool TryGetProjectItem(BuildProjectContextEntry projectEntry, out IProjectItem projectItem) { - projectItem = projectEntry.ProjectItem; + projectItem = projectEntry?.ProjectItem; if (projectItem != null) { return true; } - string projectFile = projectEntry.FileName; + string projectFile = projectEntry.ProjectFile; if (ProjectExtensions.IsProjectHidden(projectFile)) { return false; } var projectProperties = projectEntry.Properties; - var project = Projects.FirstOrDefault(x => x.FullName == projectFile); - if (projectProperties.ContainsKey("Configuration") && projectProperties.ContainsKey("Platform")) { string projectConfiguration = projectProperties["Configuration"]; string projectPlatform = projectProperties["Platform"]; - projectItem = Projects.First(item => $"{item.FullName}-{item.Configuration}|{item.Platform.Replace(" ", "")}" == $"{projectFile}-{projectConfiguration}|{projectPlatform}"); + _logger.Information("Lookup ProjectItem for ProjectFile='{ProjectFile}', Configuration='{ProjectConfiguration}, Platform='{ProjectPlatform}'.", projectFile, projectConfiguration, projectPlatform); + projectItem = Projects.FirstOrDefault(item => $"{item.FullName}-{item.Configuration}|{item.Platform.Replace(" ", "")}" == $"{projectFile}-{projectConfiguration}|{projectPlatform}"); if (projectItem == null) { - _logger.Warning("Project Item not found by: UniqueName='{UniqueName}', Configuration='{ProjectConfiguration}, Platform='{ProjectPlatform}'.", project.UniqueName, projectConfiguration, projectPlatform); + var project = Projects.FirstOrDefault(x => x.FullName == projectFile); + if (project == null) + { + _logger.Error("Project Item and Project were not found by: ProjectFile='{ProjectFile}', Configuration='{ProjectConfiguration}, Platform='{ProjectPlatform}'.", projectFile, projectConfiguration, projectPlatform); + } + else + { + _logger.Warning("Project Item not found by: UniqueName='{UniqueName}', Configuration='{ProjectConfiguration}, Platform='{ProjectPlatform}'.", project.UniqueName, projectConfiguration, projectPlatform); + } return false; } } @@ -188,12 +197,13 @@ public void BuildStarted(BuildAction buildAction, BuildScope buildScope) _windowStateService.ApplyToolWindowStateAction(_packageSettingsProvider.Settings.WindowSettings.WindowActionOnBuildBegin); _timer = new Timer(state => BuildUpdate(), null, BuildInProcessQuantumSleep, BuildInProcessQuantumSleep); - + string message = _buildMessagesFactory.GetBuildBeginMajorMessage(BuildInformationModel); _statusBarNotificationService.ShowTextWithFreeze(message); _origTextCurrentState = message; BuildInformationModel.StateMessage = _origTextCurrentState; - _taskBarInfoService.UpdateTaskBarInfo(BuildInformationModel.CurrentBuildState, BuildInformationModel.BuildScope, Projects.Count, GetFinishedProjectsCount()); + UpdateTaskBar(); + BuildStateChanged(); DiagnosticsClient.TrackEvent("BuildStarted", new Dictionary { @@ -210,38 +220,28 @@ public void ProjectBuildStarted(IProjectItem projectItem, BuildAction buildActio return; } - try + var projInCollection = Projects.FirstOrDefault(item => ProjectIdentifierGenerator.GetIdentifierForProjectItem(item) == ProjectIdentifierGenerator.GetIdentifierForProjectItem(projectItem)); + if (projInCollection == null) { - var projInCollection = Projects.FirstOrDefault(item => ProjectIdentifierGenerator.GetIdentifierForProjectItem(item) == ProjectIdentifierGenerator.GetIdentifierForProjectItem(projectItem)); - if (projInCollection == null) - { - Projects.Add(projectItem); - projInCollection = projectItem; - } - projInCollection.State = BuildInformationModel.BuildAction.GetProjectState(); - projInCollection.BuildFinishTime = null; - projInCollection.BuildStartTime = DateTime.Now; + Projects.Add(projectItem); + projInCollection = projectItem; + } + projInCollection.State = BuildInformationModel.BuildAction.GetProjectState(); + projInCollection.BuildFinishTime = null; + projInCollection.BuildStartTime = DateTime.Now; - _taskBarInfoService.UpdateTaskBarInfo(BuildInformationModel.CurrentBuildState, BuildInformationModel.BuildScope, Projects.Count, GetFinishedProjectsCount()); - _currentQueuePosOfBuildingProject++; + UpdateTaskBar(); - if (BuildInformationModel.BuildScope == BuildScope.Solution && - (BuildInformationModel.BuildAction == BuildAction.Build || - BuildInformationModel.BuildAction == BuildAction.RebuildAll)) - { - projInCollection.BuildOrder = _currentQueuePosOfBuildingProject; - } - BuildInformationModel.CurrentProject = projInCollection; - } - catch (Exception ex) + _currentQueuePosOfBuildingProject++; + + if (BuildInformationModel.BuildScope == BuildScope.Solution && + (BuildInformationModel.BuildAction == BuildAction.Build || + BuildInformationModel.BuildAction == BuildAction.RebuildAll)) { - _logger.Error(ex, "Failed during Project Build start."); + projInCollection.BuildOrder = _currentQueuePosOfBuildingProject; } - } - - private int GetFinishedProjectsCount() - { - return BuildInformationModel.SucceededProjectsCount + BuildInformationModel.UpToDateProjectsCount + BuildInformationModel.WarnedProjectsCount + BuildInformationModel.FailedProjectsCount; + BuildInformationModel.CurrentProject = projInCollection; + BuildStateChanged(); } public void ProjectBuildFinished(BuildAction buildAction, string projectIdentifier, bool success, bool canceled) @@ -274,7 +274,8 @@ public void ProjectBuildFinished(BuildAction buildAction, string projectIdentifi BuildInformationModel.CurrentProject = Projects.Last(); } - _taskBarInfoService.UpdateTaskBarInfo(BuildInformationModel.CurrentBuildState, BuildInformationModel.BuildScope, Projects.Count, GetFinishedProjectsCount()); + UpdateTaskBar(); + BuildStateChanged(); } private ProjectState GetProjectState(bool success, bool canceled, IProjectItem currentProject) @@ -313,7 +314,7 @@ private ProjectState GetProjectState(bool success, bool canceled, IProjectItem c return projectState; } - public void BuildUpdate() + private void BuildUpdate() { if(BuildInformationModel.CurrentBuildState != BuildState.InProgress) { @@ -322,7 +323,7 @@ public void BuildUpdate() var message = _origTextCurrentState + _buildMessagesFactory.GetBuildBeginExtraMessage(BuildInformationModel); BuildInformationModel.StateMessage = message; _statusBarNotificationService.ShowTextWithFreeze(message); - foreach (var project in Projects.Where(x => x.BuildStartTime.HasValue && !x.BuildFinishTime.HasValue)) + foreach (var project in Projects.Where(x => x.State != ProjectState.Cleaning && x.State != ProjectState.Building)) { project.RaiseBuildElapsedTimeChanged(); } @@ -372,8 +373,8 @@ public void BuildFinished(bool success, bool canceled) var message = _buildMessagesFactory.GetBuildDoneMessage(BuildInformationModel); _statusBarNotificationService.ShowText(message); BuildInformationModel.StateMessage = message; - _taskBarInfoService.UpdateTaskBarInfo(BuildInformationModel.CurrentBuildState, BuildInformationModel.BuildScope, Projects.Count, GetFinishedProjectsCount()); - + UpdateTaskBar(); + BuildStateChanged(); if (BuildInformationModel.FailedProjectsCount > 0 || canceled) { _windowStateService.ApplyToolWindowStateAction(_packageSettingsProvider.Settings.WindowSettings.WindowActionOnBuildError); @@ -407,5 +408,13 @@ public void BuildFinished(bool success, bool canceled) } } } + + private void UpdateTaskBar() + { + _taskBarInfoService.UpdateTaskBarInfo(BuildInformationModel.CurrentBuildState, BuildInformationModel.BuildScope, Projects.Count, BuildInformationModel.GetFinishedProjectsCount()); + } + + + public event Action BuildStateChanged; } } diff --git a/src/BuildVision/Services/BuildOutputLogger.cs b/src/BuildVision/Services/BuildOutputLogger.cs index 5cd7db13..edd80bd9 100644 --- a/src/BuildVision/Services/BuildOutputLogger.cs +++ b/src/BuildVision/Services/BuildOutputLogger.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Reflection; using BuildVision.Common.Logging; @@ -20,7 +19,7 @@ public class BuildOutputLogger : Logger, IBuildOutputLogger private Serilog.ILogger _logger = LogManager.ForContext(); public RegisterLoggerResult LoggerState { get; set; } - private Dictionary _projects = new Dictionary(); + private Dictionary _projectsLookup = new Dictionary(); public BuildOutputLogger(Guid loggerId, LoggerVerbosity loggerVerbosity) { @@ -30,28 +29,29 @@ public BuildOutputLogger(Guid loggerId, LoggerVerbosity loggerVerbosity) public override void Initialize(IEventSource eventSource) { - _projects = new Dictionary(); + _projectsLookup = new Dictionary(); eventSource.ProjectStarted += OnProjectStarted; - eventSource.MessageRaised += (s, e) => EventSource_ErrorRaised(e, ErrorLevel.Message); - eventSource.WarningRaised += (s, e) => EventSource_ErrorRaised(e, ErrorLevel.Warning); - eventSource.ErrorRaised += (s, e) => EventSource_ErrorRaised(e, ErrorLevel.Error); + eventSource.MessageRaised += (sender, e) => EventSource_Event(e.ProjectFile, e, ErrorLevel.Message); + eventSource.WarningRaised += (sender, e) => EventSource_Event(e.ProjectFile, e, ErrorLevel.Warning); + eventSource.ErrorRaised += (sender, e) => EventSource_Event(e.ProjectFile, e, ErrorLevel.Error); } private void OnProjectStarted(object sender, ProjectStartedEventArgs e) { - var identifier = $"{e.BuildEventContext.ProjectInstanceId}{e.BuildEventContext.ProjectContextId}"; - _projects.Add(identifier, new BuildProjectContextEntry( - e.BuildEventContext.ProjectInstanceId, - e.BuildEventContext.ProjectContextId, - e.ProjectFile, - e.GlobalProperties)); + var entry = new BuildProjectContextEntry(e.ProjectFile, e.GlobalProperties); + if (!_projectsLookup.ContainsKey(entry.ProjectFile)) + { + _projectsLookup.Add(entry.ProjectFile, entry); + } + + _logger.Information("Currently there are {Count} projects listed.", _projectsLookup.Count); } public void Attach() { try { - _projects.Clear(); + _projectsLookup.Clear(); const BindingFlags InterfacePropertyFlags = BindingFlags.GetProperty | BindingFlags.Public @@ -76,6 +76,9 @@ public void Attach() var loggersProperty = loggingServiceObj.GetType().GetProperty("Loggers", InterfacePropertyFlags); var loggers = (ICollection)loggersProperty.GetValue(loggingServiceObj, null); + + + var logger = loggers.FirstOrDefault(x => x is BuildOutputLogger && ((BuildOutputLogger)x)._loggerId.Equals(_loggerId)); if (logger != null) { @@ -83,6 +86,7 @@ public void Attach() return; } + var registerLoggerMethod = loggingServiceObj.GetType().GetMethod("RegisterLogger"); var registerResult = (bool)registerLoggerMethod.Invoke(loggingServiceObj, new object[] { this }); LoggerState = registerResult ? RegisterLoggerResult.RegisterSuccess : RegisterLoggerResult.RegisterFailed; @@ -94,12 +98,9 @@ public void Attach() } } - public bool IsProjectUpToDate(IProjectItem projectItem) - { - return !_projects.Any(x => x.Value.FileName == projectItem.FullName); - } + public bool IsProjectUpToDate(IProjectItem projectItem) => !_projectsLookup.ContainsKey(projectItem.FullName); - private void EventSource_ErrorRaised(BuildEventArgs e, ErrorLevel errorLevel) + private void EventSource_Event(string projectFile, BuildEventArgs e, ErrorLevel errorLevel) { try { @@ -107,13 +108,14 @@ private void EventSource_ErrorRaised(BuildEventArgs e, ErrorLevel errorLevel) { return; } + if(projectFile == null) + { + return; + } - int projectInstanceId = e.BuildEventContext.ProjectInstanceId; - int projectContextId = e.BuildEventContext.ProjectContextId; - var identifier = $"{projectInstanceId}{projectContextId}"; - if (!_projects.TryGetValue(identifier, out var projectEntry)) + if (!_projectsLookup.TryGetValue(projectFile, out var projectEntry)) { - _logger.Warning("Project entry not found by ProjectInstanceId='{ProjectInstanceId}' and ProjectContextId='{ProjectContextId}'.", projectInstanceId, projectContextId); + _logger.Warning("Project entry not found by ProjectFile='{ProjectFile}'.", projectFile); return; } if (projectEntry.IsInvalid)