コード例 #1
0
 public bool Equals(CacheKey other)
 {
     return(EqualityUtility.NotNullAndSameType(this, other) &&
            _type.Equals(other._type) &&
            string.Equals(_methodName, other._methodName) &&
            _bindingFlags == other._bindingFlags);
 }
コード例 #2
0
        public bool Equals(ProjectRestoreMetadata other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(ProjectStyle == other.ProjectStyle &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(ProjectPath, other.ProjectPath) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(ProjectJsonPath, other.ProjectJsonPath) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(OutputPath, other.OutputPath) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(ProjectName, other.ProjectName) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(ProjectUniqueName, other.ProjectUniqueName) &&
                   Sources.OrderedEquals(other.Sources.Distinct(), source => source.Source, StringComparer.OrdinalIgnoreCase) &&
                   PathUtility.GetStringComparerBasedOnOS().Equals(PackagesPath, other.PackagesPath) &&
                   ConfigFilePaths.OrderedEquals(other.ConfigFilePaths, filePath => filePath, PathUtility.GetStringComparerBasedOnOS(), PathUtility.GetStringComparerBasedOnOS()) &&
                   FallbackFolders.OrderedEquals(other.FallbackFolders, fallbackFolder => fallbackFolder, PathUtility.GetStringComparerBasedOnOS(), PathUtility.GetStringComparerBasedOnOS()) &&
                   EqualityUtility.SequenceEqualWithNullCheck(TargetFrameworks, other.TargetFrameworks) &&
                   OriginalTargetFrameworks.OrderedEquals(other.OriginalTargetFrameworks, fw => fw, StringComparer.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase) &&
                   CrossTargeting == other.CrossTargeting &&
                   LegacyPackagesDirectory == other.LegacyPackagesDirectory &&
                   ValidateRuntimeAssets == other.ValidateRuntimeAssets &&
                   SkipContentFileWrite == other.SkipContentFileWrite &&
                   EqualityUtility.SequenceEqualWithNullCheck(Files, other.Files) &&
                   EqualityUtility.EqualsWithNullCheck(ProjectWideWarningProperties, other.ProjectWideWarningProperties));
        }
コード例 #3
0
ファイル: AsyncTagger.cs プロジェクト: zf724/VsVim
            internal TrackingCacheData Merge(ITextSnapshot snapshot, TrackingCacheData trackingCacheData)
            {
                var          left  = TrackingSpan.GetSpanSafe(snapshot);
                var          right = trackingCacheData.TrackingSpan.GetSpanSafe(snapshot);
                SnapshotSpan span;

                if (left.HasValue && right.HasValue)
                {
                    span = left.Value.CreateOverarching(right.Value);
                }
                else if (left.HasValue)
                {
                    span = left.Value;
                }
                else if (right.HasValue)
                {
                    span = right.Value;
                }
                else
                {
                    span = new SnapshotSpan(snapshot, 0, 0);
                }
                var trackingSpan = snapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive);

                var tagList = TrackingList
                              .Concat(trackingCacheData.TrackingList)
                              .Distinct(EqualityUtility.Create <Tuple <ITrackingSpan, TTag> >(
                                            (x, y) => x.Item1.GetSpanSafe(snapshot) == y.Item1.GetSpanSafe(snapshot),
                                            tuple => tuple.Item1.GetSpanSafe(snapshot).GetHashCode()))
                              .ToReadOnlyCollection();

                return(new TrackingCacheData(trackingSpan, tagList));
            }
