Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zhili1208 committed Oct 9, 2015
1 parent 0d432a5 commit d0a4794
Show file tree
Hide file tree
Showing 32 changed files with 1,014 additions and 16 deletions.
570 changes: 569 additions & 1 deletion NuGet.Clients.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
<Project>{306cddfa-ff0b-4299-930c-9ec6c9308160}</Project>
<Name>PackageManagement.VisualStudio</Name>
</ProjectReference>
<ProjectReference Include="..\VisualStudioAPI\VisualStudioAPI.csproj">
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudioAPI</Name>
<Name>VisualStudio</Name>
</ProjectReference>
<ProjectReference Include="..\VsConsole\Console.Types\Console.Types.csproj">
<Project>{6fd11460-39a3-4a10-ba63-7541b0a7d053}</Project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RestoreNuGetPackages>true</RestoreNuGetPackages>
<PackagesDir>$(UserProfile)\.nuget\packages</PackagesDir>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<AssemblyOriginatorKeyFile>$(MS_PFX_PATH)</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>$(MS_PFX_PATH)</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '14.0'">
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
Expand Down Expand Up @@ -42,6 +42,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.CoreUtility, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
Expand Down Expand Up @@ -147,6 +148,7 @@
<Compile Include="UserInterfaceService\NuGetUIProjectContext.cs" />
<Compile Include="UserSettings.cs" />
<Compile Include="Utility\NuGetUIThreadHelper.cs" />
<Compile Include="Utility\PackageManagerProviderUtility.cs" />
<Compile Include="Utility\RegistrySettingUtility.cs" />
<Compile Include="Utility\UIUtility.cs" />
<Compile Include="VersionForDisplay.cs" />
Expand Down Expand Up @@ -281,6 +283,12 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudio</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\build\common.targets" />
<Import Project="..\..\..\build\sign.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using NuGet.ProjectManagement;
using NuGet.Protocol.Core.Types;
using NuGet.VisualStudio;

