private Selections Solve(Requirements requirements) { var selections = Solver.Solve(requirements); if (FeedManager.ShouldRefresh || SelectionsManager.GetUncachedSelections(selections).Any()) { FeedManager.Stale = false; FeedManager.Refresh = true; selections = Solver.Solve(requirements); FeedManager.Refresh = false; } try { selections.Name = FeedCache.GetFeed(selections.InterfaceUri).Name; } #region Error handling catch (KeyNotFoundException) { // Fall back to using feed file name selections.Name = selections.InterfaceUri.ToString().GetRightPartAtLastOccurrence('/'); } #endregion return(selections); }
/// <summary> /// Shows a list of changes found by the update process. /// </summary> protected override ExitCode ShowOutput() { var builder = new StringBuilder(); foreach (var oldImplementation in _oldSelections.Implementations) { var interfaceUri = oldImplementation.InterfaceUri; var newImplementation = Selections.GetImplementation(interfaceUri); if (newImplementation == null) { // Implementation removed builder.AppendLine(Resources.NoLongerUsed + interfaceUri); } else if (oldImplementation.Version != newImplementation.Version) { // Implementation updated builder.AppendLine(interfaceUri + ": " + oldImplementation.Version + " -> " + newImplementation.Version); } } foreach (var newImplementation in Selections.Implementations) { var interfaceUri = newImplementation.InterfaceUri; if (!_oldSelections.ContainsImplementation(interfaceUri)) { // Implementation added builder.AppendLine(interfaceUri + ": new -> " + newImplementation.Version); } } // Detect replaced feeds try { var feed = FeedCache.GetFeed(Requirements.InterfaceUri); if (feed.ReplacedBy != null) { builder.AppendLine(string.Format(Resources.FeedReplaced, Requirements.InterfaceUri, feed.ReplacedBy.Target)); } } catch (KeyNotFoundException) { } if (builder.Length == 0) { Handler.OutputLow(Resources.NoUpdatesFound, Resources.NoUpdatesFound); return(ExitCode.NoChanges); } else { Handler.Output(Resources.ChangesFound, builder.ToString()); return(ExitCode.OK); } }
/// <summary> /// Runs <see cref="ISolver.Solve"/> (unless <see cref="SelectionsDocument"/> is <c>true</c>) and stores the result in <see cref="Selections"/>. /// </summary> /// <returns>The same result as stored in <see cref="Selections"/>.</returns> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="WebException">A file could not be downloaded from the internet.</exception> /// <exception cref="IOException">An external application or file required by the solver could not be accessed.</exception> /// <exception cref="SolverException">The <see cref="ISolver"/> was unable to provide a set of <see cref="Selections"/> that fulfill the <see cref="Requirements"/>.</exception> protected virtual void Solve() { // TODO: Handle named apps // Don't run the solver if the user provided an external selections document if (SelectionsDocument) { return; } try { Selections = Solver.Solve(Requirements); } #region Error handling catch { // Suppress any left-over errors if the user canceled anyway Handler.CancellationToken.ThrowIfCancellationRequested(); throw; } #endregion try { Selections.Name = FeedCache.GetFeed(Selections.InterfaceUri).Name; } #region Error handling catch (KeyNotFoundException) { // Fall back to using feed file name Selections.Name = Selections.InterfaceUri.ToString().GetRightPartAtLastOccurrence('/'); } #endregion Handler.CancellationToken.ThrowIfCancellationRequested(); }
/// <inheritdoc/> public override ExitCode Execute() { Solve(); var exporter = new Exporter(Selections, Requirements.ForCurrentSystem().Architecture, _outputPath ?? throw new InvalidOperationException($"Must run {nameof(Parse)}() first.")); exporter.ExportFeeds(FeedCache, OpenPgp); if (!_noImplementations) { DownloadUncachedImplementations(); exporter.ExportImplementations(ImplementationStore, Handler); } if (FeedCache.GetFeed(Requirements.InterfaceUri) is {} feed) { exporter.ExportIcons( feed.Icons.Concat(feed.SplashScreens), IconStores.DesktopIntegration(Config, Handler, machineWide: false)); } exporter.DeployImportScript(); switch (_bootstrapType) { case BootstrapMode.Run: exporter.DeployBootstrapRun(Handler); break; case BootstrapMode.Integrate: exporter.DeployBootstrapIntegrate(Handler); break; } BackgroundSelfUpdate(); return(ShowOutput()); }