public async Task UpdateSource(string id, ChocolateySource source) { if (id != source.Id) { await RemoveSource(id); } await AddSource(source); }
public async Task AddSource(ChocolateySource source) { using (await Lock.WriteLockAsync()) { var choco = Lets.GetChocolatey().SetCustomLogging(new SerilogLogger(Logger, _progressService)); choco.Set( config => { config.CommandName = "source"; config.SourceCommand.Command = SourceCommandType.add; config.SourceCommand.Name = source.Id; config.Sources = source.Value; config.SourceCommand.Username = source.UserName; config.SourceCommand.Password = source.Password; config.SourceCommand.Certificate = source.Certificate; config.SourceCommand.CertificatePassword = source.CertificatePassword; config.SourceCommand.Priority = source.Priority; config.SourceCommand.BypassProxy = source.BypassProxy; config.SourceCommand.AllowSelfService = source.AllowSelfService; config.SourceCommand.VisibleToAdminsOnly = source.VisibleToAdminsOnly; }); await choco.RunAsync(); if (source.Disabled) { choco.Set( config => { config.CommandName = "source"; config.SourceCommand.Command = SourceCommandType.disable; config.SourceCommand.Name = source.Id; }); await choco.RunAsync(); } else { choco.Set( config => { config.CommandName = "source"; config.SourceCommand.Command = SourceCommandType.enable; config.SourceCommand.Name = source.Id; }); await choco.RunAsync(); } } }