Skip to content

Commit

Permalink
Fixed cancel build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Apr 6, 2019
1 parent 86897c2 commit 9e7f92d
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 86 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
40 changes: 0 additions & 40 deletions src/BuildVision/Core/BuildVisionPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public sealed class BuildVisionPackage : AsyncPackage, IVsPackageDynamicToolOwne
private uint _updateSolutionEvents4Cookie;
private SolutionBuildEvents _solutionBuildEvents;
private ISolutionProvider _solutionProvider;
private Window _activeProjectContext;
private ServiceProvider _serviceProvider;

public static ToolWindowPane ToolWindowPane { get; set; }
Expand Down Expand Up @@ -108,9 +107,6 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
_commandEvents = _dte.Events.CommandEvents;
_commandEvents.AfterExecute += CommandEvents_AfterExecute;

_windowEvents = _dte.Events.WindowEvents;
_windowEvents.WindowActivated += WindowEvents_WindowActivated;

_solutionEvents = _dte.Events.SolutionEvents;
_solutionEvents.AfterClosing += SolutionEvents_AfterClosing;
_solutionEvents.Opened += SolutionEvents_Opened;
Expand All @@ -119,8 +115,6 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
{
SolutionEvents_Opened();
}

//InitToolWindow(this);
}

private void SolutionEvents_Opened()
Expand Down Expand Up @@ -148,29 +142,6 @@ private void SolutionEvents_AfterClosing()
_solutionBuildManager4.UnadviseUpdateSolutionEvents4(_updateSolutionEvents4Cookie);
}

private void WindowEvents_WindowActivated(Window gotFocus, Window lostFocus)
{
if (gotFocus == null)
return;

switch (gotFocus.Type)
{
case vsWindowType.vsWindowTypeSolutionExplorer:
_activeProjectContext = gotFocus;
break;

case vsWindowType.vsWindowTypeDocument:
case vsWindowType.vsWindowTypeDesigner:
case vsWindowType.vsWindowTypeCodeWindow:
if (gotFocus.Project != null && !gotFocus.Project.IsHidden())
_activeProjectContext = gotFocus;
break;

default:
return;
}
}

private void CommandEvents_AfterExecute(string guid, int id, object customIn, object customOut)
{
if (id == (int)VSConstants.VSStd97CmdID.CancelBuild
Expand All @@ -188,16 +159,5 @@ public int QueryShowTool(ref Guid rguidPersistenceSlot, uint dwId, out int pfSho
pfShowTool = 1;
return 0;
}

//public static void InitToolWindow(AsyncPackage package)
//{
// package.JoinableTaskFactory.RunAsync(async () =>
// {
// var window = package.FindToolWindow(typeof(BuildVisionPane), 0, false) ?? package.FindToolWindow(typeof(BuildVisionPane), 0, true);
// var windowStateService = await package.GetServiceAsync(typeof(IWindowStateService)) as IWindowStateService;
// Assumes.Present(windowStateService);
// windowStateService.Initialize(window);
// });
//}
}
}
4 changes: 3 additions & 1 deletion src/BuildVision/Core/BuildVisionPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using System.Windows.Controls;
using BuildVision.UI.Settings.Models;
using BuildVision.UI.Settings.Models.Columns;
using System.Windows.Markup;
using System.Globalization;

namespace BuildVision.Tool
{
Expand Down Expand Up @@ -51,7 +53,7 @@ public BuildVisionPane()
BitmapIndex = 1;

Content = _contentPresenter = new ContentPresenter();
//FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}

protected override void Initialize()
Expand Down
5 changes: 1 addition & 4 deletions src/BuildVision/Core/ServiceProviderPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using BuildVision.Contracts.Models;
using BuildVision.Exports;
using BuildVision.Exports.Factories;
using BuildVision.Exports.Providers;
using BuildVision.Exports.Services;
using BuildVision.Services;
using BuildVision.Tool;
using BuildVision.Tool.Building;
using BuildVision.UI.Helpers;
using BuildVision.UI.Settings.Models;
using BuildVision.UI.ViewModels;
using BuildVision.Views.Settings;
using Microsoft;
Expand Down Expand Up @@ -114,7 +111,7 @@ async Task<object> CreateServiceAsync(IAsyncServiceContainer container, Cancella
}
}

private async Task<T> GetServiceAsync<T>(CancellationToken cancellation) where T: class
private async Task<T> GetServiceAsync<T>(CancellationToken cancellation) where T : class

This comment has been minimized.

Copy link
@yannduran

yannduran Apr 27, 2019

Why are you switching to the main thread to await GetServiceAsync?

{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellation);
var service = await GetServiceAsync(typeof(T)) as T;
Expand Down
13 changes: 1 addition & 12 deletions src/BuildVision/Core/SolutionBuildEvents.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BuildVision.Common;
using BuildVision.Contracts;
using BuildVision.Exports.Providers;
using BuildVision.Helpers;
using BuildVision.Services;
using BuildVision.Tool.Building;
using BuildVision.Tool.Models;
using BuildVision.UI.Common.Logging;
using BuildVision.UI.Contracts;
using BuildVision.UI.Helpers;
using BuildVision.UI.ViewModels;
using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
Expand All @@ -29,7 +18,7 @@ public class SolutionBuildEvents : IVsUpdateSolutionEvents2, IVsUpdateSolutionEv
private BuildActions _currentBuildAction;

