コード例 #1
0
        /// <summary>
        /// Adds a new, or replaces an existing dependency (keyed on <see cref="IDependency.ProviderType"/> and <see cref="IDependency.Id"/>).
        /// </summary>
        /// <remarks>
        /// In the course of filtering one dependency, the filter may wish to modify or add other
        /// dependencies in the project's tree. This method allows that to happen.
        /// </remarks>
        public void AddOrUpdate(IDependency dependency)
        {
            DependencyId key = dependency.GetDependencyId();

            _dependencyById.Remove(key);
            _dependencyById.Add(key, dependency);
            Changed = true;
        }
コード例 #2
0
        /// <summary>
        /// Adds a new, or replaces an existing dependency (keyed on <see cref="IDependency.ProviderType"/> and <see cref="IDependency.Id"/>).
        /// </summary>
        /// <remarks>
        /// In the course of filtering one dependency, the filter may wish to modify or add other
        /// dependencies in the project's tree. This method allows that to happen.
        /// </remarks>
        public void AddOrUpdate(IDependency dependency)
        {
            DependencyId dependencyId = dependency.GetDependencyId();

            _dependencyById.Remove(dependencyId);
            _dependencyById.Add(dependencyId, dependency);
            Changed = true;
        }
        /// <summary>
        /// Deduplicates captions of top-level dependencies from the same provider. This is done by
        /// appending the <see cref="IDependencyModel.OriginalItemSpec"/> to the caption in parentheses.
        /// </summary>
        private static void DeduplicateCaptions(
            ref IDependency dependency,
            Dictionary <DependencyId, IDependency> dependencyById)
        {
            IDependency?matchingDependency = null;
            bool        shouldApplyAlias   = false;

            foreach ((DependencyId _, IDependency other) in dependencyById)
            {
                if (StringComparers.DependencyTreeIds.Equals(other.Id, dependency.Id) ||
                    !StringComparers.DependencyProviderTypes.Equals(other.ProviderType, dependency.ProviderType))
                {
                    continue;
                }

                if (other.Caption.StartsWith(dependency.Caption, StringComparisons.ProjectTreeCaptionIgnoreCase))
                {
                    if (other.Caption.Length == dependency.Caption.Length)
                    {
                        // Exact match.
                        matchingDependency = other;
                        shouldApplyAlias   = true;
                        break;
                    }

                    // Prefix matches.
                    // Check whether we have a match of form "Caption (Suffix)".
                    string?suffix = GetSuffix(other);

                    if (suffix != null)
                    {
                        int expectedItemSpecIndex = dependency.Caption.Length + 2;             // " (".Length
                        int expectedLength        = expectedItemSpecIndex + suffix.Length + 1; // ")".Length

                        if (other.Caption.Length == expectedLength &&
                            string.Compare(other.Caption, expectedItemSpecIndex, suffix, 0, suffix.Length, StringComparisons.ProjectTreeCaptionIgnoreCase) == 0)
                        {
                            shouldApplyAlias = true;
                        }
                    }
                }
            }

            if (shouldApplyAlias)
            {
                if (matchingDependency != null)
                {
                    // Change the matching dependency's caption too
                    IDependency modifiedMatching = matchingDependency.WithCaption(caption: GetAlias(matchingDependency));
                    dependencyById[modifiedMatching.GetDependencyId()] = modifiedMatching;
                }

                // Use the alias for the caption
                dependency = dependency.WithCaption(caption: GetAlias(dependency));
            }

            return;
コード例 #4
0
        public override void BeforeAddOrUpdate(
            IDependency dependency,
            AddDependencyContext context)
        {
            // TODO should this verify that the existing one is actually resolved?
            if (!dependency.Resolved && context.Contains(dependency.GetDependencyId()))
            {
                context.Reject();
                return;
            }

            context.Accept(dependency);
        }
コード例 #5
0
        public override void BeforeAddOrUpdate(
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            // TODO should this verify that the existing one is actually resolved?
            if (!dependency.Resolved && context.Contains(dependency.GetDependencyId()))
            {
                context.Reject();
                return;
            }

            context.Accept(dependency);
        }
コード例 #6
0
        private protected void VerifyUnchangedOnAdd(IDependency dependency, IImmutableSet <string>?projectItemSpecs = null)
        {
            var dependencyById = new Dictionary <DependencyId, IDependency>
            {
                { dependency.GetDependencyId(), dependency }
            };

            var context = new AddDependencyContext(dependencyById);

            var filter = CreateFilter();

            filter.BeforeAddOrUpdate(
                dependency,
                null !,
                projectItemSpecs,
                context);

            // Accepts unchanged dependency
            Assert.Same(dependency, context.GetResult(filter));

            // No other changes made
            Assert.False(context.Changed);
        }