namespace NuGet.PackageManagement.UI
{
Expand Down Expand Up @@ -37,5 +38,7 @@ public interface INuGetUIContext
/// </summary>
/// <param name="show">The value of the setting.</param>
void ApplyShowPreviewSetting(bool show);

IEnumerable<IPackageManagerProvider> PackageManagerProviders { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using NuGet.ProjectManagement;
using NuGet.Protocol.Core.Types;
using NuGet.VisualStudio;

namespace NuGet.PackageManagement.UI
{
Expand All @@ -14,6 +15,7 @@ namespace NuGet.PackageManagement.UI
public abstract class NuGetUIContextBase : INuGetUIContext
{
private readonly NuGetProject[] _projects;
private readonly IEnumerable<IPackageManagerProvider> _packageManagerProviders;

protected NuGetUIContextBase(
ISourceRepositoryProvider sourceProvider,
Expand All @@ -22,7 +24,8 @@ protected NuGetUIContextBase(
UIActionEngine uiActionEngine,
IPackageRestoreManager packageRestoreManager,
IOptionsPageActivator optionsPageActivator,
IEnumerable<NuGetProject> projects)
IEnumerable<NuGetProject> projects,
IEnumerable<IPackageManagerProvider> packageManagerProviders)
{
SourceProvider = sourceProvider;
SolutionManager = solutionManager;
Expand All @@ -32,6 +35,7 @@ protected NuGetUIContextBase(
PackageRestoreManager = packageRestoreManager;
OptionsPageActivator = optionsPageActivator;
_projects = projects.ToArray();
_packageManagerProviders = packageManagerProviders;
}

public ISourceRepositoryProvider SourceProvider { get; }
Expand All @@ -58,5 +62,10 @@ public IEnumerable<NuGetProject> Projects
public abstract void PersistSettings();

public abstract void ApplyShowPreviewSetting(bool show);

public IEnumerable<IPackageManagerProvider> PackageManagerProviders
{
get { return _packageManagerProviders; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.Utilities;
using NuGet.VisualStudio;

namespace NuGet.PackageManagement.UI
{
public static class PackageManagerProviderUtility
{
public static List<IPackageManagerProvider> Sort(IEnumerable<Lazy<IPackageManagerProvider, IOrderable>> packageManagerProviders, int max)
{
var sortedProviders = new List<IPackageManagerProvider>();
var uniqueId = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

foreach (var provider in Orderer.Order(packageManagerProviders))
{
if (sortedProviders.Count() < max && !uniqueId.Contains(provider.Value.PackageManagerId))
{
uniqueId.Add(provider.Value.PackageManagerId);
sortedProviders.Add(provider.Value);
}
}

return sortedProviders;
}
}
}
4 changes: 4 additions & 0 deletions src/NuGet.Clients/StandaloneUI/StandaloneUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
<Project>{538adefd-2170-40a9-a2c5-ec8369cfe490}</Project>
<Name>PackageManagement.UI</Name>
</ProjectReference>
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudio</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\build\common.targets" />
Expand Down
2 changes: 1 addition & 1 deletion src/NuGet.Clients/StandaloneUI/StandaloneUIContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public StandaloneUIContext(
IOptionsPageActivator optionsPageActivator,
IEnumerable<NuGetProject> projects)
:
base(sourceProvider, solutionManager, packageManager, uiActionEngine, packageRestoreManager, optionsPageActivator, projects)
base(sourceProvider, solutionManager, packageManager, uiActionEngine, packageRestoreManager, optionsPageActivator, projects, null)
{
_settingsFile = settingsFile;
LoadSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VisualStudioAPI\VisualStudioAPI.csproj">
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudioAPI</Name>
<Name>VisualStudio</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
47 changes: 47 additions & 0 deletions src/NuGet.Clients/VisualStudio/IPackageManagerProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

namespace NuGet.VisualStudio
{
/// <summary>
/// Interface allowing integration of alternate package manager suggestion for a NuGet package.
/// For example jQuery may appear on Bower and it might be more appropriate to install a package from Bower for certain projects
/// </summary>
[ComImport]
[Guid("BCED5BF2-40FC-4D9F-BF0A-43CD4E9FF65F")]
public interface IPackageManagerProvider
{
/// <summary>
/// Localized display package manager name.
/// </summary>
string PackageManagerName { get; }

/// <summary>
/// Package manager unique id.
/// </summary>
string PackageManagerId { get; }

/// <summary>
/// Display description for package manager when user hover over the manager name on UI.
/// </summary>
string Description { get; }

/// <summary>
/// Check if a recommendation should be surfaced for an alternate package manager.
/// This code should not rely on slow network calls, and should return rapidly.
/// </summary>
/// <param name="packageId">Current package id</param>
/// <param name="projectName">Unique project name for finding the project through VS dte</param>
/// <param name="token">Cancellation Token</param>
/// <returns>return true if need to direct to integrated package manager for this package</returns>
Task<bool> CheckForPackage(string packageId, string projectName, CancellationToken token);

/// <summary>
/// This Action should take the user to the other package manager.
/// </summary>
/// <param name="packageId">Current package id</param>
/// <param name="projectName">Unique project name for finding the project through VS dte</param>
void GoToPackage(string packageId, string projectName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="Extensibility\IVsPackageRestorer.cs" />
<Compile Include="Extensibility\IVsPackageUninstaller.cs" />
<Compile Include="Extensibility\VsPackageEventHandler.cs" />
<Compile Include="IPackageManagerProvider.cs" />
<Compile Include="IRegistryKey.cs" />
<Compile Include="IVsTemplateWizard.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions src/NuGet.Clients/VsExtension/VisualStudioUIContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NuGet.PackageManagement.VisualStudio;
using NuGet.ProjectManagement;
using NuGet.Protocol.Core.Types;
using NuGet.VisualStudio;

namespace NuGetVSExtension
{
Expand All @@ -24,9 +25,10 @@ public VisualStudioUIContext(
UIActionEngine uiActionEngine,
IPackageRestoreManager packageRestoreManager,
IOptionsPageActivator optionsPageActivator,
IEnumerable<NuGetProject> projects)
IEnumerable<NuGetProject> projects,
IEnumerable<IPackageManagerProvider> packageManagerProviders)
:
base(sourceProvider, solutionManager, packageManager, uiActionEngine, packageRestoreManager, optionsPageActivator, projects)
base(sourceProvider, solutionManager, packageManager, uiActionEngine, packageRestoreManager, optionsPageActivator, projects, packageManagerProviders)
{
_package = package;
}
Expand Down
12 changes: 10 additions & 2 deletions src/NuGet.Clients/VsExtension/VisualStudioUIContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.VisualStudio.Utilities;
using NuGet.Configuration;
using NuGet.PackageManagement;
using NuGet.PackageManagement.UI;
using NuGet.ProjectManagement;
using NuGet.Protocol.Core.Types;
using NuGet.VisualStudio;

namespace NuGetVSExtension
{
Expand All @@ -22,21 +24,26 @@ internal class VisualStudioUIContextFactory : INuGetUIContextFactory
private readonly IOptionsPageActivator _optionsPage;
private readonly ISettings _settings;
private readonly IDeleteOnRestartManager _deleteOnRestartManager;
private readonly List<IPackageManagerProvider> _packageManagerProviders;
// only pick up at most three integrated package managers
private const int MaxPackageManager = 3;

[ImportingConstructor]
public VisualStudioUIContextFactory([Import] ISourceRepositoryProvider repositoryProvider,
[Import] ISolutionManager solutionManager,
[Import] ISettings settings,
[Import] IPackageRestoreManager packageRestoreManager,
[Import] IOptionsPageActivator optionsPage,
[Import] IDeleteOnRestartManager deleteOnRestartManager)
[Import] IDeleteOnRestartManager deleteOnRestartManager,
[ImportMany] IEnumerable<Lazy<IPackageManagerProvider, IOrderable>> packageManagerProviders)
{
_repositoryProvider = repositoryProvider;
_solutionManager = solutionManager;
_restoreManager = packageRestoreManager;
_optionsPage = optionsPage;
_settings = settings;
_deleteOnRestartManager = deleteOnRestartManager;
_packageManagerProviders = PackageManagerProviderUtility.Sort(packageManagerProviders, MaxPackageManager);
}

public INuGetUIContext Create(NuGetPackage package, IEnumerable<NuGetProject> projects)
Expand All @@ -62,7 +69,8 @@ public INuGetUIContext Create(NuGetPackage package, IEnumerable<NuGetProject> pr
actionEngine,
_restoreManager,
_optionsPage,
projects);
projects,
_packageManagerProviders);
}
}
}
7 changes: 4 additions & 3 deletions src/NuGet.Clients/VsExtension/VsExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@
<Project>{eea49a74-6efc-410e-9745-bad367ac151d}</Project>
<Name>VisualStudio14</Name>
</ProjectReference>
<ProjectReference Include="..\VisualStudioAPI\VisualStudioAPI.csproj">
<Project>{E5556BC6-A7FD-4D8E-8A7D-7648DF1D7471}</Project>
<Name>VisualStudioAPI</Name>
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudio</Name>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup%3bBuiltProjectOutputGroupDependencies%3bGetCopyToOutputDirectoryItems%3bSatelliteDllsProjectOutputGroup%3b</IncludeOutputGroupsInVSIX>
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup%3b</IncludeOutputGroupsInVSIXLocalOnly>
</ProjectReference>
Expand Down Expand Up @@ -206,6 +206,7 @@
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.CoreUtility, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="Console" Path="|Console|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="PowerShellHostProvider" Path="|PowerShellHostProvider|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="File" Path="NuGet.Configuration.dll" />
<Asset Type="Microsoft.VisualStudio.Assembly" d:Source="Project" d:ProjectName="VisualStudioAPI" Path="|VisualStudioAPI|" AssemblyName="|VisualStudioAPI;AssemblyName|" />
<Asset Type="Microsoft.VisualStudio.Assembly" d:Source="Project" d:ProjectName="VisualStudio.Interop" Path="|VisualStudio.Interop|" AssemblyName="|VisualStudio.Interop;AssemblyName|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="NuGet.VisualStudioImplement" Path="|NuGet.VisualStudio.Implementation|" />
<Asset Type="Microsoft.VisualStudio.Assembly" d:Source="Project" d:ProjectName="VisualStudio" Path="|VisualStudio|" AssemblyName="|VisualStudio;AssemblyName|" />
</Assets>
</PackageManifest>
Loading

0 comments on commit d0a4794

Please sign in to comment.