public SolutionBuildEvents(
ISolutionProvider solutionProvider,
ISolutionProvider solutionProvider,
IBuildInformationProvider buildInformationProvider,
IServiceProvider serviceProvider)
{
Expand Down
1 change: 0 additions & 1 deletion src/BuildVision/Services/BuildInformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using BuildVision.Helpers;
using BuildVision.Services;
using BuildVision.Tool.Building;
using BuildVision.UI;
using BuildVision.UI.Common.Logging;
using BuildVision.UI.Contracts;
using BuildVision.UI.Models;
Expand Down
22 changes: 10 additions & 12 deletions src/BuildVision/Services/BuildOutputLogger.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using BuildVision.Contracts;
using BuildVision.UI.Contracts;
using BuildVision.UI.Common.Logging;
using BuildVision.Exports;
using BuildVision.Helpers;
using System.Diagnostics;
using BuildVision.Core;
using BuildVision.Exports.Providers;
using BuildVision.UI.Common.Logging;
using BuildVision.UI.Contracts;
using BuildVision.UI.Models;
using BuildVision.Exports;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace BuildVision.Tool.Building
{
Expand Down Expand Up @@ -75,17 +73,17 @@ public void Attach()
}

var loggersProperty = loggingServiceObj.GetType().GetProperty("Loggers", InterfacePropertyFlags);
var loggers = (ICollection<ILogger>) loggersProperty.GetValue(loggingServiceObj, null);
var loggers = (ICollection<ILogger>)loggersProperty.GetValue(loggingServiceObj, null);

var logger = loggers.FirstOrDefault(x => x is BuildOutputLogger && ((BuildOutputLogger) x)._loggerId.Equals(_loggerId));
var logger = loggers.FirstOrDefault(x => x is BuildOutputLogger && ((BuildOutputLogger)x)._loggerId.Equals(_loggerId));
if (logger != null)
{
LoggerState = RegisterLoggerResult.AlreadyExists;
return;
}

var registerLoggerMethod = loggingServiceObj.GetType().GetMethod("RegisterLogger");
var registerResult = (bool) registerLoggerMethod.Invoke(loggingServiceObj, new object[] { this });
var registerResult = (bool)registerLoggerMethod.Invoke(loggingServiceObj, new object[] { this });
LoggerState = registerResult ? RegisterLoggerResult.RegisterSuccess : RegisterLoggerResult.RegisterFailed;
}
catch (Exception ex)
Expand Down Expand Up @@ -135,7 +133,7 @@ private bool VerifyLoggerBuildEvent(BuildEventArgs eventArgs, ErrorLevel errorLe

if (errorLevel == ErrorLevel.Message)
{
var messageEventArgs = (BuildMessageEventArgs) eventArgs;
var messageEventArgs = (BuildMessageEventArgs)eventArgs;
if (!messageEventArgs.IsUserMessage(this))
return false;
}
Expand Down
13 changes: 4 additions & 9 deletions src/BuildVision/Services/BuildService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using BuildVision.Common;
using BuildVision.Contracts;
using BuildVision.Contracts.Models;
using BuildVision.Core;
using BuildVision.Exports.Services;
using BuildVision.Helpers;
using BuildVision.UI;
using BuildVision.UI.Common.Logging;
using BuildVision.UI.Models;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;

Expand All @@ -29,8 +24,8 @@ public class BuildService : IBuildService
{
private const string CancelBuildCommand = "Build.Cancel";
private bool _buildCancelledInternally;
private bool _buildCancelled;
private IServiceProvider _serviceProvider;
private readonly bool _buildCancelled;
private readonly IServiceProvider _serviceProvider;

[ImportingConstructor]
public BuildService(
Expand Down Expand Up @@ -87,7 +82,7 @@ public void RaiseCommandForSelectedProject(IProjectItem selectedProjectItem, int
try
{
SelectProjectInSolutionExplorer(selectedProjectItem);
RaiseCommand((VSConstants.VSStd97CmdID) commandId);
RaiseCommand((VSConstants.VSStd97CmdID)commandId);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -198,7 +193,7 @@ private void RaiseCommand(VSConstants.VSStd97CmdID command)
object customIn = null;
object customOut = null;
var dte = _serviceProvider.GetService(typeof(DTE)) as DTE;
dte.Commands.Raise(VSConstants.GUID_VSStandardCommandSet97.ToString(), (int) command, ref customIn, ref customOut);
dte.Commands.Raise(VSConstants.GUID_VSStandardCommandSet97.ToString(), (int)command, ref customIn, ref customOut);
}
catch (Exception ex)
{
Expand Down
1 change: 0 additions & 1 deletion src/BuildVision/Services/ErrorNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.ComponentModel.Composition;
using System.IO;
using BuildVision.Contracts;
using BuildVision.Exports.Providers;
using BuildVision.Exports.Services;
using BuildVision.Helpers;
using BuildVision.UI.Common.Logging;
Expand Down
4 changes: 1 addition & 3 deletions src/BuildVision/Services/PackageSettingsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using BuildVision.Common;
using BuildVision.UI.Common.Logging;
using BuildVision.UI.Settings.Models;
using Microsoft.VisualStudio.Settings;
using Microsoft.VisualStudio.Shell.Settings;
using BuildVision.UI.Common.Logging;
using BuildVision.Core;

namespace BuildVision.Views.Settings
{
Expand Down
5 changes: 2 additions & 3 deletions src/BuildVision/Services/SolutionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace BuildVision.Core
{
Expand Down Expand Up @@ -40,15 +39,15 @@ public void ReloadSolution()

RefrehSolutionModel();
}

public ISolutionModel GetSolutionModel()
{
return _solutionModel;
}

private void RefrehSolutionModel()
{
if(_solutionModel == null)
if (_solutionModel == null)
_solutionModel = new SolutionModel();

try
Expand Down

0 comments on commit 9e7f92d

Please sign in to comment.