/// <inheritdoc/> public Selections Solve(Requirements requirements) { #region Sanity checks if (requirements == null) { throw new ArgumentNullException("requirements"); } if (requirements.InterfaceUri == null) { throw new ArgumentException(Resources.MissingInterfaceUri, "requirements"); } #endregion Log.Info("Running Python Solver for: " + requirements); // Execute the external solver ISolverControl control; if (WindowsUtils.IsWindows) { control = new SolverControlBundled(_handler); // Use bundled Python on Windows } else { control = new SolverControlNative(_handler); // Use native Python everywhere else } string arguments = GetSolverArguments(requirements); string result = null; _handler.RunTask(new SimpleTask(Resources.ExternalSolverRunning, () => { result = control.ExecuteSolver(arguments); })); // Flush in-memory cache in case external solver updated something on-disk _feedManager.Flush(); // Detect when feeds get out-of-date _feedManager.Stale = result.Contains("<!-- STALE_FEEDS -->"); // Parse StandardOutput data as XML _handler.CancellationToken.ThrowIfCancellationRequested(); try { var selections = XmlStorage.FromXmlString <Selections>(result); selections.Normalize(); return(selections); } #region Error handling catch (InvalidDataException ex) { Log.Warn("Solver result:" + Environment.NewLine + result); throw new SolverException(Resources.ExternalSolverOutputErrror, ex); } #endregion }