Exemple #1
0
        IPackageInfo Publish(string packageFileName, Stream packageStream)
        {
            var fileWithoutExtension = packageFileName.Trim().ToLowerInvariant().EndsWith(".wrap")
                                               ? Path.GetFileNameWithoutExtension(packageFileName)
                                               : packageFileName;

            if (Packages.Any(x => x.FullName.EqualsNoCase(fileWithoutExtension)))
            {
                throw new InvalidOperationException("Package already exists in repository.");
            }

            var inMemoryFile = new InMemoryFile("c:\\" + Guid.NewGuid());

            using (var stream = FileExtensions.OpenWrite(inMemoryFile))
                packageStream.CopyTo(stream);

            var tempFolder = new CachedZipPackage(null, inMemoryFile, null);

            var package = new InMemoryPackage
            {
                Name         = PackageNameUtility.GetName(fileWithoutExtension),
                Version      = PackageNameUtility.GetVersion(fileWithoutExtension),
                Source       = this,
                Dependencies = tempFolder.Dependencies.ToList(),
                Anchored     = tempFolder.Anchored
            };

            Packages.Add(package);
            return(package);
        }
Exemple #2
0
        // TODO: Read-retry should be part of an extension method that can be reused for reading the index in indexed folder repositories.



        public IPackageDescriptor Read(IFile filePath)
        {
            if (!filePath.Exists)
            {
                return(null);
            }
            IOException ioException = null;
            int         tries       = 0;

            while (tries < FILE_READ_RETRIES)
            {
                try
                {
                    using (var fileStream = filePath.OpenRead())
                    {
                        var descriptor = new PackageDescriptorReader().Read(fileStream);
                        if (descriptor.Name == null)
                        {
                            descriptor.Name = PackageNameUtility.GetName(filePath.NameWithoutExtension);
                        }
                        return(descriptor);
                    }
                }
                catch (IOException ex)
                {
                    ioException = ex;
                    tries++;
                    Thread.Sleep(FILE_READ_RETRIES_WAIT);
                    continue;
                }
            }
            throw ioException;
        }
Exemple #3
0
        ICommandOutput SetupEnvironmentForAdd()
        {
            var directory = HostEnvironment.CurrentDirectory;

            var fromDirectory = string.IsNullOrEmpty(From) ? null : FileSystem.GetDirectory(From);

            if (fromDirectory != null && fromDirectory.Exists)
            {
                if (SysPath.GetExtension(Name).EqualsNoCase(".wrap") &&
                    SysPath.IsPathRooted(Name) &&
                    FileSystem.GetDirectory(SysPath.GetDirectoryName(Name)) != fromDirectory)
                {
                    return(new Error("You provided both -From and -Name, but -Name is a path. Try removing the -From parameter."));
                }
                directory = fromDirectory;
                _userSpecifiedRepository = new FolderRepository(directory, FolderRepositoryOptions.Default);
            }


            if (SysPath.GetExtension(Name).EqualsNoCase(".wrap") && directory.GetFile(SysPath.GetFileName(Name)).Exists)
            {
                var originalName = Name;
                Name    = PackageNameUtility.GetName(SysPath.GetFileNameWithoutExtension(Name));
                Version = PackageNameUtility.GetVersion(SysPath.GetFileNameWithoutExtension(originalName)).ToString();

                return(new Warning("The requested package contained '.wrap' in the name. Assuming you pointed to a file name and meant a package named '{0}' with version qualifier '{1}'.",
                                   Name,
                                   Version));
            }
            return(null);
        }
Exemple #4
0
        IPackageInfo Publish(string packageFileName, Stream packageStream)
        {
            if (!Navigator.CanPublish)
            {
                throw new InvalidOperationException(string.Format("The repository {0} is read-only.", Navigator));
            }

            Navigator.PushPackage(packageFileName, packageStream);
            _packagesByName = null;
            EnsureDataLoaded();
            return(PackagesByName[PackageNameUtility.GetName(packageFileName)].FirstOrDefault(x => x.Version == PackageNameUtility.GetVersion(packageFileName)));
        }
        void Add(InMemoryRepository repository, string name, string[] dependencies)
        {
            var package = new InMemoryPackage
            {
                Name            = PackageNameUtility.GetName(name),
                SemanticVersion = PackageNameUtility.GetVersion(name),
                Source          = repository,
                Dependencies    = dependencies.Select(DependsParser.ParseDependsLine).ToList()
            };

            repository.Packages.Add(package);
        }
        void Add(InMemoryRepository repository, string name, string[] dependencies)
        {
            var packageNamespace = name.Contains("/") ? name.Substring(0, name.IndexOf("/")) : "global";

            name = name.Contains("/") ? name.Substring(name.IndexOf("/") + 1) : name;
            var package = new InMemoryPackage
            {
                Name         = PackageNameUtility.GetName(name),
                Version      = PackageNameUtility.GetVersion(name),
                Namespace    = packageNamespace,
                Source       = repository,
                Dependencies = dependencies.SelectMany(x => DependsParser.ParseDependsInstruction(x).Dependencies)
                               .ToList()
            };

            repository.Packages.Add(package);
        }
        void Publish(IPackageRepository source, string packageFileName, Stream packageStream)
        {
            var name    = PackageNameUtility.GetName(packageFileName);
            var version = PackageNameUtility.GetVersion(packageFileName);

            if (Packages.Any(x => x.Name.EqualsNoCase(name) && x.SemanticVersion == version))
            {
                throw new InvalidOperationException("Package already exists in repository.");
            }

            var inMemoryFile = new InMemoryFile("c:\\" + Guid.NewGuid());

            using (var stream = inMemoryFile.OpenWrite())
                IO.StreamExtensions.CopyTo(packageStream, stream);

            var tempFolder = new ZipFilePackage(inMemoryFile);

            var package = new InMemoryPackage(tempFolder)
            {
                Source = this
            };

            Packages.Add(package);
        }
Exemple #8
0
 public void version_is_parsed()
 {
     PackageNameUtility.GetVersion("openrasta-2.0.0").ShouldBe("2.0.0");
     PackageNameUtility.GetName("openrasta-2.0.0").ShouldBe("openrasta");
 }
Exemple #9
0
 public void invalid_version_is_ignored()
 {
     PackageNameUtility.GetVersion("openrasta-xxx").ShouldBeNull();
     PackageNameUtility.GetName("openrasta-xxx").ShouldBe("openrasta-xxx");
 }