Exemple #1
0
        /// <inheritdoc/>
        public Selections Solve(Requirements requirements)
        {
            #region Sanity checks
            if (requirements == null)
            {
                throw new ArgumentNullException(nameof(requirements));
            }
            if (requirements.InterfaceUri == null)
            {
                throw new ArgumentException(Resources.MissingInterfaceUri, nameof(requirements));
            }
            #endregion

            Selections?selections = null;
            _handler.RunTask(new SimpleTask(Resources.ExternalSolverRunning, () =>
            {
                using var control = new ExternalSolverSession(GetStartInfo())
                      {
                          { "confirm", args => DoConfirm((string)args[0]) },
                          { "confirm-keys", args => DoConfirmKeys(new FeedUri((string)args[0]), args[1].ReparseAsJson <Dictionary <string, string[][]> >()) },
                          { "update-key-info", args => null }
                      };
                control.Invoke(args =>
                {
                    if ((string)args[0] == "ok")
                    {
                        _feedManager.Stale = args[1].ReparseAsJson(new { stale = false }).stale;
                        selections         = XmlStorage.FromXmlString <Selections>((string)args[2]);
                    }
                    else
                    {
                        throw new SolverException(((string)args[1]).Replace("\n", Environment.NewLine));
                    }
                }, "select", GetEffectiveRequirements(requirements), false /*_feedManager.Refresh*/); // Pretend refresh is always false to avoid downloading feeds in external process (could cause problems with HTTPS and GPG validation)
                while (selections == null)
                {
                    control.HandleStderr();
                    control.HandleNextChunk();
                }
                control.HandleStderr();
            }));
            Debug.Assert(selections != null);

            // Invalidate in-memory feed cache, because external solver may have modified on-disk feed cache
            _feedManager.Clear();

            return(selections);
        }