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
 private static void UpdateLatestDictionary(
     ConcurrentDictionary <string, ServerPackage> dictionary,
     ServerPackage package)
 {
     dictionary.AddOrUpdate(
         package.Id,
         package,
         (oldId, oldEntry) => oldEntry.Version < package.Version ? package : oldEntry);
 }
Exemplo n.º 3
0
        public void Remove(ServerPackage entity)
        {
            _syncLock.EnterWriteLock();
            try
            {
                _packages.Remove(entity);

                UpdateLatestVersions(_packages.Where(package =>
                                                     String.Equals(package.Id, entity.Id, StringComparison.OrdinalIgnoreCase)));

                _isDirty = true;
            }
            finally
            {
                _syncLock.ExitWriteLock();
            }
        }
Exemplo n.º 4
0
        public void Remove(ServerPackage entity)
        {
            _syncLock.EnterWriteLock();
            try
            {
                _packages.Remove(entity);

                UpdateLatestVersions(_packages.Where(package =>
                    String.Equals(package.Id, entity.Id, StringComparison.OrdinalIgnoreCase)));

                _isDirty = true;
            }
            finally
            {
                _syncLock.ExitWriteLock();
            }
        }
        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;
        }