示例#1
0
        private PackageDerivedData GetPackageDerivedData(IPackage package, bool enableDelisting)
        {
            // File names
            var normalizedVersion = package.Version.ToNormalizedString();
            var packageFileName   = GetPackageFileName(package.Id, normalizedVersion);
            var hashFileName      = GetHashFileName(package.Id, normalizedVersion);

            // File system
            var physicalFileSystem = _fileSystem as PhysicalFileSystem;

            // Build package info
            var packageDerivedData = new PackageDerivedData();

            // Read package hash
            using (var reader = new StreamReader(_fileSystem.OpenFile(hashFileName)))
            {
                packageDerivedData.PackageHash = reader.ReadToEnd().Trim();
            }

            // Read package info
            var localPackage = package as LocalPackage;

            if (physicalFileSystem != null)
            {
                // Read package info from file system
                var fullPath = _fileSystem.GetFullPath(packageFileName);
                var fileInfo = new FileInfo(fullPath);
                packageDerivedData.PackageSize = fileInfo.Length;

                packageDerivedData.LastUpdated = _fileSystem.GetLastModified(packageFileName);
                packageDerivedData.Created     = _fileSystem.GetCreated(packageFileName);
                packageDerivedData.FullPath    = fullPath;

                if (enableDelisting && localPackage != null)
                {
                    // hidden packages are considered delisted
                    localPackage.Listed = !fileInfo.Attributes.HasFlag(FileAttributes.Hidden);
                }
            }
            else
            {
                // Read package info from package (slower)
                using (var stream = package.GetStream())
                {
                    packageDerivedData.PackageSize = stream.Length;
                }

                packageDerivedData.LastUpdated = DateTime.MinValue;
                packageDerivedData.Created     = DateTime.MinValue;
            }

            return(packageDerivedData);
        }
示例#2
0
        public ServerPackage(
            IPackage package,
            PackageDerivedData packageDerivedData)
        {
            Id         = package.Id;
            Version    = package.Version;
            Title      = package.Title;
            Authors    = package.Authors;
            Owners     = package.Owners;
            IconUrl    = package.IconUrl;
            LicenseUrl = package.LicenseUrl;
            ProjectUrl = package.ProjectUrl;
            RequireLicenseAcceptance = package.RequireLicenseAcceptance;
            DevelopmentDependency    = package.DevelopmentDependency;
            Description      = package.Description;
            Summary          = package.Summary;
            ReleaseNotes     = package.ReleaseNotes;
            Language         = package.Language;
            Tags             = package.Tags;
            Copyright        = package.Copyright;
            MinClientVersion = package.MinClientVersion;
            ReportAbuseUrl   = package.ReportAbuseUrl;
            DownloadCount    = package.DownloadCount;
            Listed           = package.Listed;

            IsSemVer2 = IsPackageSemVer2(package);

            _dependencySets = package.DependencySets.ToList();
            Dependencies    = DependencySetsAsString(package.DependencySets);

            _supportedFrameworks = package.GetSupportedFrameworks().ToList();
            SupportedFrameworks  = string.Join("|", package.GetSupportedFrameworks().Select(VersionUtility.GetFrameworkString));

            PackageSize          = packageDerivedData.PackageSize;
            PackageHash          = packageDerivedData.PackageHash;
            PackageHashAlgorithm = packageDerivedData.PackageHashAlgorithm;
            LastUpdated          = packageDerivedData.LastUpdated;
            Created  = packageDerivedData.Created;
            FullPath = packageDerivedData.FullPath;

            SemVer1IsAbsoluteLatest = false;
            SemVer1IsLatest         = false;
            SemVer2IsAbsoluteLatest = false;
            SemVer2IsLatest         = false;
        }