private bool TryToUseExistingCandidate([NotNull] Requirements requirements, [NotNull, ItemNotNull] IEnumerable <SelectionCandidate> suitableCandidates, [NotNull] ImplementationSelection selection) { if (!suitableCandidates.Contains(selection)) { return(false); } if (selection.ContainsCommand(requirements.Command)) { return(true); } var command = selection.AddCommand(requirements, from: _candidateProvider.LookupOriginalImplementation(selection)); return(TryToSolveCommand(command, requirements)); }
/// <summary> /// Turns a <see cref="SelectionCandidate"/> into a <see cref="ImplementationSelection"/>. /// </summary> /// <param name="candidate">The selection candidate.</param> /// <param name="requirements">The requirements the candidate was chosen for.</param> /// <param name="allCandidates">All candidates that were considered for selection (including <paramref name="candidate"/>). These are used to present the user with possible alternatives.</param> public static ImplementationSelection ToSelection(this SelectionCandidate candidate, Requirements requirements, [InstantHandle] IEnumerable <SelectionCandidate> allCandidates) { #region Sanity checks if (candidate == null) { throw new ArgumentNullException(nameof(candidate)); } if (allCandidates == null) { throw new ArgumentNullException(nameof(allCandidates)); } if (requirements == null) { throw new ArgumentNullException(nameof(requirements)); } #endregion var implementation = candidate.Implementation; var selection = new ImplementationSelection(allCandidates) { ID = implementation.ID, LocalPath = implementation.LocalPath, ManifestDigest = implementation.ManifestDigest, Architecture = implementation.Architecture, Version = implementation.Version, Released = implementation.Released, Stability = candidate.EffectiveStability, License = implementation.License, UnknownAttributes = implementation.UnknownAttributes, UnknownElements = implementation.UnknownElements, InterfaceUri = requirements.InterfaceUri }; if (candidate.FeedUri != requirements.InterfaceUri) { selection.FromFeed = candidate.FeedUri; } if (implementation is ExternalImplementation externalImplementation) { selection.QuickTestFile = externalImplementation.QuickTestFile; } selection.Bindings.AddRange(implementation.Bindings.CloneElements()); selection.AddDependencies(requirements, from: candidate.Implementation); selection.AddCommand(requirements, from: candidate.Implementation); return(selection); }
public static ImplementationSelection ToSelection([NotNull] this SelectionCandidate candidate, [NotNull, ItemNotNull] IEnumerable<SelectionCandidate> allCandidates, [NotNull] Requirements requirements) { #region Sanity checks if (candidate == null) throw new ArgumentNullException("candidate"); if (allCandidates == null) throw new ArgumentNullException("allCandidates"); if (requirements == null) throw new ArgumentNullException("requirements"); #endregion var implementation = candidate.Implementation; var selection = new ImplementationSelection(allCandidates) { ID = implementation.ID, LocalPath = implementation.LocalPath, ManifestDigest = implementation.ManifestDigest, Architecture = implementation.Architecture, Version = implementation.Version, Released = implementation.Released, Stability = candidate.EffectiveStability, License = implementation.License, InterfaceUri = requirements.InterfaceUri }; if (candidate.FeedUri != requirements.InterfaceUri) selection.FromFeed = candidate.FeedUri; var externalImplementation = implementation as ExternalImplementation; if (externalImplementation != null) selection.QuickTestFile = externalImplementation.QuickTestFile; selection.Bindings.AddRange(implementation.Bindings.CloneElements()); selection.AddDependencies(requirements, from: candidate.Implementation); selection.AddCommand(requirements, from: candidate.Implementation); return selection; }