Skip to content

If possible use Toast notify instead of Tray notify #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions VsDingExtension.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
# 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
Expand Down
5 changes: 4 additions & 1 deletion VsDingExtensionFor2012/VsDingExtensionFor2012.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<FileUpgradeFlags>
Expand All @@ -27,6 +27,7 @@
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\VsDingExtensionProject\Key.snk</AssemblyOriginatorKeyFile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetPlatformVersion>8.0</TargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -79,6 +80,8 @@
<Reference Include="Microsoft.VisualStudio.TestWindow.Interfaces">
<HintPath>$(DevEnvDir)\CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestWindow.Interfaces.dll</HintPath>
</Reference>
<Reference Include="Windows.Data" />
<Reference Include="Windows.UI" />
</ItemGroup>
<ItemGroup>
<COMReference Include="EnvDTE">
Expand Down
2 changes: 1 addition & 1 deletion VsDingExtensionProject/OptionsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class OptionsDialog : DialogPage

[Category("Beeps")]
[DisplayName("Failed Tests")]
[Description("Beep only when a test failed")]
[Description("Beep when a test run is completed and there are failed tests")]
public bool IsBeepOnTestFailed { get; set; }

[DisplayName("Only when in background")]
Expand Down
2 changes: 1 addition & 1 deletion VsDingExtensionProject/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 13 additions & 18 deletions VsDingExtensionProject/VsDingExtensionProject.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<TargetFrameworkProfile />
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
<StartArguments>/rootsuffix Exp</StartArguments>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>12.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>speaker.ico</ApplicationIcon>
Expand All @@ -26,6 +31,7 @@
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetPlatformVersion>8.0</TargetPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -49,7 +55,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.ComponentModelHost, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.ComponentModelHost, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.OLE.Interop" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0" />
Expand All @@ -76,27 +82,17 @@
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.12.0" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Composition.AttributedModel">
<HintPath>..\packages\Microsoft.Composition.1.0.20\lib\portable-net45+win8\System.Composition.AttributedModel.dll</HintPath>
</Reference>
<Reference Include="System.Composition.Convention">
<HintPath>..\packages\Microsoft.Composition.1.0.20\lib\portable-net45+win8\System.Composition.Convention.dll</HintPath>
</Reference>
<Reference Include="System.Composition.Hosting">
<HintPath>..\packages\Microsoft.Composition.1.0.20\lib\portable-net45+win8\System.Composition.Hosting.dll</HintPath>
</Reference>
<Reference Include="System.Composition.Runtime">
<HintPath>..\packages\Microsoft.Composition.1.0.20\lib\portable-net45+win8\System.Composition.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Composition.TypedParts">
<HintPath>..\packages\Microsoft.Composition.1.0.20\lib\portable-net45+win8\System.Composition.TypedParts.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Windows.Data" />
<Reference Include="Windows.UI" />
</ItemGroup>
<ItemGroup>
<COMReference Include="EnvDTE">
Expand Down Expand Up @@ -206,7 +202,6 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
Expand Down
89 changes: 67 additions & 22 deletions VsDingExtensionProject/VsDingExtensionProjectPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace VitaliiGanzha.VsDingExtension
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TestWindow.Extensibility;
using Task = System.Threading.Tasks.Task;

using Windows.UI.Notifications;
using System.Linq;
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.1", IconResourceID = 400)]
[Guid(GuidList.guidVsDingExtensionProjectPkgString)]
Expand Down Expand Up @@ -128,7 +129,13 @@ private void ShowNotifyMessage(string messageText, ToolTipIcon icon = ToolTipIco
messageText = string.Format("{0}{1}", messageText, autoAppendMessage);
}