コード例 #4
0
        private static bool HasProjectDependencyChanged(IEnumerable <LibraryDependency> newDependencies, IEnumerable <LockFileDependency> lockFileDependencies)
        {
            // If the count is not the same, something has changed.
            // Otherwise we N^2 walk below determines whether anything has changed.
            var newPackageDependencies = newDependencies.Where(dep => dep.LibraryRange.TypeConstraint == LibraryDependencyTarget.Package);

            if (newPackageDependencies.Count() != lockFileDependencies.Count())
            {
                return(true);
            }

            foreach (var dependency in newPackageDependencies)
            {
                var lockFileDependency = lockFileDependencies.FirstOrDefault(d => StringComparer.OrdinalIgnoreCase.Equals(d.Id, dependency.Name));

                if (lockFileDependency == null || !EqualityUtility.EqualsWithNullCheck(lockFileDependency.RequestedVersion, dependency.LibraryRange.VersionRange))
                {
                    // dependency has changed and lock file is out of sync.
                    return(true);
                }
            }

            // no dependency changed. Lock file is still valid.
            return(false);
        }
コード例 #5
0
 public bool Equals(Tuple <T1, T2, T3> other)
 {
     return(EqualityUtility.NotNullAndSameType(this, other) &&
            EqualityUtility.Equals(_item1, other._item1) &&
            EqualityUtility.Equals(_item2, other._item2) &&
            EqualityUtility.Equals(_item3, other._item3));
 }
コード例 #6
0
        /// <summary>
        /// The method will return true if:
        /// 1. If a transitive dependency from the lock file is now added to the central file.
        ///     or
        /// 1. If there is a mistmatch between the RequestedVersion of a lock file dependency marked as CentralTransitive and the the version specified in the central package management file.
        ///     or
        /// 2. If a central version that is a transitive dependency is removed from CPVM the lock file is invalidated.
        /// </summary>
        private static bool HasProjectTransitiveDependencyChanged(
            IDictionary <string, CentralPackageVersion> centralPackageVersions,
            IList <LockFileDependency> lockFileCentralTransitiveDependencies,
            IList <LockFileDependency> lockTransitiveDependencies)
        {
            // Transitive dependencies moved to be centraly managed will invalidate the lock file
            var transitiveDependenciesMovedToBeManagedCentrally = lockTransitiveDependencies.Where(dep => centralPackageVersions.ContainsKey(dep.Id));

            if (transitiveDependenciesMovedToBeManagedCentrally.Any())
            {
                return(true);
            }

            foreach (var lockFileDependencyEnforcedByCPV in lockFileCentralTransitiveDependencies)
            {
                if (centralPackageVersions.TryGetValue(lockFileDependencyEnforcedByCPV.Id, out var centralPackageVersion))
                {
                    if (centralPackageVersion != null && !EqualityUtility.EqualsWithNullCheck(lockFileDependencyEnforcedByCPV.RequestedVersion, centralPackageVersion.VersionRange))
                    {
                        return(true);
                    }
                    continue;
                }

                // The central version was removed
                return(true);
            }

            return(false);
        }
