Ejemplo n.º 1
0
        public Stream Download(PackageKey key)
        {
            var fullPath = Path.Combine(RootPath, key.GetFileName());

            if (!File.Exists(fullPath))
            {
                throw new FileNotFoundException("package not found");
            }

            return(File.OpenRead(fullPath));
        }
Ejemplo n.º 2
0
        public PackageManifest GetManifest(PackageKey key, NuGet.Frameworks.NuGetFramework projectFramework)
        {
            if (key.Framework != null)
            {
                var fullPath = Path.Combine(RootPath, key.GetFileName());

                if (!File.Exists(fullPath))
                {
                    throw new FileNotFoundException("package not found");
                }

                using (IPackageReader reader = _packageReaderFactory.Get(RepositoryType.Pundit, File.OpenRead(fullPath)))
                    return(reader.ReadManifest());
            }

            // From here on, we resolve packages that come from a NuGet package and therefore, have no FW

            var filePattern = key.GetNoFrameworkFileName();

            var results = new DirectoryInfo(RootPath).GetFiles(filePattern).ToArray();

            if (results.Length == 0)
            {
                return(null);
            }

            var matches = 0;

            foreach (var info in results)
            {
                var tempKey   = PackageExtensions.GetPackageKeyFromFileName(info.Name);
                var nearestFw = NuGet.Frameworks.NuGetFrameworkUtility.GetNearest(new[] { new FakedFrameworkGroup(tempKey.Framework) }, projectFramework);

                if (nearestFw.TargetFramework.GetShortFolderName() == tempKey.Framework)
                {
                    matches++;
                }
            }

            if (matches != 1)
            {
                throw new NotSupportedException("Error, 0 or more than 1 package found matching the framework.");
            }

            using (IPackageReader reader = _packageReaderFactory.Get(RepositoryType.Pundit, File.OpenRead(results[0].FullName)))
                return(reader.ReadManifest());
        }
Ejemplo n.º 3
0
 public bool PackageExist(PackageKey package)
 {
     return(File.Exists(Path.Combine(RootPath, package.GetFileName())));
 }