public override void BeforeAddOrUpdate(
            string projectPath,
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string> projectItemSpecs,
            IAddDependencyContext context)
        {
            IDependency matchingDependency = null;

            foreach ((string _, IDependency x) in context)
            {
                if (x.TopLevel &&
                    !x.Id.Equals(dependency.Id, StringComparison.OrdinalIgnoreCase) &&
                    StringComparers.DependencyProviderTypes.Equals(x.ProviderType, dependency.ProviderType) &&
                    x.Caption.Equals(dependency.Caption, StringComparison.OrdinalIgnoreCase))
                {
                    matchingDependency = x;
                    break;
                }
            }

            // If found node with same caption, or if there were nodes with same caption but with Alias already applied
            // NOTE: Performance sensitive, so avoid formatting the Caption with parenthesis if it's possible to avoid it.
            bool shouldApplyAlias = matchingDependency != null;

            if (!shouldApplyAlias)
            {
                int adjustedLength = dependency.Caption.Length + " (".Length;
                foreach ((string _, IDependency x) in context)
                {
                    if (x.TopLevel &&
                        !x.Id.Equals(dependency.Id, StringComparison.OrdinalIgnoreCase) &&
                        StringComparers.DependencyProviderTypes.Equals(x.ProviderType, dependency.ProviderType) &&
                        x.Caption.StartsWith(dependency.Caption, StringComparison.OrdinalIgnoreCase) &&
                        x.Caption.Length >= adjustedLength &&
                        string.Compare(x.Caption, adjustedLength, x.OriginalItemSpec, 0, x.OriginalItemSpec.Length, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        shouldApplyAlias = true;
                        break;
                    }
                }
            }

            if (shouldApplyAlias)
            {
                if (matchingDependency != null)
                {
                    context.AddOrUpdate(matchingDependency.SetProperties(caption: matchingDependency.Alias));
                }

                context.Accept(dependency.SetProperties(caption: dependency.Alias));
                return;
            }

            // Accept without changes
            context.Accept(dependency);
        }
        public override void BeforeAddOrUpdate(
            string projectPath,
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string> projectItemSpecs,
            IAddDependencyContext context)
        {
            if (!dependency.TopLevel)
            {
                context.Accept(dependency);
                return;
            }

            if (dependency.Flags.Contains(DependencyTreeFlags.SdkSubTreeNodeFlags))
            {
                // This is an SDK dependency.
                //
                // Try to find a resolved package dependency with the same name.

                string packageId = Dependency.GetID(targetFramework, PackageRuleHandler.ProviderTypeString, modelId: dependency.Name);

                if (context.TryGetDependency(packageId, out IDependency package) && package.Resolved)
                {
                    // Set to resolved, and copy dependencies.

                    context.Accept(dependency.ToResolved(
                                       schemaName: ResolvedSdkReference.SchemaName,
                                       dependencyIDs: package.DependencyIDs));
                    return;
                }
            }
            else if (dependency.Flags.Contains(DependencyTreeFlags.PackageNodeFlags) && dependency.Resolved)
            {
                // This is a resolved package dependency.
                //
                // Try to find an SDK dependency with the same name.

                string sdkId = Dependency.GetID(targetFramework, SdkRuleHandler.ProviderTypeString, modelId: dependency.Name);

                if (context.TryGetDependency(sdkId, out IDependency sdk))
                {
                    // We have an SDK dependency for this package. Such dependencies, when implicit, are created
                    // as unresolved by SdkRuleHandler, and are only marked resolved here once we have resolved the
                    // corresponding package.
                    //
                    // Set to resolved, and copy dependencies.

                    context.AddOrUpdate(sdk.ToResolved(
                                            schemaName: ResolvedSdkReference.SchemaName,
                                            dependencyIDs: dependency.DependencyIDs));
                }
            }

            context.Accept(dependency);
        }
        public override void BeforeAddOrUpdate(
            string projectPath,
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string> projectItemSpecs,
            IAddDependencyContext context)
        {
            // The check for SharedProjectDependency is needed because a SharedProject is not a dependency reference
            if (!dependency.TopLevel ||
                dependency.Implicit ||
                !dependency.Resolved ||
                !dependency.Flags.Contains(DependencyTreeFlags.GenericDependencyFlags) ||
                dependency.Flags.Contains(DependencyTreeFlags.SharedProjectFlags))
            {
                context.Accept(dependency);
                return;
            }

            if (projectItemSpecs == null)
            {
                // No data, so don't update
                context.Accept(dependency);
                return;
            }

            if (!projectItemSpecs.Contains(dependency.OriginalItemSpec))
            {
                // It is an implicit dependency
                if (subTreeProviderByProviderType.TryGetValue(dependency.ProviderType, out IProjectDependenciesSubTreeProvider provider) &&
                    provider is IProjectDependenciesSubTreeProviderInternal internalProvider)
                {
                    ImageMoniker implicitIcon = internalProvider.GetImplicitIcon();

                    DependencyIconSet implicitIconSet = DependencyIconSetCache.Instance.GetOrAddIconSet(
                        implicitIcon,
                        implicitIcon,
                        dependency.IconSet.UnresolvedIcon,
                        dependency.IconSet.UnresolvedExpandedIcon);

                    context.Accept(dependency.SetProperties(
                                       iconSet: implicitIconSet,
                                       isImplicit: true));
                    return;
                }
            }

            context.Accept(dependency);
        }
 public virtual void BeforeAddOrUpdate(
     ITargetFramework targetFramework,
     IDependency dependency,
     IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
     IImmutableSet <string>?projectItemSpecs,
     IAddDependencyContext context)
 {
     context.Accept(dependency);
 }
示例#5
0
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            IAddDependencyContext context)
        {
            if (dependency.TopLevel &&
                dependency.Resolved &&
                dependency.Flags.Contains(DependencyTreeFlags.ProjectDependency) &&
                !dependency.Flags.Contains(DependencyTreeFlags.SharedProjectFlags))
            {
                ITargetedDependenciesSnapshot?snapshot = _aggregateSnapshotProvider.GetSnapshot(dependency);

                if (snapshot != null && snapshot.HasVisibleUnresolvedDependency)
                {
                    context.Accept(dependency.ToUnresolved(ProjectReference.SchemaName));
                    return;
                }
            }

            context.Accept(dependency);
        }
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            IAddDependencyContext context)
        {
            // TODO should this verify that the existing one is actually resolved?
            if (!dependency.Resolved && context.Contains(dependency.Id))
            {
                context.Reject();
                return;
            }

            context.Accept(dependency);
        }