コード例 #7
0
        public bool Equals(ProjectRestoreMetadata other)
        {
            if (other == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(ProjectStyle == other.ProjectStyle &&
                   ProjectPath == other.ProjectPath &&
                   ProjectJsonPath == other.ProjectJsonPath &&
                   OutputPath == other.OutputPath &&
                   ProjectName == other.ProjectName &&
                   ProjectUniqueName == other.ProjectUniqueName &&
                   EqualityUtility.SequenceEqualWithNullCheck(Sources, other.Sources) &&
                   PackagesPath == other.PackagesPath &&
                   EqualityUtility.SequenceEqualWithNullCheck(ConfigFilePaths, other.ConfigFilePaths) &&
                   EqualityUtility.SequenceEqualWithNullCheck(FallbackFolders, other.FallbackFolders) &&
                   EqualityUtility.SequenceEqualWithNullCheck(TargetFrameworks, other.TargetFrameworks) &&
                   EqualityUtility.SequenceEqualWithNullCheck(OriginalTargetFrameworks, other.OriginalTargetFrameworks) &&
                   CrossTargeting == other.CrossTargeting &&
                   LegacyPackagesDirectory == other.LegacyPackagesDirectory &&
                   ValidateRuntimeAssets == other.ValidateRuntimeAssets &&
                   SkipContentFileWrite == other.SkipContentFileWrite &&
                   EqualityUtility.SequenceEqualWithNullCheck(Files, other.Files) &&
                   EqualityUtility.EqualsWithNullCheck(ProjectWideWarningProperties, other.ProjectWideWarningProperties));
        }
コード例 #8
0
ファイル: PluginManager.cs プロジェクト: dslzuha/nugetclient
        /// <summary>
        /// Creates a plugin from the discovered plugin.
        /// We firstly check the cache for the operation claims for the given request key.
        /// If there is a valid cache entry, and it does contain the requested operation claim, then we start the plugin, and if need be update the cache value itself.
        /// If there is a valid cache entry, and it does NOT contain the requested operation claim, then we return a null.
        /// If there is no valid cache entry or an invalid one, we start the plugin as normally, return an active plugin even if the requested claim is not available, and write a cache entry.
        /// </summary>
        /// <param name="result">plugin discovery result</param>
        /// <param name="requestedOperationClaim">The requested operation claim</param>
        /// <param name="requestKey">plugin request key</param>
        /// <param name="packageSourceRepository">package source repository</param>
        /// <param name="serviceIndex">service index</param>
        /// <param name="cancellationToken">cancellation token</param>
        /// <returns>A plugin creation result, null if the requested plugin cannot handle the given operation claim</returns>
        private async Task <Tuple <bool, PluginCreationResult> > TryCreatePluginAsync(
            PluginDiscoveryResult result,
            OperationClaim requestedOperationClaim,
            PluginRequestKey requestKey,
            string packageSourceRepository,
            JObject serviceIndex,
            CancellationToken cancellationToken)
        {
            PluginCreationResult pluginCreationResult = null;
            var cacheEntry = new PluginCacheEntry(_pluginsCacheDirectory.Value, result.PluginFile.Path, requestKey.PackageSourceRepository);

            return(await ConcurrencyUtilities.ExecuteWithFileLockedAsync(
                       cacheEntry.CacheFileName,
                       action : async lockedToken =>
            {
                if (cacheEntry.OperationClaims == null || cacheEntry.OperationClaims.Contains(requestedOperationClaim))
                {
                    if (result.PluginFile.State.Value == PluginFileState.Valid)
                    {
                        var plugin = await _pluginFactory.GetOrCreateAsync(
                            result.PluginFile.Path,
                            PluginConstants.PluginArguments,
                            new RequestHandlers(),
                            _connectionOptions,
                            cancellationToken);

                        var utilities = await PerformOneTimePluginInitializationAsync(plugin, cancellationToken);

                        // We still make the GetOperationClaims call even if we have the operation claims cached. This is a way to self-update the cache.
                        var operationClaims = await _pluginOperationClaims.GetOrAdd(
                            requestKey,
                            key => new Lazy <Task <IReadOnlyList <OperationClaim> > >(() =>
                                                                                      GetPluginOperationClaimsAsync(
                                                                                          plugin,
                                                                                          packageSourceRepository,
                                                                                          serviceIndex,
                                                                                          cancellationToken))).Value;

                        if (!EqualityUtility.SequenceEqualWithNullCheck(operationClaims, cacheEntry.OperationClaims))
                        {
                            cacheEntry.OperationClaims = operationClaims;
                            await cacheEntry.UpdateCacheFileAsync();
                        }

                        pluginCreationResult = new PluginCreationResult(
                            plugin,
                            utilities.Value,
                            operationClaims);
                    }
                    else
                    {
                        pluginCreationResult = new PluginCreationResult(result.Message);
                    }
                }
                return new Tuple <bool, PluginCreationResult>(pluginCreationResult != null, pluginCreationResult);
            },
                       token : cancellationToken
                       ));
        }
コード例 #9
0
        public void DictionaryEquals_CompareWithNullDict_ReturnsFalse()
        {
            // Arrange
            var dict = new Dictionary <int, string>();

            // Act & Assert
            EqualityUtility.DictionaryEquals(dict, null).Should().BeFalse();
        }
コード例 #10
0
        public void DictionaryEquals_CompareSameDicts_ReturnsTrue()
        {
            // Arrange
            var dict = new Dictionary <int, string>();

            // Act & Assert
            EqualityUtility.DictionaryEquals(dict, dict).Should().BeTrue();
        }
コード例 #11
0
        private static void ValidateProjectSpecPackageReference(PackageSpec spec, IEnumerable <string> files)
        {
            // Verify frameworks
            ValidateFrameworks(spec, files);

            // NETCore may not specify a project.json file
            if (!string.IsNullOrEmpty(spec.RestoreMetadata.ProjectJsonPath))
            {
                var message = string.Format(
                    CultureInfo.CurrentCulture,
                    Strings.PropertyNotAllowedForProjectType,
                    nameof(spec.RestoreMetadata.ProjectJsonPath),
                    ProjectStyle.PackageReference.ToString());

                throw RestoreSpecException.Create(message, files);
            }

            // Output path must be set for netcore
            if (string.IsNullOrEmpty(spec.RestoreMetadata.OutputPath))
            {
                var message = string.Format(
                    CultureInfo.CurrentCulture,
                    Strings.MissingRequiredPropertyForProjectType,
                    nameof(spec.RestoreMetadata.OutputPath),
                    ProjectStyle.PackageReference.ToString());

                throw RestoreSpecException.Create(message, files);
            }

            // Original frameworks must be set for netcore
            if (spec.RestoreMetadata.OriginalTargetFrameworks.Count < 1)
            {
                var message = string.Format(
                    CultureInfo.CurrentCulture,
                    Strings.MissingRequiredPropertyForProjectType,
                    nameof(spec.RestoreMetadata.OriginalTargetFrameworks),
                    ProjectStyle.PackageReference.ToString());

                throw RestoreSpecException.Create(message, files);
            }

            //OriginalTargetFrameworks must match the aliases.
            if (spec.RestoreMetadata.TargetFrameworks.Count > 1)
            {
                var aliases = spec.TargetFrameworks.Select(e => e.TargetAlias);

                if (!EqualityUtility.OrderedEquals(aliases, spec.RestoreMetadata.OriginalTargetFrameworks, e => e, StringComparer.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase))
                {
                    var message = string.Format(
                        CultureInfo.CurrentCulture,
                        Strings.SpecValidation_OriginalTargetFrameworksMustMatchAliases,
                        string.Join(";", spec.RestoreMetadata.OriginalTargetFrameworks),
                        string.Join(";", aliases)
                        );
                    throw RestoreSpecException.Create(message, files);
                }
            }
        }
コード例 #12
0
                public bool Equals([CanBeNull] CustomType other)
                {
                    if (!EqualityUtility.ClassEquals(this, other))
                    {
                        return(false);
                    }

                    Trace.Assert(other != null);
                    return(_value == other._value);
                }
コード例 #13
0
        public bool Equals([CanBeNull] TypeKey other)
        {
            if (!EqualityUtility.ClassEquals(this, other))
            {
                return(false);
            }

            Trace.Assert(other != null);
            return(_type == other._type);
        }
コード例 #14
0
ファイル: MemberKeyPart.cs プロジェクト: gitter-badger/Farada
        public bool Equals([CanBeNull] MemberKeyPart other)
        {
            if (!EqualityUtility.ClassEquals(this, other))
            {
                return(false);
            }

            Trace.Assert(other != null);
            return(Member.Name == other.Member.Name && MemberType == other.MemberType);
        }
コード例 #15
0
        public static bool IsLockFileStillValid(DependencyGraphSpec dgSpec, PackagesLockFile nuGetLockFile)
        {
            var uniqueName = dgSpec.Restore.First();
            var project    = dgSpec.GetProjectSpec(uniqueName);

            // Validate all the direct dependencies
            foreach (var framework in project.TargetFrameworks)
            {
                var target = nuGetLockFile.Targets.FirstOrDefault(
                    t => EqualityUtility.EqualsWithNullCheck(t.TargetFramework, framework.FrameworkName));

                if (target != null)
                {
                    var directDependencies = target.Dependencies.Where(dep => dep.Type == PackageDependencyType.Direct);

                    if (HasProjectDependencyChanged(framework.Dependencies, directDependencies))
                    {
                        // lock file is out of sync
                        return(false);
                    }
                }
            }

            // Validate all P2P references
            foreach (var p2p in dgSpec.Projects)
            {
                if (PathUtility.GetStringComparerBasedOnOS().Equals(p2p.RestoreMetadata.ProjectUniqueName, uniqueName))
                {
                    continue;
                }

                var projectName = Path.GetFileNameWithoutExtension(p2p.RestoreMetadata.ProjectPath);

                foreach (var framework in p2p.TargetFrameworks)
                {
                    var target = nuGetLockFile.Targets.FirstOrDefault(
                        t => EqualityUtility.EqualsWithNullCheck(t.TargetFramework, framework.FrameworkName));

                    if (target != null)
                    {
                        var projectDependency = target.Dependencies.FirstOrDefault(
                            dep => dep.Type == PackageDependencyType.Project &&
                            PathUtility.GetStringComparerBasedOnOS().Equals(dep.Id, projectName));

                        if (HasP2PDependencyChanged(framework.Dependencies, projectDependency))
                        {
                            // lock file is out of sync
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #16
0
ファイル: ConstructionKey.cs プロジェクト: re-motion/TypePipe
        public ConstructionKey(AssembledTypeID typeID, Type delegateType, bool allowNonPublic)
        {
            ArgumentUtility.DebugCheckNotNull("delegateType", delegateType);

            _typeID         = typeID;
            _delegateType   = delegateType;
            _allowNonPublic = allowNonPublic;

            // Pre-compute hash code.
            _hashCode = EqualityUtility.GetRotatedHashCode(_typeID.GetHashCode(), delegateType, allowNonPublic);
        }
コード例 #17
0
        protected new int GetHashCode()
        {
            var fieldValues = new object[s_targetFields.Length];

            for (int i = 0; i < fieldValues.Length; ++i)
            {
                fieldValues[i] = s_targetFields[i].GetValue(Target);
            }

            return(EqualityUtility.GetRotatedHashCode(fieldValues));
        }
コード例 #18
0
ファイル: AssembledTypeID.cs プロジェクト: re-motion/TypePipe
        public AssembledTypeID(Type requestedType, object[] parts)
        {
            ArgumentUtility.DebugCheckNotNull("requestedType", requestedType);
            ArgumentUtility.DebugCheckNotNull("parts", parts);

            _requestedType = requestedType;
            _parts         = parts;

            // Pre-compute hash code.
            _hashCode = requestedType.GetHashCode() ^ EqualityUtility.GetRotatedHashCode(_parts);
        }
コード例 #19
0
        public CustomAttributeDataCacheKey(ICustomAttributeProvider attributeTarget, bool inherit)
        {
            ArgumentUtility.DebugCheckNotNull("attributeTarget", attributeTarget);
            Assertion.DebugAssert(!(attributeTarget is IMutableMember));

            _attributeTarget = attributeTarget;
            _inherit         = inherit;

            // Pre-compute hash code.
            _hashCode = EqualityUtility.GetRotatedHashCode(RuntimeHelpers.GetHashCode(attributeTarget), inherit);
        }
コード例 #20
0
        private static (bool, string) HasDirectPackageDependencyChanged(IEnumerable <LibraryDependency> newDependencies, IEnumerable <LockFileDependency> lockFileDependencies, NuGetFramework nuGetFramework)
        {
            // If the count is not the same, something has changed.
            // Otherwise the N^2 walk below determines whether anything has changed.
            var newPackageDependencies = newDependencies.Where(dep => dep.LibraryRange.TypeConstraint == LibraryDependencyTarget.Package);

            var newPackageDependenciesCount = newPackageDependencies.Count();
            var lockFileDependenciesCount   = lockFileDependencies.Count();

            if (newPackageDependenciesCount != lockFileDependenciesCount)
            {
                return(true,
                       string.Format(
                           CultureInfo.CurrentCulture,
                           Strings.PackagesLockFile_PackageReferencesHaveChanged,
                           nuGetFramework.GetShortFolderName(),
                           lockFileDependenciesCount > 0 ? string.Join(", ", lockFileDependencies.Select(e => e.Id + ":" + e.RequestedVersion.ToNormalizedString()).OrderBy(dep => dep)) : Strings.None,
                           newPackageDependenciesCount > 0 ? string.Join(", ", newPackageDependencies.Select(e => e.LibraryRange.Name + ":" + e.LibraryRange.VersionRange.ToNormalizedString()).OrderBy(dep => dep)) : Strings.None)
                       );
            }

            foreach (var dependency in newPackageDependencies)
            {
                var lockFileDependency = lockFileDependencies.FirstOrDefault(d => StringComparer.OrdinalIgnoreCase.Equals(d.Id, dependency.Name));

                if (lockFileDependency == null)
                {
                    // dependency has changed and lock file is out of sync.
                    return(true,
                           string.Format(
                               CultureInfo.CurrentCulture,
                               Strings.PackagesLockFile_PackageReferenceAdded,
                               dependency.Name,
                               nuGetFramework.GetShortFolderName())
                           );
                }
                if (!EqualityUtility.EqualsWithNullCheck(lockFileDependency.RequestedVersion, dependency.LibraryRange.VersionRange))
                {
                    // dependency has changed and lock file is out of sync.
                    return(true,
                           string.Format(
                               CultureInfo.CurrentCulture,
                               Strings.PackagesLockFile_PackageReferenceVersionChanged,
                               dependency.Name,
                               lockFileDependency.RequestedVersion.ToNormalizedString(),
                               dependency.LibraryRange.VersionRange.ToNormalizedString())
                           );
                }
            }

            // no dependency changed. Lock file is still valid.
            return(false, string.Empty);
        }
コード例 #21
0
        public ConstructorForAssembledTypeCacheKey(Type assembledType, Type delegateType, bool allowNonPublic)
        {
            ArgumentUtility.DebugCheckNotNull("assembledType", assembledType);
            ArgumentUtility.DebugCheckNotNull("delegateType", delegateType);

            _assembledType  = assembledType;
            _delegateType   = delegateType;
            _allowNonPublic = allowNonPublic;

            // Pre-compute hash code.
            _hashCode = EqualityUtility.GetRotatedHashCode(_assembledType.GetHashCode(), delegateType, allowNonPublic);
        }
コード例 #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConcreteMixinTypeIdentifier"/> class.
        /// </summary>
        /// <param name="mixinType">The mixin type for which a concrete type was generated.</param>
        /// <param name="overriders">Mixin methods that override methods of the target class.</param>
        /// <param name="overridden">Mixin methods that are overridden by the target class.</param>
        public ConcreteMixinTypeIdentifier(Type mixinType, HashSet <MethodInfo> overriders, HashSet <MethodInfo> overridden)
        {
            ArgumentUtility.CheckNotNull("mixinType", mixinType);
            ArgumentUtility.CheckNotNull("overriders", overriders);
            ArgumentUtility.CheckNotNull("overridden", overridden);

            _mixinType  = mixinType;
            _overriders = overriders;
            _overridden = overridden;

            _cachedHashCode = MixinType.GetHashCode()
                              ^ EqualityUtility.GetXorHashCode(_overriders)
                              ^ EqualityUtility.GetXorHashCode(_overridden);
        }
コード例 #23
0
 public override int GetHashCode()
 {
     return(EqualityUtility.GetRotatedHashCode(
                _dataInfo,
                _selectProjection,
                _whereCondition,
                _topExpression,
                _isDistinctQuery,
                _rowNumberSelector,
                _currentRowNumberOffset,
                _groupByExpression)
            ^ EqualityUtility.GetRotatedHashCode(_sqlTables)
            ^ EqualityUtility.GetRotatedHashCode(_orderings));
 }
コード例 #24
0
        public LocalPackageInfo FindPackage(string packageId, NuGetVersion version)
        {
            LocalPackageInfo package = null;

            var packages = FindPackagesByIdImpl(packageId);
            var count    = packages.Count;

            for (var i = 0; i < count; i++)
            {
                var candidatePackage = packages[i];
                if (candidatePackage.Version == version)
                {
                    package = candidatePackage;
                    break;
                }
            }

            if (package == null)
            {
                return(null);
            }

            // Check for an exact match on casing
            if (StringComparer.Ordinal.Equals(packageId, package.Id) &&
                EqualityUtility.SequenceEqualWithNullCheck(version.ReleaseLabels, package.Version.ReleaseLabels, StringComparer.Ordinal))
            {
                return(package);
            }

            // nuspec
            var nuspec = _packageFileCache.GetOrAddNuspec(package.ManifestPath, package.ExpandedPath);

            // files
            var files = _packageFileCache.GetOrAddFiles(package.ExpandedPath);

            // sha512
            var sha512 = _packageFileCache.GetOrAddSha512(package.Sha512Path);

            // Create a new info to match the given id/version
            return(new LocalPackageInfo(
                       packageId,
                       version,
                       package.ExpandedPath,
                       package.ManifestPath,
                       package.ZipPath,
                       package.Sha512Path,
                       nuspec,
                       files,
                       sha512));
        }
コード例 #25
0
        /// <summary>
        /// The method will return true if:
        /// 1. If a transitive dependency from the lock file is now added to the central file.
        ///     or
        /// 1. If there is a mistmatch between the RequestedVersion of a lock file dependency marked as CentralTransitive and the the version specified in the central package management file.
        ///     or
        /// 2. If a central version that is a transitive dependency is removed from CPVM the lock file is invalidated.
        /// </summary>
        private static (bool, string) HasProjectTransitiveDependencyChanged(
            IDictionary <string, CentralPackageVersion> centralPackageVersions,
            IList <LockFileDependency> lockFileCentralTransitiveDependencies,
            IList <LockFileDependency> lockTransitiveDependencies)
        {
            // Transitive dependencies moved to be centraly managed will invalidate the lock file
            LockFileDependency dependency = lockTransitiveDependencies.FirstOrDefault(dep => centralPackageVersions.ContainsKey(dep.Id));

            if (dependency != null)
            {
                return(true,
                       string.Format(
                           CultureInfo.CurrentCulture,
                           Strings.PackagesLockFile_ProjectTransitiveDependencyChanged,
                           dependency.Id
                           )
                       );
            }

            foreach (var lockFileDependencyEnforcedByCPV in lockFileCentralTransitiveDependencies)
            {
                if (centralPackageVersions.TryGetValue(lockFileDependencyEnforcedByCPV.Id, out var centralPackageVersion))
                {
                    if (centralPackageVersion != null && !EqualityUtility.EqualsWithNullCheck(lockFileDependencyEnforcedByCPV.RequestedVersion, centralPackageVersion.VersionRange))
                    {
                        return(true,
                               string.Format(
                                   CultureInfo.CurrentCulture,
                                   Strings.PackagesLockFile_ProjectTransitiveDependencyVersionChanged,
                                   lockFileDependencyEnforcedByCPV.RequestedVersion.ToNormalizedString(),
                                   centralPackageVersion.VersionRange.ToNormalizedString()
                                   )
                               );
                    }
                    continue;
                }

                // The central version was removed
                return(true,
                       string.Format(
                           CultureInfo.CurrentCulture,
                           Strings.PackagesLockFile_CentralPackageVersionRemoved,
                           lockFileDependencyEnforcedByCPV.Id
                           )
                       );
            }

            return(false, string.Empty);
        }
コード例 #26
0
        public void DictionaryEquals_CompareEquivalentDicts_ReturnsTrue()
        {
            // Arrange
            var dict1 = new Dictionary <int, string>()
            {
                { 1, "unit.test" }
            };
            var dict2 = new Dictionary <int, string>()
            {
                { 1, "unit.test" }
            };

            // Act & Assert
            EqualityUtility.DictionaryEquals(dict1, dict2).Should().BeTrue();
        }
コード例 #27
0
        public bool Equals(LockFileDependency x, LockFileDependency y)
        {
            if (ReferenceEquals(x, y))
            {
                return(true);
            }

            if (x == null || y == null)
            {
                return(false);
            }

            return(StringComparer.OrdinalIgnoreCase.Equals(x.Id, y.Id) &&
                   EqualityUtility.EqualsWithNullCheck(x.ResolvedVersion, y.ResolvedVersion));
        }
コード例 #28
0
            public bool Equals(NodeWarningProperties other)
            {
                if (other == null)
                {
                    return(false);
                }

                if (ReferenceEquals(this, other))
                {
                    return(true);
                }

                return(EqualityUtility.SetEqualsWithNullCheck(ProjectWide, other.ProjectWide) &&
                       EqualityUtility.DictionaryEquals(PackageSpecific, other.PackageSpecific, (s, o) => EqualityUtility.SetEqualsWithNullCheck(s, o)));
            }
コード例 #29
0
        public void GetXorHashCode()
        {
            IEnumerable objects1 = new int[] { 1, 2, 3 };
            IEnumerable objects2 = new int[] { 1, 2, 3 };

            Assert.That(EqualityUtility.GetXorHashCode(objects2), Is.EqualTo(EqualityUtility.GetXorHashCode(objects1)));

            IEnumerable objects3 = new int[] { 3, 2, 1 };

            Assert.That(EqualityUtility.GetXorHashCode(objects3), Is.EqualTo(EqualityUtility.GetXorHashCode(objects1)));

            IEnumerable objects4 = new int[] { 1, 2, 17 };

            Assert.That(EqualityUtility.GetXorHashCode(objects4), Is.Not.EqualTo(EqualityUtility.GetXorHashCode(objects1)));
        }
コード例 #30
0
        public void GetRotatedHashCode_Nulls()
        {
            var array1 = new object[] { 1, null, 2 };
            var array2 = new object[] { 1, null, 2 };
            var array3 = new object[] { 1, null, null, 2 };

            Assert.That(EqualityUtility.GetRotatedHashCode(array1), Is.EqualTo(EqualityUtility.GetRotatedHashCode(array2)));
            Assert.That(EqualityUtility.GetRotatedHashCode(array1), Is.Not.EqualTo(EqualityUtility.GetRotatedHashCode(array3)));

            Assert.That(EqualityUtility.GetRotatedHashCode((IEnumerable)array1), Is.EqualTo(EqualityUtility.GetRotatedHashCode((IEnumerable)array2)));
            Assert.That(EqualityUtility.GetRotatedHashCode((IEnumerable)array1), Is.Not.EqualTo(EqualityUtility.GetRotatedHashCode((IEnumerable)array3)));

            Assert.That(EqualityUtility.GetRotatedHashCode(array1), Is.EqualTo(EqualityUtility.GetRotatedHashCode((IEnumerable)array1)));
            Assert.That(EqualityUtility.GetRotatedHashCode(array3), Is.EqualTo(EqualityUtility.GetRotatedHashCode((IEnumerable)array3)));
        }