Task.Run(async () =>
if (Win8OrHigher())
{
ShowToast("Visual Studio Ding extension", messageText);
}
else
{
Task.Run(async () =>
{
var tray = new NotifyIcon
{
Expand All @@ -145,6 +152,40 @@ private void ShowNotifyMessage(string messageText, ToolTipIcon icon = ToolTipIco
tray.Visible = false;
tray.Dispose();
});
}
}

private bool Win8OrHigher()
{
return Environment.OSVersion.Version >= new Version(6, 2, 9200, 0);
}

private void ShowToast(string title, string message)
{
var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
toastXml.GetElementsByTagName("text").First().AppendChild(toastXml.CreateTextNode(title));
toastXml.GetElementsByTagName("text").Last().AppendChild(toastXml.CreateTextNode(message));

var dte = GetGlobalService(typeof(DTE)) as DTE;
var notifier = ToastNotificationManager.CreateToastNotifier(EditionToAppUserModelId(dte.Edition));
notifier.Show(new ToastNotification(toastXml));
}

private string EditionToAppUserModelId(string edition)
{
string ApplicationID = "VisualStudio.11.0";
switch (edition)
{
case "WD Express":
return "VWDExpress.11.0";
case "Desktop Express":
return "WDExpress.11.0";
case "VSWin Express":
return "VSWinExpress.11.0";
case "PD Express":
return "VPDExpress.11.0";
}
return ApplicationID;
}

private bool ShouldPerformNotificationAction()
Expand All @@ -158,33 +199,37 @@ private bool ShouldPerformNotificationAction()

private void OperationStateOnStateChanged(object sender, OperationStateChangedEventArgs operationStateChangedEventArgs)
{
if (Options.IsBeepOnTestComplete && operationStateChangedEventArgs.State.HasFlag(TestOperationStates.TestExecutionFinished))
if (operationStateChangedEventArgs.State.HasFlag(TestOperationStates.TestExecutionFinished))
{
try
if (Options.IsBeepOnTestComplete)
{
HandleEventSafe(EventType.TestsCompletedSuccess, "Test execution has been completed.");
}

if (Options.IsBeepOnTestFailed)
{
// Issue #8: VS 2015 stops working when looking at Test Manager Window #8
// This extention can't take dependency on Microsoft.VisualStudio.TestWindow.Core.dll
// Because it will crash VS 2015. But DominantTestState is defined in that assembly.
// So as a workaround - cast it to dynamic (ewww, but alternative - to create new project/build and publish it separately.)
var testOperation = (dynamic)(operationStateChangedEventArgs.Operation);
var dominantTestState = (TestState)testOperation.DominantTestState;
var isTestsFailed = dominantTestState == TestState.Failed;
var eventType = isTestsFailed ? EventType.TestsCompletedFailure : EventType.TestsCompletedSuccess;
if (Options.IsBeepOnTestFailed && isTestsFailed)
try
{
HandleEventSafe(eventType, "Test execution failed!", ToolTipIcon.Error);
// Issue #8: VS 2015 stops working when looking at Test Manager Window #8
// This extention can't take dependency on Microsoft.VisualStudio.TestWindow.Core.dll
// Because it will crash VS 2015. But DominantTestState is defined in that assembly.
// So as a workaround - cast it to dynamic (ewww, but alternative - to create new project/build and publish it separately.)
var testOperation = (dynamic)(operationStateChangedEventArgs.Operation);
var dominantTestState = (TestState)testOperation.DominantTestState;
var isTestsFailed = dominantTestState == TestState.Failed;
var eventType = isTestsFailed ? EventType.TestsCompletedFailure : EventType.TestsCompletedSuccess;
if (isTestsFailed)
{
HandleEventSafe(eventType, "Test execution failed!", ToolTipIcon.Error);
}
}
else
catch (Exception ex)
{
HandleEventSafe(eventType, "Test execution has been completed.");
ActivityLog.LogError(GetType().FullName, ex.Message);
// Unable to get dominate test status, beep default sound for test
HandleEventSafe(EventType.TestsCompletedSuccess, "Test execution has been completed.");
}
}
catch (Exception ex)
{
ActivityLog.LogError(GetType().FullName, ex.Message);
// Unable to get dominate test status, beep default sound for test
HandleEventSafe(EventType.TestsCompletedSuccess, "Test execution has been completed.");
}
}
}
#endregion
Expand Down
2 changes: 1 addition & 1 deletion VsDingExtensionProject/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="26ba08d0-0d25-4479-8684-3054dd122876" Version="1.9" Language="en-US" Publisher="Vitalii Ganzha" />
<Identity Id="26ba08d0-0d25-4479-8684-3054dd122876" Version="2.0" Language="en-US" Publisher="Vitalii Ganzha" />
<DisplayName>Visual Studio Ding extension</DisplayName>
<Description xml:space="preserve">This small extension will play notification sounds when following events occur:
- Build Complete
Expand Down