示例#7
0
        public override void BeforeAddOrUpdate(
            string projectPath,
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string> projectItemSpecs,
            IAddDependencyContext context)
        {
            IDependency matchingDependency = null;
            bool        shouldApplyAlias   = false;

            foreach ((string _, IDependency other) in context)
            {
                if (!other.TopLevel ||
                    other.Id.Equals(dependency.Id, StringComparison.OrdinalIgnoreCase) ||
                    !StringComparers.DependencyProviderTypes.Equals(other.ProviderType, dependency.ProviderType))
                {
                    continue;
                }

                if (other.Caption.StartsWith(dependency.Caption, StringComparison.OrdinalIgnoreCase))
                {
                    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 (ItemSpec)".

                    string itemSpec = other.OriginalItemSpec;
                    int    expectedItemSpecIndex = dependency.Caption.Length + 2;               // " (".Length
                    int    expectedLength        = expectedItemSpecIndex + itemSpec.Length + 1; // ")".Length

                    if (other.Caption.Length == expectedLength &&
                        string.Compare(other.Caption, expectedItemSpecIndex, itemSpec, 0, itemSpec.Length, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        shouldApplyAlias = true;
                    }
                }
            }

            if (shouldApplyAlias)
            {
                if (matchingDependency != null)
                {
                    // Change the matching dependency's alias too
                    context.AddOrUpdate(matchingDependency.SetProperties(caption: matchingDependency.Alias));
                }

                // Use the alias for the caption
                context.Accept(dependency.SetProperties(caption: dependency.Alias));
            }
            else
            {
                // Accept without changes
                context.Accept(dependency);
            }
        }