本文整理汇总了C#中NuGet.Dialog.Providers.PackageItem类的典型用法代码示例。如果您正苦于以下问题:C# PackageItem类的具体用法?C# PackageItem怎么用?C# PackageItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PackageItem类属于NuGet.Dialog.Providers命名空间,在下文中一共展示了PackageItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanExecuteReturnsCorrectResult
public void CanExecuteReturnsCorrectResult()
{
// Local repository contains Package A and Package B
// We test the CanExecute() method on Package A and Package C
// Arrange
var repository = new MockPackageRepository();
var packageA = PackageUtility.CreatePackage("A", "1.0");
repository.AddPackage(packageA);
var packageB = PackageUtility.CreatePackage("B", "2.0");
repository.AddPackage(packageB);
var packageC = PackageUtility.CreatePackage("C", "2.0");
var projectManager = new Mock<IProjectManager>();
projectManager.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => repository.Exists(p));
var provider = CreateInstalledProvider(null, projectManager.Object);
var extensionA = new PackageItem(provider, packageA, null);
var extensionC = new PackageItem(provider, packageC, null);
// Act
bool canExecuteA = provider.CanExecute(extensionA);
bool canExecuteC = provider.CanExecute(extensionC);
// Assert
Assert.IsTrue(canExecuteA);
Assert.IsFalse(canExecuteC);
}
示例2: CanExecute
public override bool CanExecute(PackageItem item)
{
IPackage package = item.PackageIdentity;
if (package == null)
{
return false;
}
// only enable command on a Package in the Update provider if it not updated yet.
// the specified package can be updated if the local repository contains a package
// with matching id and smaller version number.
// Optimization due to bug #2008: if the LocalRepository is backed by a packages.config file,
// check the packages information directly from the file, instead of going through
// the IPackageRepository interface, which could potentially connect to TFS.
var packageLookup = LocalRepository as ILatestPackageLookup;
if (packageLookup != null)
{
SemanticVersion localPackageVersion;
return packageLookup.TryFindLatestPackageById(item.Id, out localPackageVersion) &&
localPackageVersion < package.Version;
}
return LocalRepository.GetPackages().Any(
p => p.Id.Equals(package.Id, StringComparison.OrdinalIgnoreCase) && p.Version < package.Version);
}
示例3: CanExecute
public override bool CanExecute(PackageItem item)
{
IPackage package = item.PackageIdentity;
if (package == null) {
return false;
}
// only enable command on a Package in the Update provider if it not updated yet.
// the specified package can be updated if the local repository contains a package
// with matching id and smaller version number.
return ProjectManager.LocalRepository.GetPackages().Any(
p => p.Id.Equals(package.Id, StringComparison.OrdinalIgnoreCase) && p.Version < package.Version);
}
示例4: CanExecuteReturnsCorrectResult
public void CanExecuteReturnsCorrectResult()
{
// Local repository contains Package A 1.0 and Package B
// Source repository contains Package A 2.0 and Package C
var packageA1 = PackageUtility.CreatePackage("A", "1.0");
var packageA2 = PackageUtility.CreatePackage("A", "2.0");
var packageB = PackageUtility.CreatePackage("B", "2.0");
var packageC = PackageUtility.CreatePackage("C", "3.0");
// Arrange
var localRepository = new MockPackageRepository();
localRepository.AddPackage(packageA1);
localRepository.AddPackage(packageB);
var sourceRepository = new MockPackageRepository();
sourceRepository.AddPackage(packageA2);
sourceRepository.AddPackage(packageC);
var projectManager = new Mock<IProjectManager>();
projectManager.Setup(p => p.LocalRepository).Returns(localRepository);
var packageManager = new Mock<IVsPackageManager>();
packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
var provider = CreateUpdatesProvider(packageManager.Object, projectManager.Object);
var extensionA = new PackageItem(provider, packageA2, null);
var extensionC = new PackageItem(provider, packageC, null);
// Act
bool canExecuteA = provider.CanExecute(extensionA);
bool canExecuteC = provider.CanExecute(extensionC);
// Assert
Assert.IsTrue(canExecuteA);
Assert.IsFalse(canExecuteC);
}
示例5: CanExecuteReturnsCorrectResult
public void CanExecuteReturnsCorrectResult()
{
// Arrange
var packageA = PackageUtility.CreatePackage("A", "1.0");
var packageB = PackageUtility.CreatePackage("B", "2.0");
var packageC = PackageUtility.CreatePackage("C", "3.0");
var sourceRepository = new MockPackageRepository();
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
sourceRepository.AddPackage(packageB);
var localRepository = new MockPackageRepository();
localRepository.AddPackage(packageA);
var projectManager = new Mock<IProjectManager>();
projectManager.Setup(p => p.IsInstalled(It.IsAny<IPackage>())).Returns<IPackage>(p => localRepository.Exists(p));
var packageManager = new Mock<IVsPackageManager>();
packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
var provider = CreateOnlineProvider(packageManager.Object, projectManager.Object);
var extensionA = new PackageItem(provider, packageA, null);
var extensionB = new PackageItem(provider, packageB, null);
var extensionC = new PackageItem(provider, packageC, null);
// Act
bool canExecuteA = provider.CanExecute(extensionA);
bool canExecuteB = provider.CanExecute(extensionB);
bool canExecuteC = provider.CanExecute(extensionC);
// Assert
Assert.IsTrue(canExecuteC);
Assert.IsTrue(canExecuteB);
Assert.IsFalse(canExecuteA);
}
示例6: ExecuteCore
/// <summary>
/// This method is called on background thread.
/// </summary>
/// <returns><c>true</c> if the method succeeded. <c>false</c> otherwise.</returns>
protected virtual bool ExecuteCore(PackageItem item)
{
return true;
}
示例7: CanExecute
public abstract bool CanExecute(PackageItem item);
示例8: ExecuteUninstallsSolutionLevelPackageWhenUpdating
public void ExecuteUninstallsSolutionLevelPackageWhenUpdating()
{
// Arrange
var packageA_10 = PackageUtility.CreatePackage("A", "1.0", content: null, assemblyReferences: null, tools: new[] { "init.ps1" }, dependencies: null);
var packageA_12 = PackageUtility.CreatePackage("A", "1.2", content: null, assemblyReferences: null, tools: new[] { "init.ps1" }, dependencies: null);
var sourceRepository = new MockPackageRepository();
sourceRepository.AddPackage(packageA_12);
var localRepository = new MockPackageRepository();
localRepository.AddPackage(packageA_10);
var projectManager1 = new Mock<IProjectManager>();
projectManager1.Setup(p => p.LocalRepository).Returns(localRepository);
var project1 = MockProjectUtility.CreateMockProject("Project1");
var packageManager = new Mock<IVsPackageManager>();
packageManager.Setup(p => p.LocalRepository).Returns(localRepository);
packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project1))).Returns(projectManager1.Object);
packageManager.Setup(p => p.IsProjectLevel(packageA_12)).Returns(false);
var solutionManager = new Mock<ISolutionManager>();
solutionManager.Setup(p => p.GetProject(It.Is<string>(s => s == "Project1"))).Returns(project1);
solutionManager.Setup(p => p.GetProjects()).Returns(new Project[] { project1 });
var mockWindowService = new Mock<IUserNotifierServices>();
mockWindowService.Setup(p => p.ShowProjectSelectorWindow(
It.IsAny<string>(),
It.IsAny<IPackage>(),
It.IsAny<Predicate<Project>>(),
It.IsAny<Predicate<Project>>())).Returns(new Project[0]);
var provider = CreateSolutionUpdatesProvider(packageManager.Object, localRepository, solutionManager: solutionManager.Object, userNotifierServices: mockWindowService.Object);
var extensionTree = provider.ExtensionsTree;
var firstTreeNode = (SimpleTreeNode)extensionTree.Nodes[0];
firstTreeNode.Repository.AddPackage(packageA_10);
provider.SelectedNode = firstTreeNode;
IVsPackageManager activePackageManager = provider.GetActivePackageManager();
Mock<IVsPackageManager> mockPackageManager = Mock.Get<IVsPackageManager>(activePackageManager);
var manualEvent = new ManualResetEventSlim(false);
Exception exception = null;
provider.ExecuteCompletedCallback = delegate
{
try
{
// Assert
mockPackageManager.Verify(p => p.UpdatePackage(
new Project[0],
packageA_12,
new[] { new PackageOperation(packageA_10, PackageAction.Uninstall), new PackageOperation(packageA_12, PackageAction.Install) },
true,
false,
provider,
provider), Times.Once());
}
catch (Exception e)
{
exception = e;
}
finally
{
manualEvent.Set();
}
};
var extensionA_12 = new PackageItem(provider, packageA_12);
// Act
provider.Execute(extensionA_12);
// do not allow the method to return
manualEvent.Wait();
Assert.Null(exception);
}
示例9: ExecuteCommand
protected override void ExecuteCommand(IProjectManager projectManager, PackageItem item, IVsPackageManager activePackageManager, IList<PackageOperation> operations)
{
activePackageManager.UpdatePackages(
projectManager,
new [] { item.PackageIdentity },
operations,
updateDependencies: true,
allowPrereleaseVersions: IncludePrerelease,
logger: this);
}
示例10: UninstallPackageFromProject
protected void UninstallPackageFromProject(Project project, PackageItem item, bool removeDependencies)
{
IProjectManager projectManager = null;
try
{
projectManager = PackageManager.GetProjectManager(project);
// make sure the package is installed in this project before proceeding
if (projectManager.IsInstalled(item.PackageIdentity))
{
RegisterPackageOperationEvents(PackageManager, projectManager);
PackageManager.UninstallPackage(projectManager, item.Id, version: item.PackageIdentity.Version, forceRemove: false, removeDependencies: removeDependencies, logger: this);
}
}
finally
{
if (projectManager != null)
{
UnregisterPackageOperationEvents(PackageManager, projectManager);
}
}
}
示例11: CanExecute
public override bool CanExecute(PackageItem item)
{
return true;
}
示例12: ExecuteMethodCallsInstallPackageMethodOnPackageManager
public void ExecuteMethodCallsInstallPackageMethodOnPackageManager(bool includePrerelease)
{
// Arrange
var packageA = PackageUtility.CreatePackage("A", "1.0");
var packageB = PackageUtility.CreatePackage("B", "2.0");
var packageC = PackageUtility.CreatePackage("C", "3.0");
var sourceRepository = new MockPackageRepository();
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
sourceRepository.AddPackage(packageB);
var localRepository = new MockPackageRepository();
localRepository.AddPackage(packageA);
var projectManager = new Mock<IProjectManager>();
projectManager.Setup(p => p.LocalRepository).Returns(localRepository);
var project = new Mock<Project>();
var packageManager = new Mock<IVsPackageManager>();
packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
packageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project.Object))).Returns(projectManager.Object);
var solutionManager = new Mock<ISolutionManager>();
solutionManager.Setup(s => s.GetProject(It.IsAny<string>())).Returns(project.Object);
var provider = CreateOnlineProvider(packageManager.Object, localRepository, solutionManager: solutionManager.Object, project: project.Object);
provider.IncludePrerelease = includePrerelease;
var extensionTree = provider.ExtensionsTree;
var firstTreeNode = (SimpleTreeNode)extensionTree.Nodes[0];
firstTreeNode.Repository.AddPackage(packageA);
firstTreeNode.Repository.AddPackage(packageB);
firstTreeNode.Repository.AddPackage(packageC);
provider.SelectedNode = firstTreeNode;
IVsPackageManager activePackageManager = provider.GetActivePackageManager();
Mock<IVsPackageManager> mockPackageManager = Mock.Get<IVsPackageManager>(activePackageManager);
mockPackageManager.Setup(p => p.GetProjectManager(It.Is<Project>(s => s == project.Object))).Returns(projectManager.Object);
ManualResetEvent manualEvent = new ManualResetEvent(false);
provider.ExecuteCompletedCallback = delegate
{
// Assert
Assert.Equal(RepositoryOperationNames.Install, sourceRepository.LastOperation);
mockPackageManager.Verify(p => p.InstallPackage(projectManager.Object, packageB, It.IsAny<IEnumerable<PackageOperation>>(), false, includePrerelease, provider), Times.Once());
manualEvent.Set();
};
var extensionB = new PackageItem(provider, packageB);
// Act
provider.Execute(extensionB);
// do not allow the method to return
manualEvent.WaitOne();
}
示例13: CanExecuteReturnsCorrectResultWhenLoweredVersionPackageIsInstalled
public void CanExecuteReturnsCorrectResultWhenLoweredVersionPackageIsInstalled()
{
// Arrange
var packageA = PackageUtility.CreatePackage("A", "1.0");
var packageB = PackageUtility.CreatePackage("B", "2.0");
var packageC = PackageUtility.CreatePackage("C", "3.0");
var sourceRepository = new MockPackageRepository();
sourceRepository.AddPackage(packageA);
sourceRepository.AddPackage(packageC);
sourceRepository.AddPackage(packageB);
var localRepository = new MockPackageRepository();
// these are installed packages
localRepository.AddPackage(PackageUtility.CreatePackage("A", "2.0"));
localRepository.AddPackage(PackageUtility.CreatePackage("B", "1.0-beta"));
localRepository.AddPackage(PackageUtility.CreatePackage("C", "3.0-beta"));
var packageManager = new Mock<IVsPackageManager>();
packageManager.Setup(p => p.SourceRepository).Returns(sourceRepository);
var provider = CreateOnlineProvider(packageManager.Object, localRepository);
var extensionA = new PackageItem(provider, packageA);
var extensionB = new PackageItem(provider, packageB);
var extensionC = new PackageItem(provider, packageC);
// Act
bool canExecuteA = provider.CanExecute(extensionA);
bool canExecuteB = provider.CanExecute(extensionB);
bool canExecuteC = provider.CanExecute(extensionC);
// Assert
Assert.False(canExecuteA);
Assert.True(canExecuteB);
Assert.True(canExecuteC);
}
示例14: Execute
public virtual void Execute(PackageItem item)
{
if (OperationCoordinator.IsBusy)
{
return;
}
// disable all operations while this install is in progress
OperationCoordinator.IsBusy = true;
_readmeFile = null;
_originalPackageId = item.Id;
_progressProvider.ProgressAvailable += OnProgressAvailable;
_uiCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
_culture = System.Threading.Thread.CurrentThread.CurrentCulture;
_failedProjects = new Dictionary<Project, Exception>();
ClearProgressMessages();
SaveExpandedNodes();
var worker = new BackgroundWorker();
worker.DoWork += OnRunWorkerDoWork;
worker.RunWorkerCompleted += OnRunWorkerCompleted;
worker.RunWorkerAsync(item);
// write an introductory sentence before every operation starts to make the console easier to read
string progressMessage = GetProgressMessage(item.PackageIdentity);
WriteLineToOutputWindow("------- " + progressMessage + " -------");
}
示例15: ExecuteCore
protected override bool ExecuteCore(PackageItem item)
{
_activePackageManager = GetActivePackageManager();
using (_activePackageManager.SourceRepository.StartOperation(RepositoryOperationNames.Update))
{
ShowProgressWindow();
IList<Project> selectedProjectsList;
bool isProjectLevel = _activePackageManager.IsProjectLevel(item.PackageIdentity);
if (isProjectLevel)
{
HideProgressWindow();
var selectedProjects = _userNotifierServices.ShowProjectSelectorWindow(
Resources.Dialog_UpdatesSolutionInstruction,
item.PackageIdentity,
// Selector function to return the initial checkbox state for a Project.
// We check a project if it has the current package installed by Id, but not version
project => _activePackageManager.GetProjectManager(project).LocalRepository.Exists(item.Id),
project =>
{
var localRepository = _activePackageManager.GetProjectManager(project).LocalRepository;
// for the Updates solution dialog, we only enable a project if it has an old version of
// the package installed.
return localRepository.Exists(item.Id) &&
!localRepository.Exists(item.Id, item.PackageIdentity.Version);
}
);
if (selectedProjects == null)
{
// user presses Cancel button on the Solution dialog
return false;
}
selectedProjectsList = selectedProjects.ToList();
if (selectedProjectsList.Count == 0)
{
return false;
}
ShowProgressWindow();
}
else
{
// solution package. just update into the solution
selectedProjectsList = new Project[0];
}
IList<PackageOperation> operations;
bool acceptLicense = isProjectLevel ? ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, selectedProjectsList, out operations)
: ShowLicenseAgreement(item.PackageIdentity, _activePackageManager, targetFramework: null, operations: out operations);
if (!acceptLicense)
{
return false;
}
if (!isProjectLevel && operations.Any())
{
// When dealing with solution level packages, only the set of actions specified under operations are executed.
// In such a case, no operation to uninstall the current package is specified. We'll identify the package that is being updated and
// explicitly add a uninstall operation.
var packageToUpdate = _activePackageManager.LocalRepository.FindPackage(item.Id);
if (packageToUpdate != null)
{
operations.Insert(0, new PackageOperation(packageToUpdate, PackageAction.Uninstall));
}
}
try
{
RegisterPackageOperationEvents(_activePackageManager, null);
_activePackageManager.UpdatePackage(
selectedProjectsList,
item.PackageIdentity,
operations,
updateDependencies: true,
allowPrereleaseVersions: IncludePrerelease,
logger: this,
eventListener: this);
}
finally
{
UnregisterPackageOperationEvents(_activePackageManager, null);
}
return true;
}
}