public PackageInstallModel Import(PackageInstallModel model) { var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(SystemDirectories.Packages), model.ZipFileName)); var packageInfo = Services.PackagingService.GetCompiledPackageInfo(zipFile); //now we need to check for version comparison if (packageInfo.UmbracoVersionRequirementsType == RequirementsType.Strict) { var packageMinVersion = packageInfo.UmbracoVersion; if (UmbracoVersion.Current < packageMinVersion) { throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("packager/targetVersionMismatch", new[] { packageMinVersion.ToString() }))); } } var installType = Services.PackagingService.GetPackageInstallType(packageInfo.Name, SemVersion.Parse(packageInfo.Version), out var alreadyInstalled); var packageDefinition = PackageDefinition.FromCompiledPackage(packageInfo); packageDefinition.PackagePath = zipFile.FullName; packageDefinition.PackageId = model.PackageGuid; //We must re-map the original package GUID that was generated switch (installType) { case PackageInstallType.AlreadyInstalled: throw new InvalidOperationException("The package is already installed"); case PackageInstallType.NewInstall: case PackageInstallType.Upgrade: //save to the installedPackages.config, this will create a new entry with a new Id if (!Services.PackagingService.SaveInstalledPackage(packageDefinition)) { throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Could not save the package")); } model.Id = packageDefinition.Id; break; default: throw new ArgumentOutOfRangeException(); } return(model); }
public void Install_Data() { var package = PackageInstallation.ReadPackage( //this is where our test zip file is new FileInfo(Path.Combine(IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); var def = PackageDefinition.FromCompiledPackage(package); def.Id = 1; def.PackageId = Guid.NewGuid(); var summary = PackageInstallation.InstallPackageData(def, package, -1); Assert.AreEqual(1, summary.DataTypesInstalled.Count()); //make sure the def is updated too Assert.AreEqual(summary.DataTypesInstalled.Count(), def.DataTypes.Count); }
public void Install_Files() { var package = PackageInstallation.ReadPackage( //this is where our test zip file is new FileInfo(Path.Combine(IOHelper.MapPath("~/Packaging/packages"), DocumentTypePickerPackage))); var def = PackageDefinition.FromCompiledPackage(package); def.Id = 1; def.PackageId = Guid.NewGuid(); def.Files = new List <string>(); //clear out the files of the def for testing, this should be populated by the install var result = PackageInstallation.InstallPackageFiles(def, package, -1).ToList(); Assert.AreEqual(1, result.Count); Assert.AreEqual("bin\\Auros.DocumentTypePicker.dll", result[0]); Assert.IsTrue(File.Exists(Path.Combine(IOHelper.MapPath("~/" + _testBaseFolder), result[0]))); //make sure the def is updated too Assert.AreEqual(result.Count, def.Files.Count); }
private async Task <(string packageFile, int packageId)> DownloadPackageFilesAsync(Guid kitGuid) { //Go get the package file from the package repo var packageFile = await _packageService.FetchPackageFileAsync(kitGuid, UmbracoVersion.Current, _umbracoContextAccessor.UmbracoContext.Security.GetUserId().ResultOr(0)); if (packageFile == null) { throw new InvalidOperationException("Could not fetch package file " + kitGuid); } //add an entry to the installedPackages.config var compiledPackage = _packageService.GetCompiledPackageInfo(packageFile); var packageDefinition = PackageDefinition.FromCompiledPackage(compiledPackage); packageDefinition.PackagePath = packageFile.FullName; _packageService.SaveInstalledPackage(packageDefinition); _packageService.InstallCompiledPackageFiles(packageDefinition, packageFile, _umbracoContextAccessor.UmbracoContext.Security.GetUserId().ResultOr(-1)); return(compiledPackage.PackageFile.Name, packageDefinition.Id); }