Skip to content

Commit

Permalink
(chocolateyGH-14) IChocolateyPackageService ensure app installed
Browse files Browse the repository at this point in the history
ChocolateyPackageService will determine based on the ISourceRunners it
has in the list on ensuring that an app/tool is installed.
  • Loading branch information
ferventcoder committed Jan 22, 2015
1 parent 26d3670 commit 9968418
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ namespace chocolatey.infrastructure.app.services
public class ChocolateyPackageService : IChocolateyPackageService
{
private readonly INugetService _nugetService;
private readonly IEnumerable<ISourceRunner> _sourceRunners;
private readonly IPowershellService _powershellService;
private readonly IShimGenerationService _shimgenService;
private readonly IFileSystem _fileSystem;
private readonly IRegistryService _registryService;
private readonly IChocolateyPackageInformationService _packageInfoService;
private readonly IAutomaticUninstallerService _autoUninstallerService;

public ChocolateyPackageService(INugetService nugetService, IPowershellService powershellService, IShimGenerationService shimgenService, IFileSystem fileSystem, IRegistryService registryService, IChocolateyPackageInformationService packageInfoService, IAutomaticUninstallerService autoUninstallerService)
public ChocolateyPackageService(INugetService nugetService, IEnumerable<ISourceRunner> sourceRunners, IPowershellService powershellService, IShimGenerationService shimgenService, IFileSystem fileSystem, IRegistryService registryService, IChocolateyPackageInformationService packageInfoService, IAutomaticUninstallerService autoUninstallerService)
{
_nugetService = nugetService;
_sourceRunners = sourceRunners;
_powershellService = powershellService;
_shimgenService = shimgenService;
_fileSystem = fileSystem;
Expand All @@ -49,32 +51,59 @@ public ChocolateyPackageService(INugetService nugetService, IPowershellService p
_autoUninstallerService = autoUninstallerService;
}

public void list_noop(ChocolateyConfiguration config)
public void ensure_source_app_installed(ChocolateyConfiguration config)
{
perform_source_runner_action(config, r => r.ensure_source_app_installed(config, (packageResult) => handle_package_result(packageResult, config, CommandNameType.install)));
}

private void perform_source_runner_action(ChocolateyConfiguration config, Action<ISourceRunner> action)
{
if (config.Sources.is_equal_to(SpecialSourceType.webpi.to_string()))
var runner = _sourceRunners.FirstOrDefault(r => r.SourceType == config.SourceType);
if (runner != null && action != null)
{
//todo: webpi
action.Invoke(runner);
}
else
{
_nugetService.list_noop(config);
this.Log().Warn("No runner was found that implements source type '{0}' or action was missing".format_with(config.SourceType.to_string()));
}
}

private T perform_source_runner_function<T>(ChocolateyConfiguration config, Func<ISourceRunner,T> function)
{
var runner = _sourceRunners.FirstOrDefault(r => r.SourceType == config.SourceType);
if (runner != null && function != null)
{
return function.Invoke(runner);
}

this.Log().Warn("No runner was found that implements source type '{0}' or function was missing.".format_with(config.SourceType.to_string()));
return default(T);
}

public void list_noop(ChocolateyConfiguration config)
{
perform_source_runner_action(config, r => r.list_noop(config));

//switch (config.SourceType)
//{
// case SourceType.normal:
// _nugetService.list_noop(config);
// break;
// default:
// perform_source_runner_action(config,r => r.list_noop(config));
// break;
//}
}

public void list_run(ChocolateyConfiguration config, bool logResults)
{
this.Log().Debug(() => "Searching for package information");

if (config.Sources.is_equal_to(SpecialSourceType.webpi.to_string()))
{
//todo: webpi
//install webpi if not installed
//run the webpi command
this.Log().Warn("Command not yet functional, stay tuned...");
}
else
var list = perform_source_runner_function(config, r => r.list_run(config, logResults));

if (config.SourceType == SourceType.normal)
{
var list = _nugetService.list_run(config, logResults: true);
if (config.RegularOuptut)
{
this.Log().Warn(() => @"{0} packages {1}.".format_with(list.Count, config.ListCommand.LocalOnly ? "installed" : "found"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ namespace chocolatey.infrastructure.app.services
/// </summary>
public interface IChocolateyPackageService
{

/// <summary>
/// Ensures the application that controls a source is installed
/// </summary>
/// <param name="config">The configuration.</param>
void ensure_source_app_installed(ChocolateyConfiguration config);

/// <summary>
/// Run list in noop mode
/// </summary>
Expand Down

0 comments on commit 9968418

Please sign in to comment.