This repository has been archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 771
/
PackageManagementSelectedProjects.cs
135 lines (115 loc) · 3.66 KB
/
PackageManagementSelectedProjects.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ICSharpCode.SharpDevelop.Project;
using NuGet;
namespace ICSharpCode.PackageManagement
{
public class PackageManagementSelectedProjects
{
IPackageManagementSolution solution;
bool? singledProjectSelected;
IProject singleMSBuildProjectSelected;
public PackageManagementSelectedProjects(IPackageManagementSolution solution)
{
this.solution = solution;
}
public IEnumerable<IPackageManagementSelectedProject> GetProjects(IPackageFromRepository package)
{
if (HasSingleProjectSelected()) {
yield return GetSingleProjectSelected(package);
} else {
foreach (IProject project in GetOpenProjects()) {
yield return CreateSelectedProject(project, package);
}
}
}
public bool HasSingleProjectSelected()
{
if (!singledProjectSelected.HasValue) {
singleMSBuildProjectSelected = solution.GetActiveMSBuildProject();
singledProjectSelected = singleMSBuildProjectSelected != null;
}
return singledProjectSelected.Value;
}
IEnumerable<IProject> GetOpenProjects()
{
return solution.GetMSBuildProjects();
}
IPackageManagementSelectedProject GetSingleProjectSelected(IPackageFromRepository package)
{
return CreateSelectedProject(singleMSBuildProjectSelected, package);
}
IPackageManagementSelectedProject CreateSelectedProject(IProject msbuildProject, IPackageFromRepository package)
{
IPackageManagementProject project = solution.GetProject(package.Repository, msbuildProject);
return CreateSelectedProject(project, package);
}
IPackageManagementSelectedProject CreateSelectedProject(
IPackageManagementProject project,
IPackageFromRepository package)
{
bool selected = project.IsPackageInstalled(package);
return new PackageManagementSelectedProject(project, selected);
}
public bool HasMultipleProjects()
{
if (HasSingleProjectSelected()) {
return false;
}
return solution.HasMultipleProjects();
}
public string SelectionName {
get { return GetSelectionName(); }
}
string GetSelectionName()
{
if (HasSingleProjectSelected()) {
return GetSingleProjectSelectedName();
}
return GetSolutionFileNameWithoutFullPath();
}
string GetSingleProjectSelectedName()
{
return singleMSBuildProjectSelected.Name;
}
string GetSolutionFileNameWithoutFullPath()
{
return Path.GetFileName(solution.FileName);
}
/// <summary>
/// Returns true if the package is installed in the selected projects.
/// </summary>
public bool IsPackageInstalled(IPackageFromRepository package)
{
IPackageManagementProject project = solution.GetActiveProject(package.Repository);
if (project != null) {
return project.IsPackageInstalled(package);
}
return IsPackageInstalledInSolution(package);
}
public bool IsPackageInstalledInSolution(IPackage package)
{
return solution.IsPackageInstalled(package);
}
public IQueryable<IPackage> GetPackagesInstalledInSolution()
{
return solution.GetPackages();
}
public IQueryable<IPackage> GetInstalledPackages(IPackageRepository sourceRepository)
{
if (HasSingleProjectSelected()) {
IPackageManagementProject project = GetActiveProject(sourceRepository);
return project.GetPackages();
}
return GetPackagesInstalledInSolution();
}
public IPackageManagementProject GetActiveProject(IPackageRepository repository)
{
return solution.GetActiveProject(repository);
}
}
}