public async override Task <DictionaryConfiguration> CollectConfigAsync(IOperationCollectionContext context) { using (var serverContext = context.GetServerCollectionContext()) { var output = await this.ExecuteChocolateyAsync(context, "list --limit-output --local-only").ConfigureAwait(false); if (output == null) { return(null); } await serverContext.ClearAllPackagesAsync("Chocolatey").ConfigureAwait(false); foreach (var values in output) { string name = values[0]; string version = values[1]; await serverContext.CreateOrUpdatePackageAsync( packageType : "Chocolatey", packageName : name, packageVersion : version, packageUrl : null ).ConfigureAwait(false); } return(null); } }
public async override Task <DscConfiguration> CollectConfigAsync(IOperationCollectionContext context) { var job = new CollectDscModulesJob { DebugLogging = true }; job.MessageLogged += (s, e) => this.Log(e.Level, e.Message); var jobExecuter = await context.Agent.GetServiceAsync <IRemoteJobExecuter>(); var result = (CollectDscModulesJob.Result) await jobExecuter.ExecuteJobAsync(job, context.CancellationToken); using (var serverContext = context.GetServerCollectionContext()) { await serverContext.ClearAllPackagesAsync("DSC Module"); foreach (var module in result.Modules) { await serverContext.CreateOrUpdatePackageAsync( packageType : "DSC Module", packageName : module.Name, packageVersion : module.Version, packageUrl : null ); } return(null); } }
public override async Task <PersistedConfiguration> CollectAsync(IOperationCollectionContext context) { IList <RegisteredPackage> packages; this.LogDebug("Connecting to machine package registry..."); using (var registry = await PackageRegistry.GetRegistryAsync(context.Agent, false).ConfigureAwait(false)) { this.LogDebug("Acquiring package registry lock..."); await registry.LockAsync(context.CancellationToken).ConfigureAwait(false); this.LogDebug($"Package registry lock acquired (token={registry.LockToken})."); this.LogInformation("Retreiving list of packages..."); packages = await registry.GetInstalledPackagesAsync().ConfigureAwait(false); this.LogInformation("Packages installed: " + packages.Count); // doesn't need to be in a finally because dispose will unlock if necessary, but prefer doing it asynchronously await registry.UnlockAsync().ConfigureAwait(false); } this.LogDebug("Recording installed packages..."); using (var collect = context.GetServerCollectionContext()) { await collect.ClearAllPackagesAsync("UPack"); foreach (var p in packages) { await collect.CreateOrUpdateUniversalPackageAsync( "UPack", string.IsNullOrWhiteSpace(p.Group)?p.Name : (p.Group + "/" + p.Name), p.Version, p.FeedUrl, new CollectedUniversalPackageData { Path = p.InstallPath, Cached = false, Date = p.InstallationDate, Reason = p.InstallationReason, Tool = p.InstalledUsing, User = p.InstalledBy } ); } } this.LogInformation("Package collection complete."); return(null); }