Skip to content

Commit

Permalink
(#494) Refresh the sources from file each time
Browse files Browse the repository at this point in the history
Sometimes (it looks like maybe when the Chocolatey Licensed Extension is
in play) we don't get the sources currently in the configuration file.
If instead of reusing the configuration settings service we instantiate
a new one each time, then it will ensure the configuration file is read
again. This resolves the issue of settings not applying in GUI if
they're made while GUI is running.
  • Loading branch information
corbob committed Sep 2, 2022
1 parent 424b8fb commit 583b1b9
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class ChocolateyService : IChocolateyService
private static readonly AsyncReaderWriterLock Lock = new AsyncReaderWriterLock();
private readonly IMapper _mapper;
private readonly IProgressService _progressService;
private readonly IChocolateyConfigSettingsService _configSettingsService;
private readonly IXmlService _xmlService;
private readonly IFileSystem _fileSystem;
private readonly IConfigService _configService;
Expand All @@ -46,11 +45,10 @@ public class ChocolateyService : IChocolateyService
#pragma warning disable SA1401 // Fields must be private
#pragma warning restore SA1401 // Fields must be private

public ChocolateyService(IMapper mapper, IProgressService progressService, IChocolateyConfigSettingsService configSettingsService, IXmlService xmlService, IFileSystem fileSystem, IConfigService configService)
public ChocolateyService(IMapper mapper, IProgressService progressService, IXmlService xmlService, IFileSystem fileSystem, IConfigService configService)
{
_mapper = mapper;
_progressService = progressService;
_configSettingsService = configSettingsService;
_xmlService = xmlService;
_fileSystem = fileSystem;
_configService = configService;
Expand Down Expand Up @@ -497,8 +495,8 @@ public async Task<ChocolateySource[]> GetSources()
// we need to read all information from the config file, i.e. the username and password
var config = await GetConfigFile();
var allSources = config.Sources.Select(_mapper.Map<ChocolateySource>).ToArray();

var filteredSourceIds = _configSettingsService.source_list(_choco.GetConfiguration()).Select(s => s.Id).ToArray();
var configSettingsService = new ChocolateyConfigSettingsService(_xmlService);
var filteredSourceIds = configSettingsService.source_list(_choco.GetConfiguration()).Select(s => s.Id).ToArray();

var mappedSources = allSources.Where(s => filteredSourceIds.Contains(s.Id)).ToArray();
return mappedSources;
Expand Down

0 comments on commit 583b1b9

Please sign in to comment.