Exemplo n.º 1
0
        private ServerPackage CreateServerPackage(IPackage package, bool enableDelisting)
        {
            // File names
            var packageFileName = GetPackageFileName(package.Id, package.Version);
            var hashFileName    = GetHashFileName(package.Id, package.Version);

            // 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 fileInfo = new FileInfo(_fileSystem.GetFullPath(packageFileName));
                packageDerivedData.PackageSize = fileInfo.Length;

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

                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;
            }

            // TODO: frameworks?

            // Build entry
            var serverPackage = new ServerPackage(package, packageDerivedData);

            serverPackage.IsAbsoluteLatestVersion = false;
            serverPackage.IsLatestVersion         = false;
            return(serverPackage);
        }
Exemplo n.º 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;
            SemVer1IsAbsoluteLatest = false;
            SemVer1IsLatest         = false;
            SemVer2IsAbsoluteLatest = false;
            SemVer2IsLatest         = false;
            Listed                  = package.Listed;
            Published               = package.Published;

            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;
            Path     = packageDerivedData.Path;
            FullPath = packageDerivedData.FullPath;
        }
Exemplo n.º 3
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;
            IsAbsoluteLatestVersion = package.IsAbsoluteLatestVersion;
            IsLatestVersion = package.IsLatestVersion;
            Listed = package.Listed;
            Published = package.Published;

            _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;
            Path = packageDerivedData.Path;
            FullPath = packageDerivedData.FullPath;
        }
        private ServerPackage CreateServerPackage(IPackage package, bool enableDelisting)
        {
            // File names
            var packageFileName = GetPackageFileName(package.Id, package.Version);
            var hashFileName = GetHashFileName(package.Id, package.Version);

            // 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 fileInfo = new FileInfo(_fileSystem.GetFullPath(packageFileName));
                packageDerivedData.PackageSize = fileInfo.Length;

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

                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;
            }

            // TODO: frameworks?

            // Build entry
            var serverPackage = new ServerPackage(package, packageDerivedData);
            serverPackage.IsAbsoluteLatestVersion = false;
            serverPackage.IsLatestVersion = false;
            return serverPackage;
        }