PageRenderTime 30ms CodeModel.GetById 2ms app.highlight 20ms RepoModel.GetById 2ms app.codeStats 0ms

/src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementProject.cs

https://github.com/ajadex/SharpDevelop
C# | 192 lines | 143 code | 32 blank | 17 comment | 2 complexity | 5f552df117d50adc320875e2589e70e2 MD5 | raw file
  1// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
  2// 
  3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
  4// software and associated documentation files (the "Software"), to deal in the Software
  5// without restriction, including without limitation the rights to use, copy, modify, merge,
  6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  7// to whom the Software is furnished to do so, subject to the following conditions:
  8// 
  9// The above copyright notice and this permission notice shall be included in all copies or
 10// substantial portions of the Software.
 11// 
 12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 17// DEALINGS IN THE SOFTWARE.
 18
 19using System;
 20using System.Collections.Generic;
 21using System.Linq;
 22
 23using ICSharpCode.PackageManagement.EnvDTE;
 24using ICSharpCode.SharpDevelop.Project;
 25using NuGet;
 26
 27namespace ICSharpCode.PackageManagement
 28{
 29	public class PackageManagementProject : IPackageManagementProject
 30	{
 31		ISharpDevelopPackageManager packageManager;
 32		ISharpDevelopProjectManager projectManager;
 33		IPackageManagementEvents packageManagementEvents;
 34		MSBuildBasedProject msbuildProject;
 35		
 36		public PackageManagementProject(
 37			IPackageRepository sourceRepository,
 38			MSBuildBasedProject project,
 39			IPackageManagementEvents packageManagementEvents,
 40			IPackageManagerFactory packageManagerFactory)
 41		{
 42			SourceRepository = sourceRepository;
 43			msbuildProject = project;
 44			this.packageManagementEvents = packageManagementEvents;
 45			
 46			packageManager = packageManagerFactory.CreatePackageManager(sourceRepository, project);
 47			projectManager = packageManager.ProjectManager;
 48		}
 49		
 50		public string Name {
 51			get { return msbuildProject.Name; }
 52		}
 53		
 54		public IPackageRepository SourceRepository { get; private set; }
 55		
 56		public ILogger Logger {
 57			get { return packageManager.Logger; }
 58			set {
 59				packageManager.Logger = value;
 60				packageManager.FileSystem.Logger = value;
 61			
 62				projectManager.Logger = value;
 63				projectManager.Project.Logger = value;
 64			}
 65		}
 66		
 67		public event EventHandler<PackageOperationEventArgs> PackageInstalled {
 68			add { packageManager.PackageInstalled += value; }
 69			remove { packageManager.PackageInstalled -= value; }
 70		}
 71		
 72		public event EventHandler<PackageOperationEventArgs> PackageUninstalled {
 73			add { packageManager.PackageUninstalled += value; }
 74			remove { packageManager.PackageUninstalled -= value; }
 75		}
 76		
 77		public event EventHandler<PackageOperationEventArgs> PackageReferenceAdded {
 78			add { projectManager.PackageReferenceAdded += value; }
 79			remove { projectManager.PackageReferenceAdded -= value; }
 80		}
 81		
 82		public event EventHandler<PackageOperationEventArgs> PackageReferenceRemoving {
 83			add { projectManager.PackageReferenceRemoving += value; }
 84			remove { projectManager.PackageReferenceRemoving -= value; }
 85		}
 86		
 87		public bool IsPackageInstalled(IPackage package)
 88		{
 89			return projectManager.IsInstalled(package);
 90		}
 91		
 92		public bool IsPackageInstalled(string packageId)
 93		{
 94			return projectManager.IsInstalled(packageId);
 95		}
 96		
 97		public IQueryable<IPackage> GetPackages()
 98		{
 99			return projectManager.LocalRepository.GetPackages();
100		}
101		
102		public IEnumerable<PackageOperation> GetInstallPackageOperations(IPackage package, InstallPackageAction installAction)
103		{
104			return packageManager.GetInstallPackageOperations(package, installAction);
105		}
106		
107		public void InstallPackage(IPackage package, InstallPackageAction installAction)
108		{
109			packageManager.InstallPackage(package, installAction);
110		}
111		
112		public void UninstallPackage(IPackage package, UninstallPackageAction uninstallAction)
113		{
114			packageManager.UninstallPackage(package, uninstallAction);
115		}
116		
117		public void UpdatePackage(IPackage package, UpdatePackageAction updateAction)
118		{
119			packageManager.UpdatePackage(package, updateAction);
120		}
121		
122		public InstallPackageAction CreateInstallPackageAction()
123		{
124			return new InstallPackageAction(this, packageManagementEvents);
125		}
126		
127		public UninstallPackageAction CreateUninstallPackageAction()
128		{
129			return new UninstallPackageAction(this, packageManagementEvents);
130		}
131		
132		public UpdatePackageAction CreateUpdatePackageAction()
133		{
134			return new UpdatePackageAction(this, packageManagementEvents);
135		}
136		
137		public Project ConvertToDTEProject()
138		{
139			return new Project(msbuildProject);
140		}
141		
142		public IEnumerable<IPackage> GetPackagesInReverseDependencyOrder()
143		{
144			var packageSorter = new PackageSorter(null);
145			return packageSorter
146				.GetPackagesByDependencyOrder(projectManager.LocalRepository)
147				.Reverse();
148		}
149		
150		public void UpdatePackages(UpdatePackagesAction updateAction)
151		{
152			packageManager.UpdatePackages(updateAction);
153		}
154		
155		public UpdatePackagesAction CreateUpdatePackagesAction()
156		{
157			return new UpdatePackagesAction(this, packageManagementEvents);
158		}
159		
160		public IEnumerable<PackageOperation> GetUpdatePackagesOperations(
161			IEnumerable<IPackage> packages,
162			IUpdatePackageSettings settings)
163		{
164			return packageManager.GetUpdatePackageOperations(packages, settings);
165		}
166		
167		public void RunPackageOperations(IEnumerable<PackageOperation> operations)
168		{
169			packageManager.RunPackageOperations(operations);
170		}
171		
172		public bool HasOlderPackageInstalled(IPackage package)
173		{
174			return projectManager.HasOlderPackageInstalled(package);
175		}
176		
177		public void UpdatePackageReference(IPackage package, IUpdatePackageSettings settings)
178		{
179			packageManager.UpdatePackageReference(package, settings);
180		}
181		
182		public IPackageConstraintProvider ConstraintProvider {
183			get {
184				var constraintProvider = projectManager.LocalRepository as IPackageConstraintProvider;
185				if (constraintProvider != null) {
186					return constraintProvider;
187				}
188				return NullConstraintProvider.Instance;
189			}
190		}
191	}
192}