progress on issues #5 and #7

This commit is contained in:
Vitalii Ganzha 2016-01-05 19:31:37 -08:00
parent df15518a52
commit c4d7c3c21a
9 changed files with 265 additions and 50 deletions

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SampleTestProject")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SampleTestProject")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f0230a17-5be1-4adb-b2b9-39fed6d8b4c8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3A315AD2-E21E-4FC6-A601-795989A45514}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SampleTestProject</RootNamespace>
<AssemblyName>SampleTestProject</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="UnitTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,21 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace SampleTestProject
{
[TestClass]
public class UnitTests
{
[TestMethod]
public void TestMethodSuccess()
{
Assert.IsTrue(true);
}
[TestMethod]
public void TestMethodFailure()
{
Assert.IsTrue(false);
}
}
}

View File

@ -14,6 +14,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VsDingExtensionProject", "V
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VsDingExtensionFor2012", "VsDingExtensionFor2012\VsDingExtensionFor2012.csproj", "{F37A5870-9786-4196-A3BE-51FEC6155623}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleTestProject", "SampleTestProject\SampleTestProject.csproj", "{3A315AD2-E21E-4FC6-A601-795989A45514}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -28,6 +30,10 @@ Global
{F37A5870-9786-4196-A3BE-51FEC6155623}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F37A5870-9786-4196-A3BE-51FEC6155623}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F37A5870-9786-4196-A3BE-51FEC6155623}.Release|Any CPU.Build.0 = Release|Any CPU
{3A315AD2-E21E-4FC6-A601-795989A45514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A315AD2-E21E-4FC6-A601-795989A45514}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A315AD2-E21E-4FC6-A601-795989A45514}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A315AD2-E21E-4FC6-A601-795989A45514}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,24 +1,61 @@
using Microsoft.VisualStudio.Shell;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
namespace VitaliiGanzha.VsDingExtension
{
public class Players : IDisposable
{
private readonly Dictionary<EventType, IList<SoundPlayer>> eventTypeToSoundPlayerMapping;
using System;
using System.Collections.Generic;
using System.IO;
using System.Media;
using Microsoft.VisualStudio.Shell;
public Players()
public sealed class Players : IDisposable
{
eventTypeToSoundPlayerMapping = new Dictionary<EventType, IList<SoundPlayer>>();
eventTypeToSoundPlayerMapping[EventType.BuildCompleted] = new List<SoundPlayer>() { new SoundPlayer(Resources.build) };
eventTypeToSoundPlayerMapping[EventType.BreakpointHit] = new List<SoundPlayer>() { new SoundPlayer(Resources.debug) };
eventTypeToSoundPlayerMapping[EventType.TestsCompletedSuccess] = new List<SoundPlayer>() { new SoundPlayer(Resources.ding) };
eventTypeToSoundPlayerMapping[EventType.TestsCompletedFailure] = new List<SoundPlayer>() { new SoundPlayer(Resources.test_failed) };
private readonly SoundsSelectOptionsPage overridesSettings;
private Dictionary<EventType, IList<SoundPlayer>> eventTypeToSoundPlayerMapping;
public Players(SoundsSelectOptionsPage overridesSettings)
{
this.overridesSettings = overridesSettings;
this.SetupSounds();
}
private void SetupSounds()
{
// Add regular sounds
var tempMapping = new Dictionary<EventType, IList<SoundPlayer>>();
tempMapping[EventType.BuildCompleted] = new List<SoundPlayer>() { new SoundPlayer(Resources.build) };
tempMapping[EventType.BreakpointHit] = new List<SoundPlayer>() { new SoundPlayer(Resources.debug) };
tempMapping[EventType.TestsCompletedSuccess] = new List<SoundPlayer>()
{
new SoundPlayer(Resources.ding)
};
tempMapping[EventType.TestsCompletedFailure] = new List<SoundPlayer>()
{
new SoundPlayer(Resources.test_failed)
};
// Add custom sounds
this.AddSoundOverrideIf(tempMapping, this.overridesSettings.OverrideOnBuildSound, this.overridesSettings.CustomOnBuildSoundLocation, EventType.BuildCompleted);
this.AddSoundOverrideIf(tempMapping, this.overridesSettings.OverrideOnBreakpointHitSound, this.overridesSettings.CustomOnBreakpointHitSoundLocation, EventType.BreakpointHit);
this.AddSoundOverrideIf(tempMapping, this.overridesSettings.OverrideOnTestCompleteFailureSound, this.overridesSettings.CustomOnTestCompleteFailureSoundLocation, EventType.TestsCompletedFailure);
this.AddSoundOverrideIf(tempMapping, this.overridesSettings.OverrideOnTestCompleteSuccesSound, this.overridesSettings.CustomOnTestCompleteSuccesSoundLocation, EventType.TestsCompletedSuccess);
this.eventTypeToSoundPlayerMapping = tempMapping;
}
private void AddSoundOverrideIf(Dictionary<EventType, IList<SoundPlayer>> tempMapping, bool shouldAdd, string fileLocation, EventType eventType)
{
if (shouldAdd)
{
if (!string.IsNullOrWhiteSpace(fileLocation) &&
File.Exists(fileLocation))
{
tempMapping[eventType].Insert(0, new SoundPlayer(fileLocation));
}
}
}
public void SoundSettingsChanged()
{
this.SetupSounds();
}
public void PlaySoundSafe(EventType eventType)

View File

@ -9,7 +9,19 @@ namespace VitaliiGanzha.VsDingExtension
{
private EventType eventType = EventType.None;
public SoundsSelectOptionsPage OptionsPage = null;
public SoundsSelectOptionsPage optionsPage = null;
public SoundsSelectOptionsPage OptionsPage
{
get { return this.optionsPage; }
set
{
this.optionsPage = value;
this.ReadOptions();
this.optionsPage.StoreOptionsNotifier += this.StoreOptions;
this.optionsPage.OnActivateHandler += this.ReadOptions;
}
}
[Category("Data")]
[Description("Gets or sets the event type of the sound to override sound for")]
@ -30,13 +42,11 @@ namespace VitaliiGanzha.VsDingExtension
public SingleSoundSelectControl()
{
InitializeComponent();
ReadOptions();
}
private void chkUseDifferentSound_CheckedChanged(object sender, System.EventArgs e)
{
ValidateProperties();
this.StoreOptions();
}
private void btnBrowse_Click(object sender, EventArgs e)
@ -52,7 +62,6 @@ namespace VitaliiGanzha.VsDingExtension
if (File.Exists(file))
{
this.selectedFileEdit.Text = file;
this.StoreOptions();
}
}

View File

@ -18,6 +18,12 @@ namespace VitaliiGanzha.VsDingExtension
#region Properties
public Action OnApplyHandler { get; set; }
public Action StoreOptionsNotifier { get; set; }
public Action OnActivateHandler { get; set; }
/// <summary>
/// Gets the window an instance of DialogPage that it uses as its user interface.
/// </summary>
@ -46,6 +52,27 @@ namespace VitaliiGanzha.VsDingExtension
}
}
protected override void OnApply(DialogPage.PageApplyEventArgs e)
{
if (this.StoreOptionsNotifier != null)
{
this.StoreOptionsNotifier();
}
if (this.OnApplyHandler != null)
{
this.OnApplyHandler();
}
}
protected override void OnActivate(CancelEventArgs cancelEventArgs)
{
if (this.OnActivateHandler != null)
{
this.OnActivateHandler();
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public bool OverrideOnBuildSound { get; set; }

View File

@ -1,23 +1,18 @@
namespace VitaliiGanzha.VsDingExtension
namespace VitaliiGanzha.VsDingExtension
{
using System;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Media;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TestWindow.Extensibility;
using Microsoft.VisualStudio.TestWindow.Controller;
using Process = System.Diagnostics.Process;
using Microsoft.VisualStudio.TestWindow.Extensibility;
using Task = System.Threading.Tasks.Task;
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.1", IconResourceID = 400)]
@ -31,7 +26,8 @@
private BuildEvents buildEvents;
private DebuggerEvents debugEvents;
private OptionsDialog _options = null;
private Players players = new Players();
private SoundsSelectOptionsPage soundOverridesSettings = null;
private Players players = null;
public VsDingExtensionProjectPackage()
{
@ -49,6 +45,8 @@
buildEvents = applicationObject.Events.BuildEvents;
debugEvents = applicationObject.Events.DebuggerEvents;
players = new Players(this.SoundSettingsOverrides);
this.soundOverridesSettings.OnApplyHandler += () => this.players.SoundSettingsChanged();
SetupEventHandlers();
}
@ -95,12 +93,19 @@
}
}
private void HandleEventSafe(EventType eventType, string messageText)
private SoundsSelectOptionsPage SoundSettingsOverrides
{
HandleEventSafe(eventType, messageText, ToolTipIcon.Info);
get
{
if (this.soundOverridesSettings == null)
{
this.soundOverridesSettings = (SoundsSelectOptionsPage)GetDialogPage(typeof(SoundsSelectOptionsPage));
}
return this.soundOverridesSettings;
}
}
private void HandleEventSafe(EventType eventType, string messageText, ToolTipIcon icon)
private void HandleEventSafe(EventType eventType, string messageText, ToolTipIcon icon = ToolTipIcon.Info)
{
if (!ShouldPerformNotificationAction())
{
@ -111,12 +116,7 @@
ShowNotifyMessage(messageText, icon);
}
private void ShowNotifyMessage(string messageText)
{
ShowNotifyMessage(messageText, ToolTipIcon.Info);
}
private void ShowNotifyMessage(string messageText, ToolTipIcon icon)
private void ShowNotifyMessage(string messageText, ToolTipIcon icon = ToolTipIcon.Info)
{
if (!_options.ShowTrayNotifications)
{
@ -125,11 +125,11 @@
if (Options.ShowTrayDisableMessage)
{
string autoAppendMessage = System.Environment.NewLine + "You can disable this notification in:" + System.Environment.NewLine + "Tools->Options->Ding->Show tray notifications";
string autoAppendMessage = Environment.NewLine + "You can disable this notification in:" + Environment.NewLine + "Tools->Options->Ding->Show tray notifications";
messageText = string.Format("{0}{1}", messageText, autoAppendMessage);
}
System.Threading.Tasks.Task.Run(async () =>
Task.Run(async () =>
{
var tray = new NotifyIcon
{
@ -141,7 +141,7 @@
};
tray.ShowBalloonTip(5000);
await System.Threading.Tasks.Task.Delay(5000);
await Task.Delay(5000);
tray.Icon = (Icon)null;
tray.Visible = false;
tray.Dispose();

View File

@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace VitaliiGanzha.VsDingExtension
{
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
public static class WinApiHelper
{
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]