forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageInstaller.cs
More file actions
55 lines (47 loc) · 1.48 KB
/
PackageInstaller.cs
File metadata and controls
55 lines (47 loc) · 1.48 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using Common.Logging;
using ScriptCs.Contracts;
namespace ScriptCs.Hosting.Package
{
public class PackageInstaller : IPackageInstaller
{
private readonly IInstallationProvider _installer;
private readonly ILog _logger;
public PackageInstaller(IInstallationProvider installer, ILog logger)
{
_installer = installer;
_logger = logger;
}
public void InstallPackages(IEnumerable<IPackageReference> packageIds, bool allowPreRelease = false)
{
if (packageIds == null)
{
throw new ArgumentNullException("packageIds");
}
packageIds = packageIds.ToList();
if (!packageIds.Any())
{
_logger.Info("Nothing to install.");
return;
}
bool successful = true;
foreach (var packageId in packageIds)
{
if (_installer.IsInstalled(packageId, allowPreRelease))
{
continue;
}
if(!_installer.InstallPackage(packageId, allowPreRelease))
{
successful = false;
}
}
if (packageIds.Count() > 1)
{
_logger.Info(successful ? "Installation successful." : "Installation unsuccessful.");
}
}
}
}