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
54 lines (46 loc) · 1.62 KB
/
PackageInstaller.cs
File metadata and controls
54 lines (46 loc) · 1.62 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
using System;
using System.Collections.Generic;
using System.Linq;
using ScriptCs.Contracts;
namespace ScriptCs.Hosting.Package
{
public class PackageInstaller : IPackageInstaller
{
private readonly IInstallationProvider _installer;
private readonly ILog _logger;
public PackageInstaller(IInstallationProvider installer, ILogProvider logProvider)
{
Guard.AgainstNullArgument("installer", installer);
Guard.AgainstNullArgument("logProvider", logProvider);
_installer = installer;
_logger = logProvider.ForCurrentType();
}
public void InstallPackages(IEnumerable<IPackageReference> packageIds, bool allowPreRelease = false)
{
Guard.AgainstNullArgument("packageIds", packageIds);
packageIds = packageIds.Where(packageId => !_installer.IsInstalled(packageId, allowPreRelease)).ToList();
if (!packageIds.Any())
{
_logger.Info("Nothing to install.");
return;
}
var exceptions = new List<Exception>();
foreach (var packageId in packageIds)
{
try
{
_installer.InstallPackage(packageId, allowPreRelease);
}
catch (Exception ex)
{
_logger.ErrorException("Error installing package.", ex);
exceptions.Add(ex);
}
}
if (exceptions.Any())
{
throw new AggregateException(exceptions);
}
}
}
}