Skip to content

Commit

Permalink
Additional cleanups and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Mar 23, 2019
1 parent 6d18526 commit 46a8a8d
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 176 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using BuildVision.Contracts.Models;
using BuildVision.UI.Models;

namespace BuildVision.Exports.Providers
{
public interface IBuildInformationProvider
{
void BuildFinished(bool success, bool canceled);
void BuildFinished(IEnumerable<IProjectItem> projects, bool success, bool canceled);
void BuildStarted(uint dwAction);
void BuildUpdate();
void ResetBuildInformationModel();
Expand Down
41 changes: 21 additions & 20 deletions src/BuildVision.UI/Helpers/BuildMessagesFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
using BuildVision.Exports.Providers;
using BuildVision.Contracts.Models;
using BuildVision.Exports.Factories;
using BuildVision.Views.Settings;

namespace BuildVision.UI.Helpers
{
public class BuildMessagesFactory : IBuildMessagesFactory
{
private readonly BuildMessagesSettings _buildMessageSettings;
private readonly IPackageSettingsProvider _packageSettingsProvider;

public BuildMessagesFactory(BuildMessagesSettings buildMessageSettings)
public BuildMessagesFactory(IPackageSettingsProvider packageSettingsProvider)
{
_buildMessageSettings = buildMessageSettings;
_packageSettingsProvider = packageSettingsProvider;
}

public string GetBuildBeginMajorMessage(IBuildInformationModel buildInformationModel)
{
var mainString = GetMainString(buildInformationModel);
return string.Format(_buildMessageSettings.BuildBeginMajorMessageStringFormat, mainString);
return string.Format(_packageSettingsProvider.Settings.BuildMessagesSettings.BuildBeginMajorMessageStringFormat, mainString);
}

private string GetMainString(IBuildInformationModel buildInformationModel)
Expand All @@ -32,7 +33,7 @@ private string GetMainString(IBuildInformationModel buildInformationModel)
var beginAtString = GetBeginAtString(buildInformationModel.BuildAction);
var timeString = GetTimeString(buildInformationModel.BuildStartTime);
string mainString;
switch (_buildMessageSettings.MajorMessageFormat)
switch (_packageSettingsProvider.Settings.BuildMessagesSettings.MajorMessageFormat)
{
case BuildMajorMessageFormat.Entire:
mainString = string.Format(Resources.BuildBeginStateLabelTemplate_Default, actionName, unitName, beginAtString, timeString);
Expand All @@ -43,7 +44,7 @@ private string GetMainString(IBuildInformationModel buildInformationModel)
break;

default:
throw new ArgumentOutOfRangeException(nameof(_buildMessageSettings.MajorMessageFormat));
throw new ArgumentOutOfRangeException(nameof(_packageSettingsProvider.Settings.BuildMessagesSettings.MajorMessageFormat));
}

return mainString;
Expand All @@ -54,7 +55,7 @@ private string GetTimeString(DateTime? startTime)
string timeString = "";
try
{
timeString = startTime.Value.ToString(_buildMessageSettings.DateTimeFormat);
timeString = startTime.Value.ToString(_packageSettingsProvider.Settings.BuildMessagesSettings.DateTimeFormat);
}
catch (FormatException)
{
Expand Down Expand Up @@ -127,13 +128,13 @@ private string GetUnitName(BuildScopes buildScope)

public string GetBuildBeginExtraMessage(IBuildInformationModel buildInformationModel)
{
if (buildInformationModel.BuildStartTime == null || !_buildMessageSettings.ShowExtraMessage || _buildMessageSettings.ExtraMessageDelay < 0)
if (buildInformationModel.BuildStartTime == null || !_packageSettingsProvider.Settings.BuildMessagesSettings.ShowExtraMessage || _packageSettingsProvider.Settings.BuildMessagesSettings.ExtraMessageDelay < 0)
{
return string.Empty;
}

TimeSpan timeSpan = DateTime.Now.Subtract(buildInformationModel.BuildStartTime.Value);
if (timeSpan.TotalSeconds > _buildMessageSettings.ExtraMessageDelay)
if (timeSpan.TotalSeconds > _packageSettingsProvider.Settings.BuildMessagesSettings.ExtraMessageDelay)
{
return GetExtraTimePartString( timeSpan);
}
Expand All @@ -157,7 +158,7 @@ private string GetBuildDoneMajorMessage(IBuildInformationModel buildInformationM
string timeString;
try
{
timeString = buildInformationModel.BuildFinishTime.Value.ToString(_buildMessageSettings.DateTimeFormat);
timeString = buildInformationModel.BuildFinishTime.Value.ToString(_packageSettingsProvider.Settings.BuildMessagesSettings.DateTimeFormat);
}
catch (FormatException)
{
Expand All @@ -179,7 +180,7 @@ private string GetBuildDoneMajorMessage(IBuildInformationModel buildInformationM

case BuildScopes.BuildScopeProject:
unitName = Resources.BuildScopeProject_UnitName;
if (_buildMessageSettings.ShowProjectName)
if (_packageSettingsProvider.Settings.BuildMessagesSettings.ShowProjectName)
{
// Todo this is probably wrong. maybe we should go the extra mile and check which projects are selected?
//var uniqProjName = solutionItem.Projects.LastOrDefault(x => x.State == ProjectState.BuildDone)?.UniqueName;
Expand All @@ -196,7 +197,7 @@ private string GetBuildDoneMajorMessage(IBuildInformationModel buildInformationM
var resultName = GetResultName(buildInformationModel.ResultState);

string mainString;
switch (_buildMessageSettings.MajorMessageFormat)
switch (_packageSettingsProvider.Settings.BuildMessagesSettings.MajorMessageFormat)
{
case BuildMajorMessageFormat.Entire:
mainString = string.Format(Resources.BuildDoneStateLabelTemplate_Default, actionName, unitName, resultName, timeString);
Expand All @@ -207,10 +208,10 @@ private string GetBuildDoneMajorMessage(IBuildInformationModel buildInformationM
break;

default:
throw new ArgumentOutOfRangeException(nameof(_buildMessageSettings.MajorMessageFormat));
throw new ArgumentOutOfRangeException(nameof(_packageSettingsProvider.Settings.BuildMessagesSettings.MajorMessageFormat));
}

string resultMainString = string.Format(_buildMessageSettings.BuildDoneMajorMessageStringFormat, mainString);
string resultMainString = string.Format(_packageSettingsProvider.Settings.BuildMessagesSettings.BuildDoneMajorMessageStringFormat, mainString);
return resultMainString;
}

Expand Down Expand Up @@ -242,23 +243,23 @@ private string GetResultName(BuildResultState resultState)

private string GetBuildDoneExtraMessage(IBuildInformationModel buildInformationModel)
{
if (buildInformationModel.BuildStartTime == null || buildInformationModel.BuildFinishTime == null || !_buildMessageSettings.ShowExtraMessage)
if (buildInformationModel.BuildStartTime == null || buildInformationModel.BuildFinishTime == null || !_packageSettingsProvider.Settings.BuildMessagesSettings.ShowExtraMessage)
return string.Empty;

TimeSpan timeSpan = buildInformationModel.BuildFinishTime.Value.Subtract(buildInformationModel.BuildStartTime.Value);
string extraTimePartString = GetExtraTimePartString(timeSpan);
return string.Format(_buildMessageSettings.ExtraMessageStringFormat, extraTimePartString);
return string.Format(_packageSettingsProvider.Settings.BuildMessagesSettings.ExtraMessageStringFormat, extraTimePartString);
}

private string GetExtraTimePartString(TimeSpan timeSpan)
{
string extraTimePartString;
switch (_buildMessageSettings.ExtraMessageFormat)
switch (_packageSettingsProvider.Settings.BuildMessagesSettings.ExtraMessageFormat)
{
case BuildExtraMessageFormat.Custom:
try
{
extraTimePartString = timeSpan.ToString(_buildMessageSettings.TimeSpanFormat);
extraTimePartString = timeSpan.ToString(_packageSettingsProvider.Settings.BuildMessagesSettings.TimeSpanFormat);
}
catch (FormatException)
{
Expand All @@ -279,10 +280,10 @@ private string GetExtraTimePartString(TimeSpan timeSpan)
break;

default:
throw new ArgumentOutOfRangeException(nameof(_buildMessageSettings.ExtraMessageFormat));
throw new ArgumentOutOfRangeException(nameof(_packageSettingsProvider.Settings.BuildMessagesSettings.ExtraMessageFormat));
}

return string.Format(_buildMessageSettings.ExtraMessageStringFormat, extraTimePartString);
return string.Format(_packageSettingsProvider.Settings.BuildMessagesSettings.ExtraMessageStringFormat, extraTimePartString);
}
}
}
7 changes: 7 additions & 0 deletions src/BuildVision.UI/Models/BuildInformationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public bool IsFinished
get => CurrentBuildState > BuildState.InProgress;
}

private IProjectItem _currentProject = null;
public IProjectItem CurrentProject
{
get => _currentProject;
set => SetProperty(ref _currentProject, value);
}

private string GetStateIconKey()
{
var resultState = GetBuildResultState();
Expand Down
2 changes: 0 additions & 2 deletions src/BuildVision/BuildVision.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@
<Compile Include="Services\BuildProgressViewModel.cs" />
<Compile Include="Services\ErrorNavigationService.cs" />
<Compile Include="Services\IErrorNavigationService.cs" />
<Compile Include="Services\IProjectFileNavigationService.cs" />
<Compile Include="Services\IWindowStateService.cs" />
<Compile Include="Services\ProjectFileNavigationService.cs" />
<Compile Include="Services\SolutionProvider.cs" />
<Compile Include="Helpers\ProjectIdentifierGenerator.cs" />
<Compile Include="Core\BuildVisionPackage.cs" />
Expand Down
15 changes: 13 additions & 2 deletions src/BuildVision/Core/BuildVisionPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows;
using System.Windows.Threading;
using BuildVision.Exports.Providers;
using BuildVision.Helpers;
using BuildVision.Services;
using BuildVision.Tool;
using BuildVision.UI;
using BuildVision.UI.Common.Logging;
using BuildVision.UI.Settings.Models;
using BuildVision.Views.Settings;
using EnvDTE;
using EnvDTE80;
using Microsoft;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
Expand Down Expand Up @@ -48,6 +51,7 @@ public sealed partial class BuildVisionPackage : AsyncPackage, IPackageContext
private ISolutionProvider _solutionProvider;
private IBuildingProjectsProvider _buildingProjectsProvider;
private Window _activeProjectContext;
private IErrorNavigationService _errorNavigationService;

public ControlSettings ControlSettings { get; set; }

Expand All @@ -62,7 +66,7 @@ public BuildVisionPackage()
}
}

private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
private void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show($"Diagnostics mode caught and marked as handled the following DispatcherUnhandledException raised in Visual Studio: {e.Exception}.");
e.Handled = true;
Expand All @@ -72,6 +76,8 @@ private void Current_DispatcherUnhandledException(object sender, System.Windows.

protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress);

await JoinableTaskFactory.SwitchToMainThreadAsync(DisposalToken);
_dte = await GetServiceAsync(typeof(DTE)) as DTE;
_dte2 = await GetServiceAsync(typeof(DTE)) as DTE2;
Expand All @@ -82,15 +88,20 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
mcs.AddCommand(menuToolWin);
}
_solutionBuildManager = await GetServiceAsync(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
Assumes.Present(_solutionBuildManager);
_solutionBuildManager4 = await GetServiceAsync(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager5;
Assumes.Present(_solutionBuildManager4);
_buildInformationProvider = await GetServiceAsync(typeof(IBuildInformationProvider)) as IBuildInformationProvider;
Assumes.Present(_buildInformationProvider);
_solutionProvider = await GetServiceAsync(typeof(ISolutionProvider)) as ISolutionProvider;
Assumes.Present(_solutionProvider);
_buildingProjectsProvider = await GetServiceAsync(typeof(IBuildingProjectsProvider)) as IBuildingProjectsProvider;
Assumes.Present(_buildingProjectsProvider);

IPackageContext packageContext = this;

_commandEvents = _dte.Events.CommandEvents;
_commandEvents.AfterExecute += CommandEvents_AfterExecute;
// _commandEvents.AfterExecute += CommandEvents_AfterExecute;

_windowEvents = _dte.Events.WindowEvents;
_windowEvents.WindowActivated += WindowEvents_WindowActivated;
Expand Down
Loading

0 comments on commit 46a8a8d

Please sign in to comment.