From 610f82311da4593f3d44c5eced8543d009eda8fc Mon Sep 17 00:00:00 2001 From: "Samir L. Boulema" Date: Wed, 16 Dec 2015 16:04:33 +0100 Subject: [PATCH 1/2] Add option to only notify on failed tests --- .gitignore | 1 + VsDingExtension.sln | 4 +++- .../VsDingExtensionFor2012.csproj | 5 ++++- VsDingExtensionProject/OptionsDialog.cs | 10 +++++++-- VsDingExtensionProject/Resources.Designer.cs | 2 +- .../VsDingExtensionProject.csproj | 10 ++++++++- .../VsDingExtensionProjectPackage.cs | 22 ++++++++++++++----- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 3cbf0fa..cc9aa5c 100644 --- a/.gitignore +++ b/.gitignore @@ -155,3 +155,4 @@ $RECYCLE.BIN/ # Mac desktop service store files .DS_Store /VsDingExtensionProject/pingme.txt +/VsDingExtensionProject/*.csdat diff --git a/VsDingExtension.sln b/VsDingExtension.sln index 930e6ee..7100bf6 100644 --- a/VsDingExtension.sln +++ b/VsDingExtension.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5BD9D4DB-8683-4698-8D24-01EE7306F73A}" ProjectSection(SolutionItems) = preProject IntegrationTests.testsettings = IntegrationTests.testsettings diff --git a/VsDingExtensionFor2012/VsDingExtensionFor2012.csproj b/VsDingExtensionFor2012/VsDingExtensionFor2012.csproj index 576c0c6..e849744 100644 --- a/VsDingExtensionFor2012/VsDingExtensionFor2012.csproj +++ b/VsDingExtensionFor2012/VsDingExtensionFor2012.csproj @@ -1,7 +1,7 @@  - 11.0 + 14.0 11.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) @@ -56,6 +56,9 @@ true + + $(DevEnvDir)\CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestWindow.Core.dll + diff --git a/VsDingExtensionProject/OptionsDialog.cs b/VsDingExtensionProject/OptionsDialog.cs index ad73042..131da46 100644 --- a/VsDingExtensionProject/OptionsDialog.cs +++ b/VsDingExtensionProject/OptionsDialog.cs @@ -22,7 +22,12 @@ namespace VitaliiGanzha.VsDingExtension [Category("Beeps")] [DisplayName("Tests")] [Description("Beep when a test run is completed")] - public bool IsBuildOnTestComplete { get; set; } + public bool IsBeepOnTestComplete { get; set; } + + [Category("Beeps")] + [DisplayName("Failed Tests")] + [Description("Beep only when a test failed")] + public bool IsBeepOnTestFailed { get; set; } [DisplayName("Only when in background")] [Description("Beep only when Visual Studio does not have focus")] @@ -36,7 +41,8 @@ namespace VitaliiGanzha.VsDingExtension { IsBeepOnBreakpointHit = true; IsBeepOnBuildComplete = true; - IsBuildOnTestComplete = true; + IsBeepOnTestComplete = true; + IsBeepOnTestFailed = false; ShowTrayNotifications = true; IsBeepOnlyWhenVisualStudioIsInBackground = false; } diff --git a/VsDingExtensionProject/Resources.Designer.cs b/VsDingExtensionProject/Resources.Designer.cs index d98eab0..b0f2be0 100644 --- a/VsDingExtensionProject/Resources.Designer.cs +++ b/VsDingExtensionProject/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18449 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. diff --git a/VsDingExtensionProject/VsDingExtensionProject.csproj b/VsDingExtensionProject/VsDingExtensionProject.csproj index cf98311..02f873f 100644 --- a/VsDingExtensionProject/VsDingExtensionProject.csproj +++ b/VsDingExtensionProject/VsDingExtensionProject.csproj @@ -1,10 +1,15 @@  - 12.0 + 14.0 12.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 12.0 speaker.ico @@ -58,6 +63,9 @@ true + + $(DevEnvDir)\CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestWindow.Core.dll + $(DevEnvDir)\CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestWindow.Interfaces.dll diff --git a/VsDingExtensionProject/VsDingExtensionProjectPackage.cs b/VsDingExtensionProject/VsDingExtensionProjectPackage.cs index 0d85223..a5fed66 100644 --- a/VsDingExtensionProject/VsDingExtensionProjectPackage.cs +++ b/VsDingExtensionProject/VsDingExtensionProjectPackage.cs @@ -15,9 +15,10 @@ using Microsoft.VisualStudio.ComponentModelHost; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.TestWindow.Extensibility; + using Microsoft.VisualStudio.TestWindow.Controller; using Process = System.Diagnostics.Process; - + [PackageRegistration(UseManagedResourcesOnly = true)] [InstalledProductRegistration("#110", "#112", "1.1", IconResourceID = 400)] [Guid(GuidList.guidVsDingExtensionProjectPkgString)] @@ -67,7 +68,7 @@ } }; - debugEvents.OnEnterBreakMode += delegate(dbgEventReason reason, ref dbgExecutionAction action) + debugEvents.OnEnterBreakMode += delegate (dbgEventReason reason, ref dbgExecutionAction action) { if (reason != dbgEventReason.dbgEventReasonStep && Options.IsBeepOnBreakpointHit) { @@ -163,9 +164,20 @@ private void OperationStateOnStateChanged(object sender, OperationStateChangedEventArgs operationStateChangedEventArgs) { - if (Options.IsBuildOnTestComplete && operationStateChangedEventArgs.State.HasFlag(TestOperationStates.TestExecutionFinished)) + if (Options.IsBeepOnTestComplete && operationStateChangedEventArgs.State.HasFlag(TestOperationStates.TestExecutionFinished)) { - HandleEventSafe(testCompleteSoundPlayer, "Test execution has been completed."); + if (Options.IsBeepOnTestFailed) + { + var testOperation = ((TestRunRequest)operationStateChangedEventArgs.Operation); + if (testOperation.DominantTestState == TestState.Failed) + { + HandleEventSafe(testCompleteSoundPlayer, "Test execution failed!"); + } + } + else + { + HandleEventSafe(testCompleteSoundPlayer, "Test execution has been completed."); + } } } #endregion @@ -180,7 +192,7 @@ var procId = Process.GetCurrentProcess().Id; int activeProcId; GetWindowThreadProcessId(activatedHandle, out activeProcId); - return activeProcId == procId; + return activeProcId == procId; } public void Dispose() From ce880f40ced3eb8b5263e699084e41d94d6f5f4b Mon Sep 17 00:00:00 2001 From: "Samir L. Boulema" Date: Wed, 16 Dec 2015 17:18:16 +0100 Subject: [PATCH 2/2] Change icon for error, Add option to disable message --- VsDingExtensionProject/OptionsDialog.cs | 5 ++++ .../VsDingExtensionProjectPackage.cs | 23 +++++++++++++++---- .../source.extension.vsixmanifest | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/VsDingExtensionProject/OptionsDialog.cs b/VsDingExtensionProject/OptionsDialog.cs index 131da46..0e29983 100644 --- a/VsDingExtensionProject/OptionsDialog.cs +++ b/VsDingExtensionProject/OptionsDialog.cs @@ -37,6 +37,10 @@ namespace VitaliiGanzha.VsDingExtension [Description("Show tray notifications for enabled events")] public bool ShowTrayNotifications { get; set; } + [DisplayName("Tray notifications message")] + [Description("Show message how to disable tray notifications")] + public bool ShowTrayDisableMessage { get; set; } + public OptionsDialog() { IsBeepOnBreakpointHit = true; @@ -45,6 +49,7 @@ namespace VitaliiGanzha.VsDingExtension IsBeepOnTestFailed = false; ShowTrayNotifications = true; IsBeepOnlyWhenVisualStudioIsInBackground = false; + ShowTrayDisableMessage = true; } } } diff --git a/VsDingExtensionProject/VsDingExtensionProjectPackage.cs b/VsDingExtensionProject/VsDingExtensionProjectPackage.cs index a5fed66..c643a60 100644 --- a/VsDingExtensionProject/VsDingExtensionProjectPackage.cs +++ b/VsDingExtensionProject/VsDingExtensionProjectPackage.cs @@ -102,6 +102,11 @@ } private void HandleEventSafe(SoundPlayer soundPlayer, string messageText) + { + HandleEventSafe(soundPlayer, messageText, ToolTipIcon.Info); + } + + private void HandleEventSafe(SoundPlayer soundPlayer, string messageText, ToolTipIcon icon) { if (!ShouldPerformNotificationAction()) { @@ -109,25 +114,33 @@ } PlaySoundSafe(soundPlayer); - ShowNotifyMessage(messageText); + ShowNotifyMessage(messageText, icon); } private void ShowNotifyMessage(string messageText) + { + ShowNotifyMessage(messageText, ToolTipIcon.Info); + } + + private void ShowNotifyMessage(string messageText, ToolTipIcon icon) { if (!_options.ShowTrayNotifications) { return; } - string autoAppendMessage = System.Environment.NewLine + "You can disable this notification in:" + System.Environment.NewLine + "Tools->Options->Ding->Show tray notifications"; - messageText = string.Format("{0}{1}", messageText, autoAppendMessage); + if (Options.ShowTrayDisableMessage) + { + string autoAppendMessage = System.Environment.NewLine + "You can disable this notification in:" + System.Environment.NewLine + "Tools->Options->Ding->Show tray notifications"; + messageText = string.Format("{0}{1}", messageText, autoAppendMessage); + } System.Threading.Tasks.Task.Run(async () => { var tray = new NotifyIcon { Icon = SystemIcons.Application, - BalloonTipIcon = ToolTipIcon.Info, + BalloonTipIcon = icon, BalloonTipText = messageText, BalloonTipTitle = "Visual Studio Ding extension", Visible = true @@ -171,7 +184,7 @@ var testOperation = ((TestRunRequest)operationStateChangedEventArgs.Operation); if (testOperation.DominantTestState == TestState.Failed) { - HandleEventSafe(testCompleteSoundPlayer, "Test execution failed!"); + HandleEventSafe(testCompleteSoundPlayer, "Test execution failed!", ToolTipIcon.Error); } } else diff --git a/VsDingExtensionProject/source.extension.vsixmanifest b/VsDingExtensionProject/source.extension.vsixmanifest index 3737064..b6868af 100644 --- a/VsDingExtensionProject/source.extension.vsixmanifest +++ b/VsDingExtensionProject/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + Visual Studio Ding extension This small extension will play notification sounds when following events occur: - Build Complete