Esempio n. 1
0
    /// <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);
    }
Esempio n. 2
0
        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;
        }