public void UninstallTest() { IPackageBuilder packageBuilder = _container.Resolve <IPackageBuilder>(); Stream stream = BuildHelloWorld(packageBuilder); string filename = Path.Combine(_basePath, "package.nupkg"); using (var fileStream = File.Create(filename)) { stream.CopyTo(fileStream); } ZipPackage zipPackage = new ZipPackage(filename); IPackageInstaller packageInstaller = _container.Resolve <IPackageInstaller>(); _mockedVirtualPathProvider.Setup(v => v.MapPath(It.IsAny <string>())) .Returns <string>(path => Path.Combine(_basePath, path.Replace("~\\", "").Replace("~/", ""))); _mockedVirtualPathProvider.Setup(v => v.Combine(It.IsAny <string[]>())) .Returns <string[]>(Path.Combine); PackageInfo packageInfo = packageInstaller.Install(zipPackage, _basePath, _basePath); Assert.That(packageInfo, Is.Not.Null); Assert.That(Directory.Exists(Path.Combine(_basePath, "Modules/Hello.World"))); Assert.That(File.Exists(Path.Combine(_basePath, "Modules/Hello.World/Hello.World.csproj"))); // Uninstall and check that the installation will be gone packageInstaller.Uninstall(zipPackage.Id, _basePath); Assert.That(Directory.Exists(Path.Combine(_basePath, "Modules/Hello.World")), Is.False); }
public void InstallTest() { IPackageBuilder packageBuilder = _container.Resolve <IPackageBuilder>(); Stream stream = BuildHelloWorld(packageBuilder); string filename = Path.Combine(_basePath, "package.nupkg"); using (var fileStream = File.Create(filename)) { stream.CopyTo(fileStream); } ZipPackage zipPackage = new ZipPackage(filename); IPackageInstaller packageInstaller = _container.Resolve <IPackageInstaller>(); _mockedVirtualPathProvider.Setup(v => v.MapPath(It.IsAny <string>())) .Returns <string>(path => Path.Combine(_basePath, path.Replace("~\\", ""))); _mockedVirtualPathProvider.Setup(v => v.Combine(It.IsAny <string[]>())) .Returns <string[]>(Path.Combine); PackageInfo packageInfo = packageInstaller.Install(zipPackage, _basePath, _basePath); Assert.That(packageInfo, Is.Not.Null); Assert.That(Directory.Exists(Path.Combine(_basePath, "Modules/Hello.World"))); var fileOnePath = Path.Combine(_basePath, "Modules/Hello.World/Hello.World.csproj"); var fileTwoPath = Path.Combine(_basePath, "Modules/Hello.World/Service References/SomeReference.cs"); Assert.That(File.Exists(fileOnePath)); Assert.That(File.Exists(fileTwoPath)); Assert.That(File.GetLastWriteTime(fileOnePath), Is.EqualTo(File.GetLastWriteTime(fileTwoPath)), "Installed files should have the same last write time."); }
/// <exclude /> public List <PackageFragmentValidationResult> Install() { Verify.IsNotNull(_packageInstaller, "Pre installation did not validate"); Verify.IsNotNull(_validationResult, "Call validation first"); if (_validationResult.Count > 0) { throw new InvalidOperationException("Installation did not validate"); } Verify.IsNull(_installationResult, "Install may only be called once"); var userName = UserValidationFacade.IsLoggedIn() ? UserValidationFacade.GetUsername() : "<system>"; Log.LogInformation(LogTitle, $"Installing package: {_packageName}, Version: {_packageVersion}, Id = {_packageId}; User name: '{userName}'"); PackageFragmentValidationResult result = _packageInstaller.Install(_systemLockingType); _installationResult = new List <PackageFragmentValidationResult>(); if (result != null) { _installationResult.Add(result); } _installationResult.AddRange(FinalizeProcess(true)); return(_installationResult); }
/// <exclude /> public List <PackageFragmentValidationResult> Install() { Verify.IsNotNull(_packageInstaller, "Pre installation did not validate"); Verify.IsNotNull(_validationResult, "Call validation first"); if (_validationResult.Count > 0) { throw new InvalidOperationException("Installation did not validate"); } Verify.IsNull(_installationResult, "Install may only be called once"); Log.LogInformation(LogTitle, "Installing package: {0}, Version: {1}, Id = {2}", _packageName, _packageVersion, _packageId); PackageFragmentValidationResult result = _packageInstaller.Install(_systemLockingType); _installationResult = new List <PackageFragmentValidationResult>(); if (result != null) { _installationResult.Add(result); } _installationResult.AddRange(FinalizeProcess(true)); return(_installationResult); }
public void InstallUpgradeTest() { IPackageBuilder packageBuilder = _container.Resolve <IPackageBuilder>(); Stream stream = BuildHelloWorld(packageBuilder); string filename = Path.Combine(_basePath, "package.nupkg"); using (var fileStream = File.Create(filename)) { stream.CopyTo(fileStream); } ZipPackage zipPackage = new ZipPackage(filename); IPackageInstaller packageInstaller = _container.Resolve <IPackageInstaller>(); _mockedVirtualPathProvider.Setup(v => v.MapPath(It.IsAny <string>())) .Returns <string>(path => Path.Combine(_basePath, path.Replace("~\\", "").Replace("~/", ""))); _mockedVirtualPathProvider.Setup(v => v.Combine(It.IsAny <string[]>())) .Returns <string[]>(Path.Combine); PackageInfo packageInfo = packageInstaller.Install(zipPackage, _basePath, _basePath); Assert.That(packageInfo, Is.Not.Null); Assert.That(Directory.Exists(Path.Combine(_basePath, "Modules/Hello.World"))); Assert.That(File.Exists(Path.Combine(_basePath, "Modules/Hello.World/Hello.World.csproj"))); // Modify one of the files and install again and check that backup worked and file content is updated string[] lines = File.ReadAllLines(Path.Combine(_basePath, "Modules/Hello.World/Hello.World.csproj")); string originalLine = lines[lines.Length - 1]; lines[lines.Length - 1] = "modified"; File.WriteAllLines(Path.Combine(_basePath, "Modules/Hello.World/Hello.World.csproj"), lines); packageInfo = packageInstaller.Install(zipPackage, _basePath, _basePath); Assert.That(packageInfo, Is.Not.Null); Assert.That(Directory.Exists(Path.Combine(_basePath, "Modules/Hello.World"))); Assert.That(File.Exists(Path.Combine(_basePath, "Modules/Hello.World/Hello.World.csproj"))); lines = File.ReadAllLines(Path.Combine(_basePath, "Modules/Hello.World/Hello.World.csproj")); Assert.That(lines[lines.Length - 1], Is.EqualTo(originalLine)); Assert.That(Directory.Exists(Path.Combine(_basePath, "Modules/_Backup/Hello.World"))); Assert.That(File.Exists(Path.Combine(_basePath, "Modules/_Backup/Hello.World/Hello.World.csproj"))); lines = File.ReadAllLines(Path.Combine(_basePath, "Modules/_Backup/Hello.World/Hello.World.csproj")); Assert.That(lines[lines.Length - 1], Is.EqualTo("modified")); }
public override int Execute(PushPkgOptions options) { try { _packageInstaller.Install(options.Name, options.ReportPath); Console.WriteLine("Done"); return(0); } catch (Exception e) { Console.WriteLine(e.Message); return(1); } }
public override int Execute(PushPkgOptions options) { try { bool success = _packageInstaller.Install(options.Name, options.ReportPath); Console.WriteLine(success ? "Done" : "Error"); return(success ? 0 : 1); } catch (Exception e) { Console.WriteLine(e.StackTrace); return(1); } }
public void Install(string packageName, string version, string nugetSourceUrl) { _workingDirectoriesProvider.CreateTempDirectory(restoreTempDirectory => { _nugetManager.RestoreToDirectory(packageName, version, nugetSourceUrl, restoreTempDirectory, true); _workingDirectoriesProvider.CreateTempDirectory(zipTempDirectory => { var restoreTempDirectoryInfo = new DirectoryInfo(restoreTempDirectory); string packagePath = Path.Combine(zipTempDirectory, _packageArchiver.GetPackedGroupPackagesFileName(restoreTempDirectoryInfo.Name)); _packageArchiver.ZipPackages(restoreTempDirectory, packagePath, true); _packageInstaller.Install(packagePath); }); }); }
public void Install(IEnumerable <NugetPackageFullName> nugetPackageFullNames, string nugetSourceUrl) { _workingDirectoriesProvider.CreateTempDirectory(restoreTempDirectory => { foreach (NugetPackageFullName nugetPackageFullName in nugetPackageFullNames) { _nugetManager.RestoreToDirectory(nugetPackageFullName, nugetSourceUrl, restoreTempDirectory, true); } _workingDirectoriesProvider.CreateTempDirectory(zipTempDirectory => { var restoreTempDirectoryInfo = new DirectoryInfo(restoreTempDirectory); string packagePath = Path.Combine(zipTempDirectory, _packageArchiver.GetPackedGroupPackagesFileName(restoreTempDirectoryInfo.Name)); _packageArchiver.ZipPackages(restoreTempDirectory, packagePath, true); _packageInstaller.Install(packagePath); }); }); }
private async Task HandleUpdater() { try { string updateSiteString = "https://onedrive.live.com/download?resid=D332F531B200D073%218103"; Uri updateSite = new Uri(updateSiteString); Uri remotePackageStorageDirectory = new Uri(updateSite, "Packages/"); if (Directory.Exists(baseDirectory) == false) { Directory.CreateDirectory(baseDirectory); } IStorageProvider storageProvider = new StorageProvider(baseDirectory); using (ICacheStorageProvider cacheStorageProvider = new CacheStorageProvider(System.IO.Path.Combine(baseDirectory, "Cache"))) { IPackageAcquisitionFactory packageAcquisitionFactory = new PackageAcquisitionFactory(); IUpdaterCache updaterCache = UpdaterCache.InitializeCache(cacheStorageProvider); IPackageMetadataCollection packageMetadataCollection = null; IUpdater updater = new Updater.Updater(); using (XmlReader xmlReader = XmlReader.Create(updateSite.AbsoluteUri)) { packageMetadataCollection = updater.ParseMetadataCollectionXml(xmlReader); } IUpdateState updateState = updater.DetermineUpdateState(updaterCache.InstalledPackages, packageMetadataCollection); IPackageInstaller packageInstaller = updater.CreateInstaller(); foreach (IPackageMetadata packageMetadata in updateState.Packages) { IPackageAcquisition packageAcquisition = packageAcquisitionFactory.BuildPackageAcquisition(remotePackageStorageDirectory, cacheStorageProvider); using (ZipArchive packageArchive = await packageAcquisition.AcquirePackageArchive(packageMetadata)) { using (IPackage package = Package.OpenPackage(packageMetadata, packageArchive)) { packageInstaller.Install(storageProvider, package); updaterCache.MarkPackageAsInstalled(package.Metadata); } } } } } catch (Exception ex) { string baseDirectory = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "Updater"); File.WriteAllText(System.IO.Path.Combine(baseDirectory, "error.txt"), ex.ToString()); } }
static async Task MainAsync(string[] args) { Uri updateSite = new Uri(ConfigurationManager.AppSettings["updateSite"]); Uri remotePackageStorageDirectory = new Uri(updateSite, "Packages/"); string baseDirectory = Path.GetFullPath("Testing"); // Clean the old test environment if it already exist if (Directory.Exists(baseDirectory)) { Directory.Delete(baseDirectory, true); } // Setup the test environment Directory.CreateDirectory(baseDirectory); IStorageProvider storageProvider = new StorageProvider(baseDirectory); using (ICacheStorageProvider cacheStorageProvider = new CacheStorageProvider(Path.Combine(baseDirectory, "Cache"))) { IPackageAcquisitionFactory packageAcquisitionFactory = new PackageAcquisitionFactory(); IUpdaterCache updaterCache = UpdaterCache.InitializeCache(cacheStorageProvider); IPackageMetadataCollection packageMetadataCollection = null; IUpdater updater = new Updater(); using (XmlReader xmlReader = XmlReader.Create(updateSite.AbsoluteUri)) { packageMetadataCollection = updater.ParseMetadataCollectionXml(xmlReader); } IUpdateState updateState = updater.DetermineUpdateState(updaterCache.InstalledPackages, packageMetadataCollection); IPackageInstaller packageInstaller = updater.CreateInstaller(); foreach (IPackageMetadata packageMetadata in updateState.Packages) { IPackageAcquisition packageAcquisition = packageAcquisitionFactory.BuildPackageAcquisition(remotePackageStorageDirectory, cacheStorageProvider); using (ZipArchive packageArchive = await packageAcquisition.AcquirePackageArchive(packageMetadata)) { using (IPackage package = Package.OpenPackage(packageMetadata, packageArchive)) { packageInstaller.Install(storageProvider, package); updaterCache.MarkPackageAsInstalled(package.Metadata); } } } } }
private async void PerformUpdateCommandCallback() { Status = "Downloading update..."; Uri updateSite = new Uri(@"https://onedrive.live.com/download?resid=D332F531B200D073%218103"); Uri remotePackageStorageDirectory = new Uri(updateSite, "Packages/"); string baseDirectory = Path.GetFullPath("Data"); IStorageProvider storageProvider = new StorageProvider(baseDirectory); using (ICacheStorageProvider cacheStorageProvider = new CacheStorageProvider(Path.Combine(baseDirectory, "Cache"))) { IPackageAcquisitionFactory packageAcquisitionFactory = new PackageAcquisitionFactory(); IUpdaterCache updaterCache = UpdaterCache.InitializeCache(cacheStorageProvider); IPackageMetadataCollection packageMetadataCollection = null; IUpdater updater = new Updater.Updater(); using (XmlReader xmlReader = XmlReader.Create(updateSite.AbsoluteUri)) { packageMetadataCollection = updater.ParseMetadataCollectionXml(xmlReader); } IUpdateState updateState = updater.DetermineUpdateState(updaterCache.InstalledPackages, packageMetadataCollection); IPackageInstaller packageInstaller = updater.CreateInstaller(); foreach (IPackageMetadata packageMetadata in updateState.Packages) { IPackageAcquisition packageAcquisition = packageAcquisitionFactory.BuildPackageAcquisition(remotePackageStorageDirectory, cacheStorageProvider); using (ZipArchive packageArchive = await packageAcquisition.AcquirePackageArchive(packageMetadata)) { using (IPackage package = Package.OpenPackage(packageMetadata, packageArchive)) { packageInstaller.Install(storageProvider, package); updaterCache.MarkPackageAsInstalled(package.Metadata); } } } } RefreshImage(); Status = "Image updated!"; }
public PackageInfo Install(Stream packageStream, string location, string applicationPath) { return(DoInstall(() => _packageInstaller.Install(packageStream, location, applicationPath))); }
public PackageInfo Install(IPackage package, string location, string applicationPath) { return(DoInstall(() => _packageExpander.Install(package, location, applicationPath))); }
public void InstallPackage(string packagePath) { PackageInstaller.Install(packagePath); }
private void ApplyMigration([NotNull] DbMigration migration, int currentVersion) { try { _logger.Debug(Resources.DbMigrator_MigrationApplying.FormatWith( migration.GetType().FullName, currentVersion, migration.Version)); if (migration.RequireTransaction) { _dbTransformationProvider.BeginTransaction(); } else { _dbTransformationProvider.OpenConnectionIfClosed(); } migration.Up(_dbTransformationProvider); _dbTransformationProvider.SetDbPartVersion(Settings.Default.SchemaDbPart, migration.Version); var item = _maps.FirstOrDefault(x => x.MigrationVersion == migration.Version); if ((item?.Packages != null) && item.Packages.Any()) { var migrationPackages = item.Packages.Select(packageInfo => _provider.Get(packageInfo.Key, packageInfo.Value)); foreach (var package in migrationPackages) { _installer.Install(_dbTransformationProvider, package); } } if (migration.RequireTransaction) { _dbTransformationProvider.Commit(); } else { _dbTransformationProvider.CloseConnectionIfOpen(); } _logger.Debug( Resources.MigrationAppliedSuccessfully.FormatWith( migration.GetType().FullName, currentVersion, migration.Version)); } catch (Exception exception) { if (migration.RequireTransaction) { _dbTransformationProvider.Rollback(); } var message = Resources.MigrationError.FormatWith(migration.GetType().FullName, currentVersion, migration.Version); _logger.Error(message); throw new InvalidOperationException(message, exception); } }