public void InstallPackage_extract_package_success() { //given var version10 = new Version(1, 0); var packageDetails = new PackageDetails("TestNugetPackage", _nugetFeedFolder, version10); var op = new InstallPackage(); var context = new DeploymentTaskContext { Folders = new ServiceFolders { DeployFolder = (FullPath)_targetPath }, PackageDetails = packageDetails, KeepOnUpdate = FileList.Empty }; context.Parameters.Version = version10.ToString(); //when op.Execute(context); //then string[] sampleFiles = { "TestNugetPackLib.dll", }; var files = Directory .GetFiles(_targetPath) .Select(Path.GetFileName); Assert.That(sampleFiles, Is.SubsetOf(files)); }
public void InstallPackage_extract_package_success() { //given var version10 = new Version(1, 0); var packageDetails = new PackageDetails("TestNugetPackage", _nugetFeedFolder, version10); var op = new InstallPackage(_targetPath, packageDetails); var stringWriter = new StringWriter(); var buildLog = new DeploymentTaskContext(stringWriter); //when op.Execute(buildLog); //then string[] sampleFiles = { "TestNugetPackLib.dll", }; var files = Directory .GetFiles(_targetPath) .Select(Path.GetFileName); Assert.That(sampleFiles, Is.SubsetOf(files)); }
public void Init() { _nugetFeedFolder = Path.Combine(Environment.CurrentDirectory, "testnuget"); Folder.EnsureDeleted(_nugetFeedFolder); Folder.EnsureExists(_nugetFeedFolder); var version10 = new Version(1, 0); TestPackages.CopyHostPackageTo(_nugetFeedFolder); TestPackages.CopyTest10To(_nugetFeedFolder); _basePath = Folder.Combine(_nugetFeedFolder, "extracted"); var packageDetails = new PackageDetails("Codestellation.Galaxy.Host", _nugetFeedFolder, version10); var installPackage = new InstallPackage(_basePath, packageDetails, FileList.Empty); var stringWriter = new StringWriter(); _context = new DeploymentTaskContext(stringWriter); installPackage.Execute(_context); }
/// <summary> /// Merges ICE cubes into the database <paramref name="item"/> and executes selected ICEs. /// </summary> /// <param name="item">The database to validate.</param> protected override void ProcessItem(PSObject item) { // Get the item path and set the current context. string path = item.GetPropertyValue <string>("PSPath"); path = this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(path); this.CurrentPath = path; // Copy the database to a writable location and open. string copy = this.Copy(path); using (var db = new InstallPackage(copy, DatabaseOpenMode.Direct)) { // Apply any patches or transforms before otherwise modifying. this.ApplyTransforms(db); // Copy the ProductCode and drop the Property table to avoid opening an installed product. bool hasProperty = db.IsTablePersistent("Property"); string productCode = null; if (hasProperty) { productCode = db.ExecutePropertyQuery("ProductCode"); } // Merge the ICE cubes and fix up the database if needed. this.MergeCubes(db); if (!hasProperty) { db.Execute("DROP TABLE `Property`"); } var included = new List <WildcardPattern>(); if (null != this.Include) { Array.ForEach(this.Include, pattern => included.Add(new WildcardPattern(pattern))); } var excluded = new List <WildcardPattern>(); if (null != this.Exclude) { Array.ForEach(this.Exclude, pattern => excluded.Add(new WildcardPattern(pattern))); } // Get all the ICE actions in the database that are not excluded. var actions = new List <string>(); foreach (var action in db.ExecuteStringQuery("SELECT `Action` FROM `_ICESequence` ORDER BY `Sequence`")) { if (!action.Match(excluded)) { actions.Add(action); } } // Remove any actions not explicitly included. if (0 < included.Count) { for (int i = actions.Count - 1; 0 <= i; --i) { if (!actions[i].Match(included)) { actions.RemoveAt(i); } } } // Open a session with the database. using (var session = Installer.OpenPackage(db, false)) { // Put the original ProductCode back. if (!string.IsNullOrEmpty(productCode)) { db.Execute("DELETE FROM `Property` WHERE `Property` = 'ProductCode'"); db.Execute("INSERT INTO `Property` (`Property`, `Value`) VALUES ('ProductCode', '{0}')", productCode); } // Now execute all the remaining actions in order. foreach (string action in actions) { try { session.DoAction(action); this.Flush(); } catch (InstallerException ex) { using (var pse = new PSInstallerException(ex)) { if (null != pse.ErrorRecord) { this.WriteError(pse.ErrorRecord); } } } } } } }