Exemple #1
0
            private ImplementationSelection AddToSelections([NotNull] SelectionCandidate candidate, [NotNull] Requirements requirements, [NotNull, ItemNotNull] IEnumerable <SelectionCandidate> allCandidates)
            {
                var selection = candidate.ToSelection(allCandidates, requirements);

                Selections.Implementations.Add(selection);
                _restrictions.AddRange(selection.Restrictions);
                return(selection);
            }
Exemple #2
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);
    }
Exemple #3
0
            private bool ConflictsWithExistingRestrictions([NotNull] SelectionCandidate candidate, [NotNull] FeedUri interfaceUri)
            {
                var nativeImplementation = candidate.Implementation as ExternalImplementation;

                foreach (var restriction in _restrictions.Where(x => x.InterfaceUri == interfaceUri))
                {
                    if (restriction.Versions != null && !restriction.Versions.Match(candidate.Version))
                    {
                        return(true);
                    }
                    if (nativeImplementation != null && !restriction.Distributions.ContainsOrEmpty(nativeImplementation.Distribution))
                    {
                        return(true);
                    }
                }
                return(false);
            }
Exemple #4
0
            private bool ConflictsWithExistingSelections([NotNull] SelectionCandidate candidate)
            {
                var nativeImplementation = candidate.Implementation as ExternalImplementation;

                foreach (var restriction in candidate.Implementation.Restrictions)
                {
                    var existingSelection = Selections.GetImplementation(restriction.InterfaceUri);
                    if (existingSelection != null)
                    {
                        if (restriction.Versions != null && !restriction.Versions.Match(existingSelection.Version))
                        {
                            return(true);
                        }
                        if (nativeImplementation != null && !restriction.Distributions.ContainsOrEmpty(nativeImplementation.Distribution))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }