public void SupressErrorWorksForFindPackagesForRepositoriesThatThrowWhenInvoked()
        {
            // Arrange
            var mockRepository = new Mock <IPackageRepository>();

            mockRepository.Setup(c => c.GetPackages()).Throws(new InvalidOperationException()).Verifiable();

            var packageLookup = new Mock <IPackageLookup>(MockBehavior.Strict);

            packageLookup.Setup(c => c.FindPackage(It.IsAny <string>(), It.IsAny <SemanticVersion>())).Throws(new Exception());
            var mockRepositoryWithLookup = packageLookup.As <IPackageRepository>();

            mockRepositoryWithLookup.Setup(c => c.GetPackages()).Throws(new InvalidOperationException());

            var repository = new AggregateRepository(new[] {
                new MockPackageRepository {
                    PackageUtility.CreatePackage("A"),
                },
                mockRepository.Object,
                new MockPackageRepository {
                    PackageUtility.CreatePackage("B"),
                },
                mockRepositoryWithLookup.Object
            });

            repository.IgnoreFailingRepositories = true;

            // Act
            var package = repository.FindPackage("C", new SemanticVersion("1.0"));

            // Assert
            Assert.Null(package);
        }
Beispiel #2
0
        /// <summary>
        ///     Deletes all files from a package
        /// </summary>
        /// <param name="installed">Insyalled package</param>
        /// <param name="repositories">Repositories where to find the package</param>
        private static void DeleteFiles(PackageInfo installed, ICollection <string> repositories, ILogger logger)
        {
            logger.Log("Deleting installed files... ");

            var factory = new PackageRepositoryFactory();

            IPackage package;

            var globalRepo = new AggregateRepository(factory, repositories, true);

            package = globalRepo.FindPackage(installed.Name, SemanticVersion.Parse(installed.Version), true, true);

            if (package == null)
            {
                throw new InexistentPackageException(string.Format("Unable to find package {0} version {1}", installed.Name, installed.Version));
            }

            var fylesystem = new PhysicalFileSystem(installed.InstallationDirectory);

            fylesystem.DeleteFiles(package.GetFiles(), installed.InstallationDirectory);

            File.Delete(Path.Combine(installed.InstallationDirectory, installed.Name + "." + installed.Version + ".nupkg"));

            foreach (var config in Directory.GetFiles(installed.InstallationDirectory, "*.config"))
            {
                File.Delete(config);
            }

            logger.Log("Installed files deleted");
        }
Beispiel #3
0
        /// <summary>
        ///     Downloads the specified package and installs it in the configured folder
        /// </summary>
        /// <param name="info">Pacakge informations</param>
        private static void DownloadPackage(PackageInfo info, ICollection <string> repositories, ILogger logger)
        {
            logger.Log(String.Format("Downloading package for {0} version {1} ... ", info.Name, info.Version));

            var factory = new PackageRepositoryFactory();

            IPackage package;

            var globalRepo = new AggregateRepository(factory, repositories, true);

            package = globalRepo.FindPackage(info.Name, SemanticVersion.Parse(info.Version), true, true);

            if (package == null)
            {
                throw new InexistentPackageException(string.Format("Unable to find package {0} version {1}", info.Name, info.Version));
            }

            var manager = new PackageManager(
                globalRepo,
                new CustomPathResolver()
            {
                BasePath = info.InstallationDirectory
            },
                new OverWritingPhysicalFilesystem(info.InstallationDirectory));

            manager.InstallPackage(package, false, true);

            logger.Log(String.Format("Package for {0} version {1} downloaded ... ", info.Name, info.Version));
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var orchardDirectory = args[0];
            var inputDirectory   = args[1];
            var outputDirectory  = args[2];
            var cacheDirectory   = args[3];

            var cacheFileSystem      = new PhysicalFileSystem(cacheDirectory);
            var cachePackageResolver = new DefaultPackagePathResolver(cacheFileSystem, false);

            var orchardRepository = new AggregateRepository(new IPackageRepository[]
            {
                new LocalPackageRepository(orchardDirectory),
                new DataServicePackageRepository(new Uri("http://nuget.org/api/v2")),
            });

            var orchardManager = new PackageManager(orchardRepository, cachePackageResolver, cacheFileSystem);

            var inputRepository = new LocalPackageRepository(inputDirectory);
            var inputManager    = new PackageManager(inputRepository, cachePackageResolver, cacheFileSystem);

            var references = new[] { "Orchard.Core", "Orchard.Framework", "Orchard.External" };

            foreach (var reference in references)
            {
                orchardManager.InstallPackage(orchardRepository.FindPackage(reference), false, false);
            }

            foreach (var inputPackage in inputRepository.GetPackages().Where(p => p.Id.StartsWith("Orchard.Module.")))
            {
                Do(inputRepository, inputManager, inputPackage, cacheDirectory, references, outputDirectory);
            }
        }
Beispiel #5
0
        /// <summary>
        ///     Deletes a package from a repository
        /// </summary>
        /// <param name="package">Pacakge to delte</param>
        /// <param name="version">Version to delete</param>
        /// <param name="gallery">Origin gallery</param>
        public static void Delete(string package, string version, string gallery)
        {
            var factory    = new PackageRepositoryFactory();
            var globalRepo = new AggregateRepository(factory, new List <string>()
            {
                gallery
            }, true);

            var p = globalRepo.FindPackage(package, new SemanticVersion(version));

            globalRepo.RemovePackage(p);
        }
Beispiel #6
0
        public static Stream DownloadDacpac(string packageName, string version, string repository)
        {
            var factory = new PackageRepositoryFactory();

            IPackage package;

            var globalRepo = new AggregateRepository(factory, new string[] { repository }, true);

            package = globalRepo.FindPackage(packageName, SemanticVersion.Parse(version), true, true);

            var files = package.GetFiles();

            return(files.Single(x => x.Path.EndsWith(".dacpac")).GetStream());
        }
        public void SupressErrorWorksForFindPackagesForRepositoriesThatThrowWhenInvoked()
        {
            // Arrange
            var mockRepository = new Mock<IPackageRepository>();
            mockRepository.Setup(c => c.GetPackages()).Throws(new InvalidOperationException()).Verifiable();

            var packageLookup = new Mock<PackageLookupBase>();
            packageLookup.Setup(c => c.FindPackage(It.IsAny<string>(), It.IsAny<SemanticVersion>())).Throws(new Exception());
            var mockRepositoryWithLookup = packageLookup.As<IPackageRepository>();
            mockRepositoryWithLookup.Setup(c => c.GetPackages()).Throws(new InvalidOperationException());

            var repository = new AggregateRepository(new[] { 
                new MockPackageRepository { 
                    PackageUtility.CreatePackage("A"), 
                }, 
                mockRepository.Object,
                new MockPackageRepository { 
                    PackageUtility.CreatePackage("B"), 
                },
                mockRepositoryWithLookup.Object
            });
            repository.IgnoreFailingRepositories = true;

            // Act
            var package = repository.FindPackage("C", new SemanticVersion("1.0"));

            // Assert
            Assert.Null(package);
        }
        protected virtual void InternalExecute()
        {
            if (PackageSources.Count == 0)
            {
                throw new ArgumentException("Source");
            }

            if (string.IsNullOrEmpty(Id))
            {
                throw new ArgumentException("Id");
            }

            if (string.IsNullOrEmpty(Url))
            {
                throw new ArgumentException("Url");
            }

            if (IsSharePointOnline)
            {
                if (string.IsNullOrEmpty(UserName))
                {
                    throw new ArgumentException("UserName");
                }

                if (string.IsNullOrEmpty(UserPassword))
                {
                    throw new ArgumentException("UserPassword");
                }
            }

            var spService = new SharePointService();

            spService.WithSharePointContext(Url,
                                            UserName,
                                            UserPassword,
                                            IsSharePointOnline,
                                            context =>
            {
                // connect to remote repo
                var repo         = new AggregateRepository(PackageRepositoryFactory.Default, PackageSources, true);
                IPackage package = null;

                if (!string.IsNullOrEmpty(Version))
                {
                    MetaPackTrace.Info("Fetching package [{0}] with version [{1}]", Id, Version);
                    package = repo.FindPackage(Id, new SemanticVersion(Version));
                }
                else
                {
                    MetaPackTrace.Info("Fetching the latest package [{0}]", Id);
                    package = repo.FindPackage(Id);
                }

                if (package == null)
                {
                    MetaPackTrace.Info("Cannot find package [{0}]. Throwing exception.", Id);
                    throw new ArgumentException("package");
                }
                else
                {
                }

                MetaPackTrace.Info("Found package [{0}] version [{1}].",
                                   package.Id,
                                   package.Version);

                MetaPackTrace.Info("Installing package to SharePoint web site...");

                // create manager with repo and current web site
                var packageManager = CreatePackageManager(repo, context);

                // install package
                if (Force)
                {
                    MetaPackTrace.Info("Force flag is true. Looking for existing package...");

                    var currentPackage = packageManager.LocalRepository.FindPackage(
                        package.Id,
                        package.Version,
                        this.PreRelease,
                        true);

                    if (currentPackage != null)
                    {
                        MetaPackTrace.Info(string.Format(
                                               "Package [{0}] version [{1}] already exists. Uninstalling...",
                                               currentPackage.Id,
                                               currentPackage.Version));

                        packageManager.UninstallPackage(package);

                        // we need a fresh start due to cached nuet packages
                        // TODO - rewrite SharePointCSOMFileSystem to support deletions better
                        packageManager = CreatePackageManager(repo, context);
                    }
                    else
                    {
                        MetaPackTrace.Info(string.Format(
                                               "Package [{0}] version [{1}] does not exist. It will be deployed.",
                                               package.Id,
                                               package.Version));
                    }
                }
                else
                {
                    var currentPackage = packageManager.LocalRepository.FindPackage(
                        package.Id,
                        package.Version,
                        this.PreRelease,
                        true);

                    if (currentPackage != null)
                    {
                        MetaPackTrace.Info(string.Format(
                                               "Package [{0}] version [{1}] already exists. Use --force flag to redeploy it.",
                                               currentPackage.Id,
                                               currentPackage.Version));

                        return;
                    }
                }

                packageManager.InstallPackage(package, false, PreRelease);
                MetaPackTrace.Info("Completed installation. All good!");
            });
        }