Exemple #1
0
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            if (dependency.Flags.Contains(DependencyTreeFlags.SdkDependency))
            {
                // 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));
                    return;
                }
            }
            else if (dependency.Flags.Contains(DependencyTreeFlags.PackageDependency) && 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));
                }
            }

            context.Accept(dependency);
        }
 public virtual void BeforeAddOrUpdate(
     IDependency dependency,
     IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
     IImmutableSet <string>?projectItemSpecs,
     AddDependencyContext context)
 {
     context.Accept(dependency);
 }
        public override void BeforeAddOrUpdate(
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            if (dependency.Flags.Contains(DependencyTreeFlags.SdkDependency))
            {
                // This is an SDK dependency.
                //
                // Try to find a resolved package dependency with the same name.

                if (context.TryGetDependency(new DependencyId(PackageRuleHandler.ProviderTypeString, dependency.Id), out IDependency package) && package.Resolved)
                {
                    // Set to resolved and clear any diagnostic.

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

                if (context.TryGetDependency(new DependencyId(SdkRuleHandler.ProviderTypeString, dependency.Id), 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 clear any diagnostic.

                    context.AddOrUpdate(sdk.ToResolved(
                                            schemaName: ResolvedSdkReference.SchemaName,
                                            diagnosticLevel: DiagnosticLevel.None));
                }
            }

            context.Accept(dependency);
        }
        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);
        }
        public override void BeforeAddOrUpdate(
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            if (projectItemSpecs != null &&                                           // must have data
                !Strings.IsNullOrEmpty(dependency.OriginalItemSpec) &&
                !dependency.Implicit &&                                               // explicit
                dependency.Resolved &&                                                // resolved
                dependency.Flags.Contains(DependencyTreeFlags.GenericDependency) &&   // generic dependency
                !dependency.Flags.Contains(DependencyTreeFlags.SharedProjectDependency) && // except for shared projects
                !projectItemSpecs.Contains(dependency.OriginalItemSpec) &&            // is not a known item spec
                subTreeProviderByProviderType.TryGetValue(dependency.ProviderType, out IProjectDependenciesSubTreeProvider provider) &&
                provider is IProjectDependenciesSubTreeProviderInternal internalProvider)
            {
                // Obtain custom implicit icon
                ImageMoniker implicitIcon = internalProvider.ImplicitIcon;

                // Obtain a pooled icon set with this implicit icon
                DependencyIconSet implicitIconSet = DependencyIconSetCache.Instance.GetOrAddIconSet(
                    implicitIcon,
                    implicitIcon,
                    dependency.IconSet.UnresolvedIcon,
                    dependency.IconSet.UnresolvedExpandedIcon);

                context.Accept(
                    dependency.SetProperties(
                        iconSet: implicitIconSet,
                        isImplicit: true,
                        flags: dependency.Flags.Except(DependencyTreeFlags.SupportsRemove)));
                return;
            }

            context.Accept(dependency);
        }
Exemple #6
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.ProviderType, dependency.Id))
            {
                context.Reject();
                return;
            }

            context.Accept(dependency);
        }
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            IDependency?matchingDependency = null;
            bool        shouldApplyAlias   = false;

            foreach ((string _, IDependency other) in context)
            {
                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 (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, StringComparisons.ProjectTreeCaptionIgnoreCase) == 0)
                    {
                        shouldApplyAlias = true;
                    }
                }
            }

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

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

            return;
        public override void BeforeAddOrUpdate(
            IDependency dependency,
            AddDependencyContext context)
        {
            IDependency?matchingDependency = null;
            bool        shouldApplyAlias   = false;

            foreach ((DependencyId _, IDependency other) in context)
            {
                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 alias too
                    context.AddOrUpdate(matchingDependency.SetProperties(caption: GetAlias(matchingDependency)));
                }

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

            return;